Skip to content

Commit

Permalink
Change the default behavior of serialization to only copy the root ob…
Browse files Browse the repository at this point in the history
…ject

- The fully recursive copy is an option via ProxySerializationPolicy.All still
  • Loading branch information
MerlinVR committed Sep 7, 2020
1 parent 398f471 commit fc106b2
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 10 deletions.
10 changes: 5 additions & 5 deletions Assets/UdonSharp/Editor/Editors/UdonSharpBehaviourEditor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

Expand Down Expand Up @@ -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);
Expand All @@ -434,7 +434,7 @@ public override void OnInspectorGUI()

baseEditor.OnInspectorGUI();

UdonSharpEditorUtility.CopyProxyToUdon(inspectorTarget);
UdonSharpEditorUtility.CopyProxyToUdon(inspectorTarget, ProxySerializationPolicy.All);
}
else
{
Expand Down Expand Up @@ -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);
Expand All @@ -492,7 +492,7 @@ private void OnSceneGUI()

onSceneGUIMethod.Invoke(baseEditor, null);

UdonSharpEditorUtility.CopyProxyToUdon(inspectorTarget);
UdonSharpEditorUtility.CopyProxyToUdon(inspectorTarget, ProxySerializationPolicy.All);
}

void DrawDefaultUdonSharpInspector()
Expand Down
2 changes: 1 addition & 1 deletion Assets/UdonSharp/Editor/Editors/UdonSharpUndo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
14 changes: 12 additions & 2 deletions Assets/UdonSharp/Editor/Serialization/ProxySerializationPolicy.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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 };

/// <summary>
/// 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
/// </summary>
[PublicAPI]
public static readonly ProxySerializationPolicy All = new ProxySerializationPolicy() { ChildProxyMode = ChildProxyCreateMode.Null, MaxSerializationDepth = int.MaxValue };

/// <summary>
/// Does not run any copy operations, usually used if you want the GetUdonSharpComponent call to not copy any data
/// </summary>
[PublicAPI]
public static readonly ProxySerializationPolicy NoSerialization = new ProxySerializationPolicy() { ChildProxyMode = ChildProxyCreateMode.Null, MaxSerializationDepth = 0 };

Expand Down
2 changes: 1 addition & 1 deletion Assets/UdonSharp/Editor/UdonSharpEditorUtility.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"))
Expand Down

0 comments on commit fc106b2

Please sign in to comment.