From fc106b281e7720b356b40a42040e1abf5ec5c68a Mon Sep 17 00:00:00 2001 From: Merlin <36685500+Merlin-san@users.noreply.github.com> Date: Mon, 7 Sep 2020 14:00:03 -0700 Subject: [PATCH] Change the default behavior of serialization to only copy the root object - The fully recursive copy is an option via ProxySerializationPolicy.All still --- .../Editor/Editors/UdonSharpBehaviourEditor.cs | 10 +++++----- Assets/UdonSharp/Editor/Editors/UdonSharpUndo.cs | 2 +- .../Serialization/ProxySerializationPolicy.cs | 14 ++++++++++++-- Assets/UdonSharp/Editor/UdonSharpEditorUtility.cs | 2 +- .../CustomInspectors/CustomInspectorBehaviour.cs | 2 +- 5 files changed, 20 insertions(+), 10 deletions(-) diff --git a/Assets/UdonSharp/Editor/Editors/UdonSharpBehaviourEditor.cs b/Assets/UdonSharp/Editor/Editors/UdonSharpBehaviourEditor.cs index 64fa151d..e9e7170a 100644 --- a/Assets/UdonSharp/Editor/Editors/UdonSharpBehaviourEditor.cs +++ b/Assets/UdonSharp/Editor/Editors/UdonSharpBehaviourEditor.cs @@ -363,7 +363,7 @@ void OnUndoRedo() System.Type customEditorType = UdonSharpCustomEditorManager.GetInspectorEditorType(inspectorTarget.GetType()); if (customEditorType != null) // Only do the undo copying on things with a custom inspector - UdonSharpEditorUtility.CopyProxyToUdon(inspectorTarget); + UdonSharpEditorUtility.CopyProxyToUdon(inspectorTarget, ProxySerializationPolicy.All); } } @@ -423,7 +423,7 @@ public override void OnInspectorGUI() baseEditor = null; } - UdonSharpBehaviour inspectorTarget = UdonSharpEditorUtility.GetProxyBehaviour(behaviour); + UdonSharpBehaviour inspectorTarget = UdonSharpEditorUtility.GetProxyBehaviour(behaviour, ProxySerializationPolicy.All); inspectorTarget.enabled = false; Editor.CreateCachedEditorWithContext(inspectorTarget, this, customEditorType, ref baseEditor); @@ -434,7 +434,7 @@ public override void OnInspectorGUI() baseEditor.OnInspectorGUI(); - UdonSharpEditorUtility.CopyProxyToUdon(inspectorTarget); + UdonSharpEditorUtility.CopyProxyToUdon(inspectorTarget, ProxySerializationPolicy.All); } else { @@ -483,7 +483,7 @@ private void OnSceneGUI() baseEditor = null; } - UdonSharpBehaviour inspectorTarget = UdonSharpEditorUtility.GetProxyBehaviour(behaviour); + UdonSharpBehaviour inspectorTarget = UdonSharpEditorUtility.GetProxyBehaviour(behaviour, ProxySerializationPolicy.All); inspectorTarget.enabled = false; Editor.CreateCachedEditorWithContext(inspectorTarget, this, customEditorType, ref baseEditor); @@ -492,7 +492,7 @@ private void OnSceneGUI() onSceneGUIMethod.Invoke(baseEditor, null); - UdonSharpEditorUtility.CopyProxyToUdon(inspectorTarget); + UdonSharpEditorUtility.CopyProxyToUdon(inspectorTarget, ProxySerializationPolicy.All); } void DrawDefaultUdonSharpInspector() diff --git a/Assets/UdonSharp/Editor/Editors/UdonSharpUndo.cs b/Assets/UdonSharp/Editor/Editors/UdonSharpUndo.cs index 84fa6e4a..5af1d84d 100644 --- a/Assets/UdonSharp/Editor/Editors/UdonSharpUndo.cs +++ b/Assets/UdonSharp/Editor/Editors/UdonSharpUndo.cs @@ -58,7 +58,7 @@ public static UdonSharpBehaviour AddComponent(GameObject gameObject, System.Type proxyComponent.enabled = false; UdonSharpEditorUtility.SetBackingUdonBehaviour(proxyComponent, udonBehaviour); - UdonSharpEditorUtility.CopyUdonToProxy(proxyComponent, ProxySerializationPolicy.AllWithUndo); + UdonSharpEditorUtility.CopyUdonToProxy(proxyComponent, ProxySerializationPolicy.AllWithCreateUndo); if (EditorApplication.isPlaying) udonBehaviour.InitializeUdonContent(); diff --git a/Assets/UdonSharp/Editor/Serialization/ProxySerializationPolicy.cs b/Assets/UdonSharp/Editor/Serialization/ProxySerializationPolicy.cs index d632483f..866ff6c1 100644 --- a/Assets/UdonSharp/Editor/Serialization/ProxySerializationPolicy.cs +++ b/Assets/UdonSharp/Editor/Serialization/ProxySerializationPolicy.cs @@ -15,14 +15,24 @@ public enum ChildProxyCreateMode public ChildProxyCreateMode ChildProxyMode { get; private set; } = ChildProxyCreateMode.Create; public int MaxSerializationDepth { get; private set; } = int.MaxValue; - internal static readonly ProxySerializationPolicy AllWithUndo = new ProxySerializationPolicy() { ChildProxyMode = ChildProxyCreateMode.CreateWithUndo }; + internal static readonly ProxySerializationPolicy AllWithCreateUndo = new ProxySerializationPolicy() { ChildProxyMode = ChildProxyCreateMode.CreateWithUndo }; [PublicAPI] - public static readonly ProxySerializationPolicy Default = new ProxySerializationPolicy(); + public static readonly ProxySerializationPolicy Default = new ProxySerializationPolicy() { ChildProxyMode = ChildProxyCreateMode.Null, MaxSerializationDepth = 1 }; [PublicAPI] public static readonly ProxySerializationPolicy RootOnly = new ProxySerializationPolicy() { ChildProxyMode = ChildProxyCreateMode.Null, MaxSerializationDepth = 1 }; + /// + /// Copies all properties on all behaviours directly and indirectly referenced by the target behaviour recursively. + /// example: Calling this on the root node of a tree where each node is an UdonSharpBehaviour would copy all node data for every node on the tree + /// + [PublicAPI] + public static readonly ProxySerializationPolicy All = new ProxySerializationPolicy() { ChildProxyMode = ChildProxyCreateMode.Null, MaxSerializationDepth = int.MaxValue }; + + /// + /// Does not run any copy operations, usually used if you want the GetUdonSharpComponent call to not copy any data + /// [PublicAPI] public static readonly ProxySerializationPolicy NoSerialization = new ProxySerializationPolicy() { ChildProxyMode = ChildProxyCreateMode.Null, MaxSerializationDepth = 0 }; diff --git a/Assets/UdonSharp/Editor/UdonSharpEditorUtility.cs b/Assets/UdonSharp/Editor/UdonSharpEditorUtility.cs index f1c94850..4adff2bc 100644 --- a/Assets/UdonSharp/Editor/UdonSharpEditorUtility.cs +++ b/Assets/UdonSharp/Editor/UdonSharpEditorUtility.cs @@ -607,7 +607,7 @@ internal static UdonBehaviour[] ConvertToUdonBehavioursInternal(UdonSharpBehavio try { if (convertChildren) - UdonSharpEditorUtility.CopyProxyToUdon(targetObject, shouldUndo ? ProxySerializationPolicy.AllWithUndo : ProxySerializationPolicy.Default); + UdonSharpEditorUtility.CopyProxyToUdon(targetObject, shouldUndo ? ProxySerializationPolicy.AllWithCreateUndo : ProxySerializationPolicy.All); else UdonSharpEditorUtility.CopyProxyToUdon(targetObject, ProxySerializationPolicy.RootOnly); } diff --git a/Assets/UdonSharp/Examples/CustomInspectors/CustomInspectorBehaviour.cs b/Assets/UdonSharp/Examples/CustomInspectors/CustomInspectorBehaviour.cs index f310488d..867f3063 100644 --- a/Assets/UdonSharp/Examples/CustomInspectors/CustomInspectorBehaviour.cs +++ b/Assets/UdonSharp/Examples/CustomInspectors/CustomInspectorBehaviour.cs @@ -76,7 +76,7 @@ void DrawChildBehaviourControls(CustomInspectorBehaviour inspectorBehaviour) inspectorBehaviour.childBehaviours = inspectorBehaviour.childBehaviours.Append(newChild).ToArray(); // Will recursively apply the child behaviour as well since it is referenced in the childBehaviours array - inspectorBehaviour.ApplyProxyModifications(); + inspectorBehaviour.ApplyProxyModifications(ProxySerializationPolicy.All); } if (GUILayout.Button("Remove child behaviour"))