diff --git a/.github/README.md b/.github/README.md index 9601221..3973ed3 100644 --- a/.github/README.md +++ b/.github/README.md @@ -41,6 +41,6 @@ There are 5 ways to install this plugin: ## KNOWN LIMITATIONS -- *static* variables are not searched -- GUIText materials are not searched -- Textures in Lens Flare's can not be searched +- *static* variables aren't searched +- GUIText materials aren't searched +- Textures in Lens Flares can't be searched diff --git a/Plugins/AssetUsageDetector/Editor/AssetUsageDetector.cs b/Plugins/AssetUsageDetector/Editor/AssetUsageDetector.cs index e551dc6..cb5e3da 100644 --- a/Plugins/AssetUsageDetector/Editor/AssetUsageDetector.cs +++ b/Plugins/AssetUsageDetector/Editor/AssetUsageDetector.cs @@ -43,9 +43,9 @@ namespace AssetUsageDetectorNamespace public BindingFlags propertyModifiers = BindingFlags.Public | BindingFlags.NonPublic; public bool searchNonSerializableVariables = true; - public bool lazySceneSearch = false; + public bool lazySceneSearch = true; public bool noAssetDatabaseChanges = false; - public bool showDetailedProgressBar = false; + public bool showDetailedProgressBar = true; } #endregion @@ -100,26 +100,16 @@ namespace AssetUsageDetectorNamespace { if( searchParameters == null ) { - Debug.LogError( "searchParameters must not be null!" ); + Debug.LogError( "'searchParameters' mustn't be null!" ); return new SearchResult( false, null, null, this, searchParameters ); } if( searchParameters.objectsToSearch == null ) { - Debug.LogError( "objectsToSearch list is empty!" ); + Debug.LogError( "'objectsToSearch' list (\"Find references of:\") is empty!" ); return new SearchResult( false, null, null, this, searchParameters ); } - if( !EditorApplication.isPlaying && !Utilities.AreScenesSaved() ) - { - // Don't start the search if at least one scene is currently dirty (not saved) - Debug.LogError( "Save open scenes first!" ); - return new SearchResult( false, null, null, this, searchParameters ); - } - - List searchResult = null; - - isInPlayMode = EditorApplication.isPlaying; #if UNITY_2018_3_OR_NEWER openPrefabStagePrefabAsset = null; string openPrefabStageAssetPath = null; @@ -133,7 +123,7 @@ namespace AssetUsageDetectorNamespace if( openPrefabStage.scene.isDirty ) { // Don't start the search if a prefab stage is currently open and dirty (not saved) - Debug.LogError( "Save open prefabs first!" ); + Debug.LogError( "Save open prefab first!" ); return new SearchResult( false, null, null, this, searchParameters ); } @@ -152,6 +142,15 @@ namespace AssetUsageDetectorNamespace } #endif + List searchResult = null; + isInPlayMode = EditorApplication.isPlaying; + + if( !isInPlayMode && !Utilities.AreScenesSaved() && !EditorUtility.DisplayDialog( "Asset Usage Detector", "Some scene(s) aren't saved. This may result in incorrect search results in those scene(s). Proceed?", "Yes", "Cancel" ) ) + { + Debug.LogError( "Save open scene(s) first!" ); + return new SearchResult( false, null, null, this, searchParameters ); + } + // Get the scenes that are open right now SceneSetup[] initialSceneSetup = !isInPlayMode ? EditorSceneManager.GetSceneManagerSetup() : null; diff --git a/Plugins/AssetUsageDetector/Editor/AssetUsageDetectorWindow.cs b/Plugins/AssetUsageDetector/Editor/AssetUsageDetectorWindow.cs index 4f922ca..cb926e4 100644 --- a/Plugins/AssetUsageDetector/Editor/AssetUsageDetectorWindow.cs +++ b/Plugins/AssetUsageDetector/Editor/AssetUsageDetectorWindow.cs @@ -55,14 +55,10 @@ namespace AssetUsageDetectorNamespace private int searchDepthLimit = 4; // Depth limit for recursively searching variables of objects - private bool restoreInitialSceneSetup = true; // Close the additively loaded scenes that were not part of the initial scene setup - - private string errorMessage = string.Empty; - - private bool lazySceneSearch = false; + private bool lazySceneSearch = true; private bool searchNonSerializableVariables = true; private bool noAssetDatabaseChanges = false; - private bool showDetailedProgressBar = false; + private bool showDetailedProgressBar = true; private BindingFlags fieldModifiers, propertyModifiers; @@ -75,7 +71,6 @@ namespace AssetUsageDetectorNamespace private readonly ObjectListDrawer excludedAssetsDrawer = new ObjectListDrawer( "Don't search following asset(s):", false ); private readonly ObjectListDrawer excludedScenesDrawer = new ObjectListDrawer( "Don't search in following scene(s):", false ); - private readonly GUIContent restoreInitialSceneSetupLabel = new GUIContent( "Restore initial scene setup (Recommended)", "For example, if scene A was open when the search was started and scenes A and B are open after the search is completed, clicking the \"Reset Search\" button will automatically close scene B" ); private readonly GUIContent showTooltipsLabel = new GUIContent( "Show tooltips", "Display nodes' contents in a tooltip when cursor hovers over them" ); private Vector2 scrollPosition = Vector2.zero; @@ -193,7 +188,7 @@ namespace AssetUsageDetectorNamespace private static void ShowAndSearchInternal( IEnumerable searchObjects, AssetUsageDetector.Parameters searchParameters, bool? shouldSearchChildren ) { - if( mainWindow != null && !mainWindow.ReturnToSetupPhase( true, true ) ) + if( mainWindow && !mainWindow.ReturnToSetupPhase() ) { Debug.LogError( "Need to reset the previous search first!" ); return; @@ -281,7 +276,7 @@ namespace AssetUsageDetectorNamespace SavePrefs(); if( searchResult != null && currentPhase == Phase.Complete ) - searchResult.RestoreInitialSceneSetup( true ); + searchResult.RestoreInitialSceneSetup(); } private void OnFocus() @@ -328,9 +323,9 @@ namespace AssetUsageDetectorNamespace } searchNonSerializableVariables = EditorPrefs.GetBool( PREFS_SEARCH_NON_SERIALIZABLES, true ); - lazySceneSearch = EditorPrefs.GetBool( PREFS_LAZY_SCENE_SEARCH, false ); + lazySceneSearch = EditorPrefs.GetBool( PREFS_LAZY_SCENE_SEARCH, true ); searchResultDrawParameters.showTooltips = EditorPrefs.GetBool( PREFS_SHOW_TOOLTIPS, false ); - showDetailedProgressBar = EditorPrefs.GetBool( PREFS_SHOW_PROGRESS, false ); + showDetailedProgressBar = EditorPrefs.GetBool( PREFS_SHOW_PROGRESS, true ); } private SceneSearchMode GetSceneSearchMode( bool hideOptionsInPlayMode ) @@ -380,28 +375,17 @@ namespace AssetUsageDetectorNamespace GUILayout.BeginVertical(); - GUILayout.Space( 10 ); - - // Show the error message, if it is not empty - if( errorMessage.Length > 0 ) - EditorGUILayout.HelpBox( errorMessage, MessageType.Error ); - - GUILayout.Space( 10 ); - if( currentPhase == Phase.Processing ) { // If we are stuck at this phase, then we have encountered an exception GUILayout.Label( ". . . Search in progress or something went wrong (check console) . . ." ); - restoreInitialSceneSetup = EditorGUILayout.ToggleLeft( restoreInitialSceneSetupLabel, restoreInitialSceneSetup ); - if( GUILayout.Button( "RETURN", Utilities.GL_HEIGHT_30 ) ) - ReturnToSetupPhase( restoreInitialSceneSetup, false ); + ReturnToSetupPhase(); } else if( currentPhase == Phase.Setup ) { - if( objectsToSearchDrawer.Draw( objectsToSearch ) ) - errorMessage = string.Empty; + objectsToSearchDrawer.Draw( objectsToSearch ); GUILayout.Space( 10 ); @@ -527,7 +511,7 @@ namespace AssetUsageDetectorNamespace lazySceneSearch = EditorGUILayout.ToggleLeft( "Lazy scene search: scenes are searched in detail only when they are manually refreshed (faster search)", lazySceneSearch ); noAssetDatabaseChanges = EditorGUILayout.ToggleLeft( "I haven't modified any assets/scenes since the last search (faster search)", noAssetDatabaseChanges ); - showDetailedProgressBar = EditorGUILayout.ToggleLeft( "Show detailed progress bar (slower search)", showDetailedProgressBar ); + showDetailedProgressBar = EditorGUILayout.ToggleLeft( "Update search progress bar more often (slower search)", showDetailedProgressBar ); GUILayout.Space( 10 ); @@ -551,10 +535,8 @@ namespace AssetUsageDetectorNamespace GUILayout.Space( 10 ); GUI.enabled = true; - restoreInitialSceneSetup = EditorGUILayout.ToggleLeft( restoreInitialSceneSetupLabel, restoreInitialSceneSetup ); - if( GUILayout.Button( "Reset Search", Utilities.GL_HEIGHT_30 ) ) - ReturnToSetupPhase( restoreInitialSceneSetup, false ); + ReturnToSetupPhase(); if( searchResult == null ) { @@ -647,46 +629,35 @@ namespace AssetUsageDetectorNamespace private void InitiateSearch() { - if( objectsToSearch.IsEmpty() ) - errorMessage = "ADD AN ASSET TO THE LIST FIRST!"; - else if( !EditorApplication.isPlaying && !Utilities.AreScenesSaved() ) - { - // Don't start the search if at least one scene is currently dirty (not saved) - errorMessage = "SAVE OPEN SCENES FIRST!"; - } - else - { - errorMessage = string.Empty; - currentPhase = Phase.Processing; + currentPhase = Phase.Processing; - SavePrefs(); + SavePrefs(); #if UNITY_2018_3_OR_NEWER - ReplacePrefabStageObjectsWithAssets( PrefabStageUtility.GetCurrentPrefabStage() ); + ReplacePrefabStageObjectsWithAssets( PrefabStageUtility.GetCurrentPrefabStage() ); #endif - // Start searching - searchResult = core.Run( new AssetUsageDetector.Parameters() - { - objectsToSearch = new ObjectToSearchEnumerator( objectsToSearch ).ToArray(), - searchInScenes = GetSceneSearchMode( true ), - searchInAssetsFolder = searchInAssetsFolder, - searchInAssetsSubset = !searchInAssetsSubset.IsEmpty() ? searchInAssetsSubset.ToArray() : null, - excludedAssetsFromSearch = !excludedAssets.IsEmpty() ? excludedAssets.ToArray() : null, - dontSearchInSourceAssets = dontSearchInSourceAssets, - excludedScenesFromSearch = !excludedScenes.IsEmpty() ? excludedScenes.ToArray() : null, - searchInProjectSettings = searchInProjectSettings, - //fieldModifiers = fieldModifiers, - //propertyModifiers = propertyModifiers, - //searchDepthLimit = searchDepthLimit, - //searchNonSerializableVariables = searchNonSerializableVariables, - lazySceneSearch = lazySceneSearch, - noAssetDatabaseChanges = noAssetDatabaseChanges, - showDetailedProgressBar = showDetailedProgressBar - } ); + // Start searching + searchResult = core.Run( new AssetUsageDetector.Parameters() + { + objectsToSearch = !objectsToSearch.IsEmpty() ? new ObjectToSearchEnumerator( objectsToSearch ).ToArray() : null, + searchInScenes = GetSceneSearchMode( true ), + searchInAssetsFolder = searchInAssetsFolder, + searchInAssetsSubset = !searchInAssetsSubset.IsEmpty() ? searchInAssetsSubset.ToArray() : null, + excludedAssetsFromSearch = !excludedAssets.IsEmpty() ? excludedAssets.ToArray() : null, + dontSearchInSourceAssets = dontSearchInSourceAssets, + excludedScenesFromSearch = !excludedScenes.IsEmpty() ? excludedScenes.ToArray() : null, + searchInProjectSettings = searchInProjectSettings, + //fieldModifiers = fieldModifiers, + //propertyModifiers = propertyModifiers, + //searchDepthLimit = searchDepthLimit, + //searchNonSerializableVariables = searchNonSerializableVariables, + lazySceneSearch = lazySceneSearch, + noAssetDatabaseChanges = noAssetDatabaseChanges, + showDetailedProgressBar = showDetailedProgressBar + } ); - currentPhase = Phase.Complete; - } + currentPhase = Phase.Complete; } #if UNITY_2018_3_OR_NEWER @@ -729,14 +700,12 @@ namespace AssetUsageDetectorNamespace } #endif - private bool ReturnToSetupPhase( bool restoreInitialSceneSetup, bool sceneSetupRestorationIsOptional ) + private bool ReturnToSetupPhase() { - if( searchResult != null && restoreInitialSceneSetup && !EditorApplication.isPlaying && !searchResult.RestoreInitialSceneSetup( sceneSetupRestorationIsOptional ) ) + if( searchResult != null && !EditorApplication.isPlaying && !searchResult.RestoreInitialSceneSetup() ) return false; searchResult = null; - - errorMessage = string.Empty; currentPhase = Phase.Setup; return true; diff --git a/Plugins/AssetUsageDetector/Editor/SearchResult.cs b/Plugins/AssetUsageDetector/Editor/SearchResult.cs index 5f4f79a..c4ad766 100644 --- a/Plugins/AssetUsageDetector/Editor/SearchResult.cs +++ b/Plugins/AssetUsageDetector/Editor/SearchResult.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.Text; using UnityEditor; using UnityEditor.SceneManagement; using UnityEngine; @@ -328,17 +329,31 @@ 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( bool optional ) + public bool RestoreInitialSceneSetup() { if( initialSceneSetup == null || initialSceneSetup.Length == 0 ) return true; - if( EditorApplication.isPlaying || !EditorSceneManager.SaveCurrentModifiedScenesIfUserWantsTo() ) + if( EditorApplication.isPlaying ) return false; - if( optional && IsSceneSetupDifferentThanCurrentSetup() && !EditorUtility.DisplayDialog( "Scenes", "Restore initial scene setup?", "Yes", "Leave it as is" ) ) + if( !IsSceneSetupDifferentThanCurrentSetup() ) return true; + StringBuilder sb = new StringBuilder( 300 ); + sb.AppendLine( "Restore initial scene setup?" ); + for( int i = 0; i < initialSceneSetup.Length; i++ ) + sb.AppendLine().Append( "- " ).Append( initialSceneSetup[i].path ); + + switch( EditorUtility.DisplayDialogComplex( "Asset Usage Detector", sb.ToString(), "Yes", "Cancel", "Leave it as is" ) ) + { + case 1: return false; + case 2: return true; + } + + if( !EditorSceneManager.SaveCurrentModifiedScenesIfUserWantsTo() ) + return false; + for( int i = 0; i < initialSceneSetup.Length; i++ ) { Scene scene = EditorSceneManager.GetSceneByPath( initialSceneSetup[i].path ); diff --git a/Plugins/AssetUsageDetector/README.txt b/Plugins/AssetUsageDetector/README.txt index 35dd350..dfff56f 100644 --- a/Plugins/AssetUsageDetector/README.txt +++ b/Plugins/AssetUsageDetector/README.txt @@ -3,17 +3,12 @@ Online documentation available at: https://github.com/yasirkula/UnityAssetUsageDetector E-mail: yasirkula@gmail.com -1. ABOUT +### ABOUT This tool helps you find usages of the selected asset(s) and/or Object(s) in your Unity project, i.e. lists the objects that refer to them. -2. HOW TO +### HOW TO Open "Window-Asset Usage Detector" window, configure the settings and hit GO! You can also right click an object and select "Search For References". In the search results page, each row represents a reference to the searched Object(s). Rows can be traversed from left to right to see how the references are formed. If a node's label contains text inside square brackets (e.g. [Child object]), then that text describes how that node is -connected to the node to its left. - -3. KNOWN LIMITATIONS -- static variables are not searched -- GUIText materials are not searched -- Textures in Lens Flare's can not be searched \ No newline at end of file +connected to the node to its left. \ No newline at end of file diff --git a/package.json b/package.json index a582076..3e24f7a 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "com.yasirkula.assetusagedetector", "displayName": "Asset Usage Detector", - "version": "1.9.8", + "version": "1.9.9", "documentationUrl": "https://github.com/yasirkula/UnityAssetUsageDetector", "changelogUrl": "https://github.com/yasirkula/UnityAssetUsageDetector/releases", "licensesUrl": "https://github.com/yasirkula/UnityAssetUsageDetector/blob/master/LICENSE.txt",