Skip to content

Commit

Permalink
Add confirmation dialog for creating program assets from conversion
Browse files Browse the repository at this point in the history
- Add confirmation dialog for creating program assets from convert to UdonBehaviour button when there is no program asset found
- Fix a typo in a method name
  • Loading branch information
MerlinVR committed Sep 23, 2020
1 parent 77c29dc commit 384c3bc
Showing 1 changed file with 15 additions and 7 deletions.
22 changes: 15 additions & 7 deletions Assets/UdonSharp/Editor/UdonSharpEditorUtility.cs
Original file line number Diff line number Diff line change
Expand Up @@ -465,7 +465,7 @@ public static void DestroyImmediate(UdonSharpBehaviour behaviour)
}

#region Internal utilities
internal static void CollectSharpUdonBehaviourReferencesInternal(object rootObject, HashSet<UdonSharpBehaviour> gatheredSet, HashSet<object> visitedSet = null)
internal static void CollectUdonSharpBehaviourReferencesInternal(object rootObject, HashSet<UdonSharpBehaviour> gatheredSet, HashSet<object> visitedSet = null)
{
if (gatheredSet == null)
gatheredSet = new HashSet<UdonSharpBehaviour>();
Expand Down Expand Up @@ -499,7 +499,7 @@ internal static void CollectSharpUdonBehaviourReferencesInternal(object rootObje
{
foreach (object arrayElement in (System.Array)rootObject)
{
CollectSharpUdonBehaviourReferencesInternal(arrayElement, gatheredSet, visitedSet);
CollectUdonSharpBehaviourReferencesInternal(arrayElement, gatheredSet, visitedSet);
}
}
else
Expand All @@ -510,7 +510,7 @@ internal static void CollectSharpUdonBehaviourReferencesInternal(object rootObje
{
object fieldValue = fieldInfo.GetValue(rootObject);

CollectSharpUdonBehaviourReferencesInternal(fieldValue, gatheredSet, visitedSet);
CollectUdonSharpBehaviourReferencesInternal(fieldValue, gatheredSet, visitedSet);
}
}
}
Expand All @@ -530,7 +530,7 @@ internal static UdonBehaviour[] ConvertToUdonBehavioursInternal(UdonSharpBehavio
{
HashSet<UdonSharpBehaviour> referencedBehaviours = new HashSet<UdonSharpBehaviour>();

CollectSharpUdonBehaviourReferencesInternal(targetObject, referencedBehaviours);
CollectUdonSharpBehaviourReferencesInternal(targetObject, referencedBehaviours);

if (referencedBehaviours.Count > 1)
{
Expand Down Expand Up @@ -588,11 +588,16 @@ internal static UdonBehaviour[] ConvertToUdonBehavioursInternal(UdonSharpBehavio

string assetPath = Path.Combine(scriptDirectory, $"{scriptFileName}.asset").Replace('\\', '/');

if (AssetDatabase.LoadAssetAtPath<UdonSharpProgramAsset>(assetPath) != null)
if (EditorUtility.DisplayDialog("No linked program asset", $"There was no UdonSharpProgramAsset found for '{behaviourScript.GetClass()}', do you want to create one?", "Ok", "Cancel"))
{
if (!EditorUtility.DisplayDialog("Existing file found", $"Asset file {assetPath} already exists, do you want to overwrite it?", "Ok", "Cancel"))
continue;
if (AssetDatabase.LoadAssetAtPath<UdonSharpProgramAsset>(assetPath) != null)
{
if (!EditorUtility.DisplayDialog("Existing file found", $"Asset file {assetPath} already exists, do you want to overwrite it?", "Ok", "Cancel"))
continue;
}
}
else
continue;

programAsset = ScriptableObject.CreateInstance<UdonSharpProgramAsset>();
programAsset.sourceCsScript = behaviourScript;
Expand All @@ -608,7 +613,10 @@ internal static UdonBehaviour[] ConvertToUdonBehavioursInternal(UdonSharpBehavio
AssetDatabase.Refresh(ImportAssetOptions.ForceSynchronousImport);
}
else
{
Debug.LogWarning($"Could not convert U# behaviour '{behaviourScript.GetClass()}' on '{targetObject.gameObject}' because it does not have a corresponding UdonSharpProgramAsset");
continue;
}
}

GameObject targetGameObject = targetObject.gameObject;
Expand Down

0 comments on commit 384c3bc

Please sign in to comment.