Skip to content
This repository has been archived by the owner on Jan 22, 2022. It is now read-only.

Commit

Permalink
Make child behaviour act consistently on ConvertToUdonBehaviours
Browse files Browse the repository at this point in the history
- `ConvertToUdonBehavioursWithUndo` was converting children behaviours while `ConvertToUdonBehaviours` was not.  Both methods now have an optional parameter to choose whether to convert children and do not by default. Reported by Rael
  • Loading branch information
MerlinVR committed Jan 19, 2021
1 parent 0442495 commit 054d5e9
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 10 deletions.
4 changes: 2 additions & 2 deletions Assets/UdonSharp/Editor/Editors/UdonSharpGUI.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1502,7 +1502,7 @@ public static bool DrawConvertToUdonBehaviourButton(UnityEngine.Object target)
EditorGUI.BeginDisabledGroup(EditorApplication.isPlaying);
if (GUILayout.Button("Convert to UdonBehaviour", GUILayout.Height(25)))
{
UdonSharpEditorUtility.ConvertToUdonBehavioursInternal(new[] { behaviour }, true, true);
UdonSharpEditorUtility.ConvertToUdonBehavioursInternal(new[] { behaviour }, true, true, true);
EditorGUI.EndDisabledGroup();

return true;
Expand Down Expand Up @@ -1547,7 +1547,7 @@ public static bool DrawConvertToUdonBehaviourButton(UnityEngine.Object[] targets
EditorGUI.BeginDisabledGroup(EditorApplication.isPlaying);
if (GUILayout.Button("Convert to UdonBehaviour", GUILayout.Height(25)))
{
UdonSharpEditorUtility.ConvertToUdonBehavioursInternal(Array.ConvertAll(targets, e => e as UdonSharpBehaviour).Where(e => e != null && !UdonSharpEditorUtility.IsProxyBehaviour(e)).ToArray(), true, true);
UdonSharpEditorUtility.ConvertToUdonBehavioursInternal(Array.ConvertAll(targets, e => e as UdonSharpBehaviour).Where(e => e != null && !UdonSharpEditorUtility.IsProxyBehaviour(e)).ToArray(), true, true, true);
EditorGUI.EndDisabledGroup();

return true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ public enum ChildProxyCreateMode
public int MaxSerializationDepth { get; private set; } = int.MaxValue;

internal static readonly ProxySerializationPolicy AllWithCreateUndo = new ProxySerializationPolicy() { ChildProxyMode = ChildProxyCreateMode.CreateWithUndo };
internal static readonly ProxySerializationPolicy AllWithCreate = new ProxySerializationPolicy() { ChildProxyMode = ChildProxyCreateMode.Create };

[PublicAPI]
public static readonly ProxySerializationPolicy Default = new ProxySerializationPolicy() { ChildProxyMode = ChildProxyCreateMode.Null, MaxSerializationDepth = 1 };
Expand Down
14 changes: 6 additions & 8 deletions Assets/UdonSharp/Editor/UdonSharpEditorUtility.cs
Original file line number Diff line number Diff line change
Expand Up @@ -136,9 +136,9 @@ public static void DeleteProgramAsset(UdonSharpProgramAsset programAsset)
/// <param name="components"></param>
/// <returns></returns>
[PublicAPI]
public static UdonBehaviour[] ConvertToUdonBehaviours(UdonSharpBehaviour[] components)
public static UdonBehaviour[] ConvertToUdonBehaviours(UdonSharpBehaviour[] components, bool convertChildren = false)
{
return ConvertToUdonBehavioursInternal(components, false, false);
return ConvertToUdonBehavioursInternal(components, false, false, convertChildren);
}

/// <summary>
Expand All @@ -148,9 +148,9 @@ public static UdonBehaviour[] ConvertToUdonBehaviours(UdonSharpBehaviour[] compo
/// <param name="components"></param>
/// <returns></returns>
[PublicAPI]
public static UdonBehaviour[] ConvertToUdonBehavioursWithUndo(UdonSharpBehaviour[] components)
public static UdonBehaviour[] ConvertToUdonBehavioursWithUndo(UdonSharpBehaviour[] components, bool convertChildren = false)
{
return ConvertToUdonBehavioursInternal(components, true, false);
return ConvertToUdonBehavioursInternal(components, true, false, convertChildren);
}

static internal Dictionary<MonoScript, UdonSharpProgramAsset> _programAssetLookup;
Expand Down Expand Up @@ -587,12 +587,10 @@ internal static void CollectUdonSharpBehaviourReferencesInternal(object rootObje
}
}

internal static UdonBehaviour[] ConvertToUdonBehavioursInternal(UdonSharpBehaviour[] components, bool shouldUndo, bool showPrompts)
internal static UdonBehaviour[] ConvertToUdonBehavioursInternal(UdonSharpBehaviour[] components, bool shouldUndo, bool showPrompts, bool convertChildren)
{
components = components.Distinct().ToArray();

bool convertChildren = true;

if (showPrompts)
{
HashSet<UdonSharpBehaviour> allReferencedBehaviours = new HashSet<UdonSharpBehaviour>();
Expand Down Expand Up @@ -710,7 +708,7 @@ internal static UdonBehaviour[] ConvertToUdonBehavioursInternal(UdonSharpBehavio
try
{
if (convertChildren)
UdonSharpEditorUtility.CopyProxyToUdon(targetObject, shouldUndo ? ProxySerializationPolicy.AllWithCreateUndo : ProxySerializationPolicy.All);
UdonSharpEditorUtility.CopyProxyToUdon(targetObject, shouldUndo ? ProxySerializationPolicy.AllWithCreateUndo : ProxySerializationPolicy.AllWithCreate);
else
UdonSharpEditorUtility.CopyProxyToUdon(targetObject, ProxySerializationPolicy.RootOnly);
}
Expand Down

0 comments on commit 054d5e9

Please sign in to comment.