From 5a81e5011b5ee07233bb5744f31aad1f32514afa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=BCleyman=20Yasir=20KULA?= Date: Tue, 22 Dec 2020 22:46:22 +0300 Subject: [PATCH] While using the Search for References button in right-click menu, if 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 --- .../Editor/AssetUsageDetector.cs | 21 ++++++++++++++++++- .../Editor/AssetUsageDetectorWindow.cs | 17 +++++++-------- .../AssetUsageDetector/Editor/SearchResult.cs | 5 ++++- package.json | 2 +- 4 files changed, 32 insertions(+), 13 deletions(-) diff --git a/Plugins/AssetUsageDetector/Editor/AssetUsageDetector.cs b/Plugins/AssetUsageDetector/Editor/AssetUsageDetector.cs index aad9e57..15028d7 100644 --- a/Plugins/AssetUsageDetector/Editor/AssetUsageDetector.cs +++ b/Plugins/AssetUsageDetector/Editor/AssetUsageDetector.cs @@ -549,9 +549,28 @@ namespace AssetUsageDetectorNamespace { StringBuilder sb = new StringBuilder( objectsToSearchSet.Count * 50 + callStack.Count * 50 + 500 ); sb.AppendLine( "AssetUsageDetector Error:" ).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 @@ namespace AssetUsageDetectorNamespace sb.Append( obj.name ).Append( " (" ).Append( obj.GetType() ).AppendLine( ")" ); } - Debug.LogError( sb.ToString() ); + Debug.LogError( sb.ToString(), latestUnityObjectInCallStack ); try { diff --git a/Plugins/AssetUsageDetector/Editor/AssetUsageDetectorWindow.cs b/Plugins/AssetUsageDetector/Editor/AssetUsageDetectorWindow.cs index 01e6169..4598384 100644 --- a/Plugins/AssetUsageDetector/Editor/AssetUsageDetectorWindow.cs +++ b/Plugins/AssetUsageDetector/Editor/AssetUsageDetectorWindow.cs @@ -193,7 +193,7 @@ namespace AssetUsageDetectorNamespace private static void ShowAndSearchInternal( IEnumerable 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 @@ namespace AssetUsageDetectorNamespace 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 @@ namespace AssetUsageDetectorNamespace 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 @@ namespace AssetUsageDetectorNamespace 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 @@ namespace AssetUsageDetectorNamespace } #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; diff --git a/Plugins/AssetUsageDetector/Editor/SearchResult.cs b/Plugins/AssetUsageDetector/Editor/SearchResult.cs index f5cc370..d3b456e 100644 --- a/Plugins/AssetUsageDetector/Editor/SearchResult.cs +++ b/Plugins/AssetUsageDetector/Editor/SearchResult.cs @@ -328,7 +328,7 @@ namespace AssetUsageDetectorNamespace // 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; @@ -336,6 +336,9 @@ namespace AssetUsageDetectorNamespace 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 ); diff --git a/package.json b/package.json index d76fad5..411b343 100644 --- a/package.json +++ b/package.json @@ -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!" }