Trying to get stuff to work
This commit is contained in:
@@ -1,120 +1,120 @@
|
||||
namespace Marro.PacManUdon
|
||||
{
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEditor.Animations;
|
||||
using UnityEditor;
|
||||
//namespace Marro.PacManUdon
|
||||
//{
|
||||
// using System.Collections;
|
||||
// using System.Collections.Generic;
|
||||
// using UnityEngine;
|
||||
// using UnityEditor.Animations;
|
||||
// using UnityEditor;
|
||||
|
||||
public class AnimationRecorder : MonoBehaviour
|
||||
{
|
||||
[SerializeField] AnimationClip clip;
|
||||
[SerializeField] GameObject root;
|
||||
[SerializeField] GameObject[] gameObjectsToAnimate;
|
||||
private GameObjectRecorder recorder;
|
||||
// public class AnimationRecorder : MonoBehaviour
|
||||
// {
|
||||
// [SerializeField] AnimationClip clip;
|
||||
// [SerializeField] GameObject root;
|
||||
// [SerializeField] GameObject[] gameObjectsToAnimate;
|
||||
// private GameObjectRecorder recorder;
|
||||
|
||||
void Start()
|
||||
{
|
||||
recorder = new GameObjectRecorder(root);
|
||||
// void Start()
|
||||
// {
|
||||
// recorder = new GameObjectRecorder(root);
|
||||
|
||||
foreach (GameObject gameObject in gameObjectsToAnimate)
|
||||
{
|
||||
// if(gameObject.GetComponent<PacMan>() || gameObject.GetComponent<Ghost>())
|
||||
// {
|
||||
// recorder.BindComponentsOfType<Transform>(gameObject, true);
|
||||
// }
|
||||
// recorder.BindComponentsOfType<Renderer>(gameObject, true);
|
||||
// foreach (GameObject gameObject in gameObjectsToAnimate)
|
||||
// {
|
||||
// // if(gameObject.GetComponent<PacMan>() || gameObject.GetComponent<Ghost>())
|
||||
// // {
|
||||
// // recorder.BindComponentsOfType<Transform>(gameObject, true);
|
||||
// // }
|
||||
// // recorder.BindComponentsOfType<Renderer>(gameObject, true);
|
||||
|
||||
string path = AnimationUtility.CalculateTransformPath(gameObject.transform, root.transform);
|
||||
// string path = AnimationUtility.CalculateTransformPath(gameObject.transform, root.transform);
|
||||
|
||||
recorder.Bind(EditorCurveBinding.FloatCurve(path, typeof(GameObject), "m_IsActive"));
|
||||
// recorder.Bind(EditorCurveBinding.FloatCurve(path, typeof(GameObject), "m_IsActive"));
|
||||
|
||||
Pellet pellet = gameObject.GetComponent<Pellet>();
|
||||
if (pellet)
|
||||
{
|
||||
recorder.Bind(EditorCurveBinding.FloatCurve(path, typeof(SpriteRenderer), "m_Enabled"));
|
||||
if (pellet.isPowerPellet)
|
||||
{
|
||||
recorder.Bind(EditorCurveBinding.PPtrCurve(path, typeof(SpriteRenderer), "m_Sprite"));
|
||||
}
|
||||
continue;
|
||||
}
|
||||
// Pellet pellet = gameObject.GetComponent<Pellet>();
|
||||
// if (pellet)
|
||||
// {
|
||||
// recorder.Bind(EditorCurveBinding.FloatCurve(path, typeof(SpriteRenderer), "m_Enabled"));
|
||||
// if (pellet.isPowerPellet)
|
||||
// {
|
||||
// recorder.Bind(EditorCurveBinding.PPtrCurve(path, typeof(SpriteRenderer), "m_Sprite"));
|
||||
// }
|
||||
// continue;
|
||||
// }
|
||||
|
||||
if (gameObject.GetComponent<SpriteRenderer>())
|
||||
{
|
||||
recorder.Bind(EditorCurveBinding.FloatCurve(path, typeof(SpriteRenderer), "m_Enabled"));
|
||||
recorder.Bind(EditorCurveBinding.PPtrCurve(path, typeof(SpriteRenderer), "m_Sprite"));
|
||||
}
|
||||
else if (gameObject.GetComponent<MeshRenderer>())
|
||||
{
|
||||
recorder.Bind(EditorCurveBinding.DiscreteCurve(path, typeof(MeshRenderer), "m_Enabled"));
|
||||
}
|
||||
recorder.Bind(EditorCurveBinding.FloatCurve(path, typeof(Transform), "m_LocalPosition.x"));
|
||||
recorder.Bind(EditorCurveBinding.FloatCurve(path, typeof(Transform), "m_LocalPosition.y"));
|
||||
recorder.Bind(EditorCurveBinding.FloatCurve(path, typeof(Transform), "m_LocalPosition.z"));
|
||||
}
|
||||
// if (gameObject.GetComponent<SpriteRenderer>())
|
||||
// {
|
||||
// recorder.Bind(EditorCurveBinding.FloatCurve(path, typeof(SpriteRenderer), "m_Enabled"));
|
||||
// recorder.Bind(EditorCurveBinding.PPtrCurve(path, typeof(SpriteRenderer), "m_Sprite"));
|
||||
// }
|
||||
// else if (gameObject.GetComponent<MeshRenderer>())
|
||||
// {
|
||||
// recorder.Bind(EditorCurveBinding.DiscreteCurve(path, typeof(MeshRenderer), "m_Enabled"));
|
||||
// }
|
||||
// recorder.Bind(EditorCurveBinding.FloatCurve(path, typeof(Transform), "m_LocalPosition.x"));
|
||||
// recorder.Bind(EditorCurveBinding.FloatCurve(path, typeof(Transform), "m_LocalPosition.y"));
|
||||
// recorder.Bind(EditorCurveBinding.FloatCurve(path, typeof(Transform), "m_LocalPosition.z"));
|
||||
// }
|
||||
|
||||
EditorCurveBinding[] bindings = recorder.GetBindings();
|
||||
foreach (EditorCurveBinding binding in bindings)
|
||||
{
|
||||
Debug.Log($"{binding.path}, {binding.propertyName}, {binding.type}");
|
||||
}
|
||||
}
|
||||
// EditorCurveBinding[] bindings = recorder.GetBindings();
|
||||
// foreach (EditorCurveBinding binding in bindings)
|
||||
// {
|
||||
// Debug.Log($"{binding.path}, {binding.propertyName}, {binding.type}");
|
||||
// }
|
||||
// }
|
||||
|
||||
private static string GetGameObjectPathToObject(GameObject obj, Transform target)
|
||||
{
|
||||
string path = "/" + obj.name;
|
||||
while (!obj.transform.parent.Equals(target))
|
||||
{
|
||||
obj = obj.transform.parent.gameObject;
|
||||
path = "/" + obj.name + path;
|
||||
}
|
||||
Debug.Log($"GetGameObjectPathToTransform from {obj} to {target.gameObject} gives {path}");
|
||||
return path;
|
||||
}
|
||||
// private static string GetGameObjectPathToObject(GameObject obj, Transform target)
|
||||
// {
|
||||
// string path = "/" + obj.name;
|
||||
// while (!obj.transform.parent.Equals(target))
|
||||
// {
|
||||
// obj = obj.transform.parent.gameObject;
|
||||
// path = "/" + obj.name + path;
|
||||
// }
|
||||
// Debug.Log($"GetGameObjectPathToTransform from {obj} to {target.gameObject} gives {path}");
|
||||
// return path;
|
||||
// }
|
||||
|
||||
void LateUpdate()
|
||||
{
|
||||
if (clip == null)
|
||||
return;
|
||||
// void LateUpdate()
|
||||
// {
|
||||
// if (clip == null)
|
||||
// return;
|
||||
|
||||
recorder.TakeSnapshot(Time.deltaTime);
|
||||
}
|
||||
// recorder.TakeSnapshot(Time.deltaTime);
|
||||
// }
|
||||
|
||||
void OnDisable()
|
||||
{
|
||||
if (clip == null)
|
||||
return;
|
||||
// void OnDisable()
|
||||
// {
|
||||
// if (clip == null)
|
||||
// return;
|
||||
|
||||
if (recorder.isRecording)
|
||||
{
|
||||
recorder.SaveToClip(clip);
|
||||
RemoveUnneededCurves(clip);
|
||||
}
|
||||
}
|
||||
// if (recorder.isRecording)
|
||||
// {
|
||||
// recorder.SaveToClip(clip);
|
||||
// RemoveUnneededCurves(clip);
|
||||
// }
|
||||
// }
|
||||
|
||||
private static void RemoveUnneededCurves(AnimationClip clip)
|
||||
{
|
||||
// Collect curves to process
|
||||
EditorCurveBinding[] bindings = AnimationUtility.GetCurveBindings(clip);
|
||||
List<EditorCurveBinding> unneededCurves = new List<EditorCurveBinding>();
|
||||
// private static void RemoveUnneededCurves(AnimationClip clip)
|
||||
// {
|
||||
// // Collect curves to process
|
||||
// EditorCurveBinding[] bindings = AnimationUtility.GetCurveBindings(clip);
|
||||
// List<EditorCurveBinding> unneededCurves = new List<EditorCurveBinding>();
|
||||
|
||||
foreach (var binding in bindings)
|
||||
{
|
||||
AnimationCurve curve = AnimationUtility.GetEditorCurve(clip, binding);
|
||||
// foreach (var binding in bindings)
|
||||
// {
|
||||
// AnimationCurve curve = AnimationUtility.GetEditorCurve(clip, binding);
|
||||
|
||||
if (curve == null || curve.keys.Length <= 2)
|
||||
{
|
||||
unneededCurves.Add(binding);
|
||||
}
|
||||
}
|
||||
// if (curve == null || curve.keys.Length <= 2)
|
||||
// {
|
||||
// unneededCurves.Add(binding);
|
||||
// }
|
||||
// }
|
||||
|
||||
// Remove unchanged curves
|
||||
foreach (var binding in unneededCurves)
|
||||
{
|
||||
AnimationUtility.SetEditorCurve(clip, binding, null);
|
||||
Debug.Log($"Removed unchanged curve for property: {binding.propertyName}");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
// // Remove unchanged curves
|
||||
// foreach (var binding in unneededCurves)
|
||||
// {
|
||||
// AnimationUtility.SetEditorCurve(clip, binding, null);
|
||||
// Debug.Log($"Removed unchanged curve for property: {binding.propertyName}");
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
//}
|
||||
File diff suppressed because it is too large
Load Diff
@@ -425,9 +425,9 @@ namespace Marro.PacManUdon
|
||||
|
||||
public override void AppendSyncedData(byte[][] data, ref int offset)
|
||||
{
|
||||
data[offset++] = new byte[] { (byte)gameState };
|
||||
data[offset++] = new byte[] { Int32ToByte((int)gameState) };
|
||||
data[offset++] = BitConverter.GetBytes(currentlyInTimeSequence);
|
||||
data[offset++] = new byte[] { (byte) currentTimeSequence };
|
||||
data[offset++] = new byte[] { Int32ToByte((int)currentTimeSequence) };
|
||||
data[offset++] = BitConverter.GetBytes(timeSequenceProgress);
|
||||
}
|
||||
|
||||
@@ -497,5 +497,8 @@ namespace Marro.PacManUdon
|
||||
}
|
||||
get => level;
|
||||
}
|
||||
|
||||
public static byte Int32ToByte(int value) =>
|
||||
byte.Parse(value.ToString()); // This is the only way I could find to cast an int to byte in Udon, a regular cast crashes in runtime...
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,7 @@
|
||||
using Assets.Scripts;
|
||||
using JetBrains.Annotations;
|
||||
using System;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using UdonSharp;
|
||||
using UnityEngine;
|
||||
@@ -84,8 +85,23 @@ namespace Marro.PacManUdon
|
||||
obj.AppendSyncedData(data, ref index);
|
||||
}
|
||||
|
||||
var eventSize = 0;
|
||||
for (int i = 0; i < index; i++)
|
||||
{
|
||||
eventSize += data[i].Length;
|
||||
}
|
||||
|
||||
if (!EnsureSpaceToStorePreparedEvent(eventSize))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
var oldIndex = this.index;
|
||||
|
||||
FlattenAndCopy(data, index, buffer, ref this.index);
|
||||
|
||||
Debug.Log($"({nameof(PacManUdon)} {nameof(NetworkManager)}) Prepared event with {eventSize} bytes for serialization, index went from {oldIndex} to {this.index}");
|
||||
|
||||
RequestSerialization();
|
||||
}
|
||||
|
||||
@@ -105,7 +121,7 @@ namespace Marro.PacManUdon
|
||||
var syncType = (NetworkEventType)networkedData[4];
|
||||
var size = networkedData.Length;
|
||||
|
||||
if (!EnsureSpaceToStoreEvent(size, syncType == NetworkEventType.FullSync))
|
||||
if (!EnsureSpaceToStoreReceivedEvent(size, syncType == NetworkEventType.FullSync))
|
||||
{
|
||||
return;
|
||||
}
|
||||
@@ -137,7 +153,7 @@ namespace Marro.PacManUdon
|
||||
}
|
||||
else
|
||||
{
|
||||
Debug.LogError($"({nameof(PacManUdon)} {nameof(NetworkManager)}) Events are in invalid order! Clearing buffer.");
|
||||
Debug.LogWarning($"({nameof(PacManUdon)} {nameof(NetworkManager)}) Events are in invalid order! Clearing buffer.");
|
||||
ClearBuffer();
|
||||
return;
|
||||
}
|
||||
@@ -151,7 +167,7 @@ namespace Marro.PacManUdon
|
||||
switch (eventType)
|
||||
{
|
||||
default:
|
||||
Debug.LogError($"({nameof(PacManUdon)} {nameof(NetworkManager)}) Invalid sync type for incoming data! Buffer will be cleared.");
|
||||
Debug.LogWarning($"({nameof(PacManUdon)} {nameof(NetworkManager)}) Invalid sync type for incoming data! Buffer will be cleared.");
|
||||
ClearBuffer();
|
||||
return;
|
||||
case NetworkEventType.FullSync:
|
||||
@@ -162,14 +178,14 @@ namespace Marro.PacManUdon
|
||||
|
||||
private void ProcessFullSync()
|
||||
{
|
||||
var index = 0;
|
||||
var index = 5; // Skip header
|
||||
foreach (var obj in syncedObjects)
|
||||
{
|
||||
var success = obj.SetSyncedData(buffer, ref index);
|
||||
|
||||
if (!success)
|
||||
{
|
||||
Debug.LogError($"({nameof(PacManUdon)} {nameof(NetworkManager)}) Malformed data reported by {obj.name} during full sync! Clearing buffer and requesting new full sync.");
|
||||
Debug.LogWarning($"({nameof(PacManUdon)} {nameof(NetworkManager)}) Malformed data reported by {obj.name} during full sync! Clearing buffer and requesting new full sync.");
|
||||
ClearBuffer();
|
||||
RequestFullSync();
|
||||
return;
|
||||
@@ -181,7 +197,26 @@ namespace Marro.PacManUdon
|
||||
Debug.Log($"Processed full sync! Total {index} bytes.");
|
||||
}
|
||||
|
||||
private bool EnsureSpaceToStoreEvent(int eventSize, bool isFullSync)
|
||||
private bool EnsureSpaceToStorePreparedEvent(int eventSize)
|
||||
{
|
||||
if (index + eventSize <= buffer.Length)
|
||||
{
|
||||
return true; // Enough space!
|
||||
}
|
||||
|
||||
if (index == 0)
|
||||
{
|
||||
Debug.LogError($"({nameof(PacManUdon)} {nameof(NetworkManager)}) Buffer is not large enough to store event! Viewing remote play is not possible.");
|
||||
return false; // Unable to store event, networking features will not function.
|
||||
}
|
||||
|
||||
ClearBuffer();
|
||||
|
||||
Debug.LogWarning($"({nameof(PacManUdon)} {nameof(NetworkManager)}) Too much data in buffer to store event! Old events will be discarded.");
|
||||
return true; // We can store event now that we cleared the buffer.
|
||||
}
|
||||
|
||||
private bool EnsureSpaceToStoreReceivedEvent(int eventSize, bool isFullSync)
|
||||
{
|
||||
if (index + eventSize <= buffer.Length)
|
||||
{
|
||||
@@ -198,14 +233,14 @@ namespace Marro.PacManUdon
|
||||
|
||||
if (!isFullSync)
|
||||
{
|
||||
Debug.LogError($"({nameof(PacManUdon)} {nameof(NetworkManager)}) Too much data in buffer to store event! Old events will be discarded, and full sync will be performed.");
|
||||
Debug.LogWarning($"({nameof(PacManUdon)} {nameof(NetworkManager)}) Too much data in buffer to store event! Old events will be discarded, and full sync will be performed.");
|
||||
|
||||
RequestFullSync();
|
||||
|
||||
return false; // No use storing this event, we're going to wait for the full sync.
|
||||
}
|
||||
|
||||
Debug.LogError($"({nameof(PacManUdon)} {nameof(NetworkManager)}) Too much data in buffer to store full sync! Old events will be discarded.");
|
||||
Debug.LogWarning($"({nameof(PacManUdon)} {nameof(NetworkManager)}) Too much data in buffer to store full sync! Old events will be discarded.");
|
||||
return true; // We can store event now that we cleared the buffer.
|
||||
}
|
||||
|
||||
@@ -215,8 +250,7 @@ namespace Marro.PacManUdon
|
||||
index = 2;
|
||||
|
||||
data[0] = BitConverter.GetBytes(CurrentTime);
|
||||
byte eventTypeByte = byte.Parse(eventType.ToString());
|
||||
data[1] = new byte[] { eventTypeByte };
|
||||
data[1] = new byte[] { GameManager.Int32ToByte((int)eventType) };
|
||||
}
|
||||
|
||||
private void FlattenAndCopy(byte[][] data, int length, byte[] target, ref int index)
|
||||
|
||||
Reference in New Issue
Block a user