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 @@ public SearchResult Run( Parameters searchParameters ) { 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 @@ public SearchResult Run( Parameters searchParameters ) 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 @@ private static void CallSearchSelectedAssetReferencesWithChildrenOnce() 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 @@ 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; 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 @@ 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; @@ -336,6 +336,9 @@ public bool RestoreInitialSceneSetup() 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!" }