Skip to content

Commit

Permalink
While using the Search for References button in right-click menu, if …
Browse files Browse the repository at this point in the history
…current scene setup is different from the initial scene setup, plugin now asks user whether or not they want to restore the initial scene setup instead of automatically restoring the initial scene setup
yasirkula committed Dec 22, 2020
1 parent ba7539d commit 5a81e50
Showing 4 changed files with 32 additions and 13 deletions.
21 changes: 20 additions & 1 deletion Plugins/AssetUsageDetector/Editor/AssetUsageDetector.cs
Original file line number Diff line number Diff line change
@@ -549,9 +549,28 @@ public SearchResult Run( Parameters searchParameters )
{
StringBuilder sb = new StringBuilder( objectsToSearchSet.Count * 50 + callStack.Count * 50 + 500 );
sb.AppendLine( "<b>AssetUsageDetector Error:</b>" ).AppendLine().Append( e ).AppendLine();

Object latestUnityObjectInCallStack = null;
if( callStack.Count > 0 )
{
sb.AppendLine( "Stack contents: " );

for( int i = callStack.Count - 1; i >= 0; i-- )
{
latestUnityObjectInCallStack = callStack[i] as Object;
if( latestUnityObjectInCallStack )
{
if( !AssetDatabase.Contains( latestUnityObjectInCallStack ) )
{
string scenePath = AssetDatabase.GetAssetOrScenePath( latestUnityObjectInCallStack );
if( !string.IsNullOrEmpty( scenePath ) && SceneManager.GetSceneByPath( scenePath ).IsValid() )
sb.Append( "Scene: " ).AppendLine( scenePath );
}

break;
}
}

for( int i = callStack.Count - 1; i >= 0; i-- )
{
sb.Append( i ).Append( ": " );
@@ -575,7 +594,7 @@ public SearchResult Run( Parameters searchParameters )
sb.Append( obj.name ).Append( " (" ).Append( obj.GetType() ).AppendLine( ")" );
}

Debug.LogError( sb.ToString() );
Debug.LogError( sb.ToString(), latestUnityObjectInCallStack );

try
{
17 changes: 7 additions & 10 deletions Plugins/AssetUsageDetector/Editor/AssetUsageDetectorWindow.cs
Original file line number Diff line number Diff line change
@@ -193,7 +193,7 @@ private static void CallSearchSelectedAssetReferencesWithChildrenOnce()

private static void ShowAndSearchInternal( IEnumerable<Object> searchObjects, AssetUsageDetector.Parameters searchParameters, bool? shouldSearchChildren )
{
if( mainWindow != null && !mainWindow.ReturnToSetupPhase( true ) )
if( mainWindow != null && !mainWindow.ReturnToSetupPhase( true, true ) )
{
Debug.LogError( "Need to reset the previous search first!" );
return;
@@ -280,11 +280,8 @@ private void OnDestroy()

SavePrefs();

if( searchResult != null && currentPhase == Phase.Complete && !EditorApplication.isPlaying && searchResult.IsSceneSetupDifferentThanCurrentSetup() )
{
if( EditorUtility.DisplayDialog( "Scenes", "Restore initial scene setup?", "Yes", "Leave it as is" ) )
searchResult.RestoreInitialSceneSetup();
}
if( searchResult != null && currentPhase == Phase.Complete )
searchResult.RestoreInitialSceneSetup( true );
}

private void OnFocus()
@@ -399,7 +396,7 @@ private void OnGUI()
restoreInitialSceneSetup = EditorGUILayout.ToggleLeft( restoreInitialSceneSetupLabel, restoreInitialSceneSetup );

if( GUILayout.Button( "RETURN", Utilities.GL_HEIGHT_30 ) )
ReturnToSetupPhase( restoreInitialSceneSetup );
ReturnToSetupPhase( restoreInitialSceneSetup, false );
}
else if( currentPhase == Phase.Setup )
{
@@ -561,7 +558,7 @@ private void OnGUI()
restoreInitialSceneSetup = EditorGUILayout.ToggleLeft( restoreInitialSceneSetupLabel, restoreInitialSceneSetup );

if( GUILayout.Button( "Reset Search", Utilities.GL_HEIGHT_30 ) )
ReturnToSetupPhase( restoreInitialSceneSetup );
ReturnToSetupPhase( restoreInitialSceneSetup, false );

if( searchResult == null )
{
@@ -736,9 +733,9 @@ public void ReplacePrefabStageObjectsWithAssets( PrefabStage prefabStage )
}
#endif

private bool ReturnToSetupPhase( bool restoreInitialSceneSetup )
private bool ReturnToSetupPhase( bool restoreInitialSceneSetup, bool sceneSetupRestorationIsOptional )
{
if( searchResult != null && restoreInitialSceneSetup && !EditorApplication.isPlaying && !searchResult.RestoreInitialSceneSetup() )
if( searchResult != null && restoreInitialSceneSetup && !EditorApplication.isPlaying && !searchResult.RestoreInitialSceneSetup( sceneSetupRestorationIsOptional ) )
return false;

searchResult = null;
5 changes: 4 additions & 1 deletion Plugins/AssetUsageDetector/Editor/SearchResult.cs
Original file line number Diff line number Diff line change
@@ -328,14 +328,17 @@ public bool IsSceneSetupDifferentThanCurrentSetup()

// Close the scenes that were not part of the initial scene setup
// Returns true if initial scene setup is restored successfully
public bool RestoreInitialSceneSetup()
public bool RestoreInitialSceneSetup( bool optional )
{
if( initialSceneSetup == null || initialSceneSetup.Length == 0 )
return true;

if( EditorApplication.isPlaying || !EditorSceneManager.SaveCurrentModifiedScenesIfUserWantsTo() )
return false;

if( optional && IsSceneSetupDifferentThanCurrentSetup() && !EditorUtility.DisplayDialog( "Scenes", "Restore initial scene setup?", "Yes", "Leave it as is" ) )
return true;

for( int i = 0; i < initialSceneSetup.Length; i++ )
{
Scene scene = EditorSceneManager.GetSceneByPath( initialSceneSetup[i].path );
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "com.yasirkula.assetusagedetector",
"displayName": "Asset Usage Detector",
"version": "1.8.9",
"version": "1.9.0",
"description": "This editor extension helps you figure out at which places an asset or GameObject is used, i.e. lists the objects that refer to the asset. It is possible to search for references in the Assets folder (Project view) and/or in the scene(s) of your project. You can also search for references while in Play mode!"
}

0 comments on commit 5a81e50

Please sign in to comment.