diff --git a/Plugins/AssetUsageDetector/Editor/AssetUsageDetector.cs b/Plugins/AssetUsageDetector/Editor/AssetUsageDetector.cs index 225bea9..74b700e 100644 --- a/Plugins/AssetUsageDetector/Editor/AssetUsageDetector.cs +++ b/Plugins/AssetUsageDetector/Editor/AssetUsageDetector.cs @@ -12,6 +12,7 @@ using System.Reflection; using System; using System.IO; using UnityEngine.UI; +using System.Text; #if UNITY_2017_1_OR_NEWER using UnityEngine.U2D; #if UNITY_2018_2_OR_NEWER @@ -33,40 +34,27 @@ namespace AssetUsageDetectorNamespace public class AssetUsageDetector { #region Helper Classes + [Serializable] public class Parameters { - public IEnumerable objectsToSearch; + public Object[] objectsToSearch = null; - public SceneSearchMode searchInScenes; - public bool searchInAssetsFolder; - public IEnumerable searchInAssetsSubset; - public IEnumerable excludedAssetsFromSearch; - public bool dontSearchInSourceAssets; - public IEnumerable excludedScenesFromSearch; + public SceneSearchMode searchInScenes = SceneSearchMode.AllScenes; + public Object[] searchInScenesSubset = null; + public bool searchInAssetsFolder = true; + public Object[] searchInAssetsSubset = null; + public Object[] excludedAssetsFromSearch = null; + public bool dontSearchInSourceAssets = false; + public Object[] excludedScenesFromSearch = null; - public int searchDepthLimit; - public BindingFlags fieldModifiers, propertyModifiers; + public int searchDepthLimit = 4; + public BindingFlags fieldModifiers = BindingFlags.Public | BindingFlags.NonPublic; + public BindingFlags propertyModifiers = BindingFlags.Public | BindingFlags.NonPublic; + public bool searchNonSerializableVariables = true; - public bool searchNonSerializableVariables; - public bool noAssetDatabaseChanges; - public bool showProgressBar; - - public Parameters() - { - objectsToSearch = null; - searchInScenes = SceneSearchMode.AllScenes; - searchInAssetsFolder = true; - searchInAssetsSubset = null; - excludedAssetsFromSearch = null; - dontSearchInSourceAssets = false; - excludedScenesFromSearch = null; - searchDepthLimit = 4; - fieldModifiers = BindingFlags.Public | BindingFlags.NonPublic; - propertyModifiers = BindingFlags.Public | BindingFlags.NonPublic; - searchNonSerializableVariables = true; - noAssetDatabaseChanges = false; - showProgressBar = false; - } + public bool lazySceneSearch = false; + public bool noAssetDatabaseChanges = false; + public bool showDetailedProgressBar = false; } private class CacheEntry @@ -119,23 +107,36 @@ namespace AssetUsageDetectorNamespace } #endregion - private HashSet objectsToSearchSet; // A set that contains the searched asset(s) and their sub-assets (if any) + // A set that contains the searched asset(s) and their sub-assets (if any) + private readonly HashSet objectsToSearchSet = new HashSet(); - private HashSet sceneObjectsToSearchSet; // Scene object(s) in objectsToSearchSet - private HashSet sceneObjectsToSearchScenesSet; // sceneObjectsToSearchSet's scene(s) + // Scene object(s) in objectsToSearchSet + private readonly HashSet sceneObjectsToSearchSet = new HashSet(); + // sceneObjectsToSearchSet's scene(s) + private readonly HashSet sceneObjectsToSearchScenesSet = new HashSet(); - private HashSet assetsToSearchSet; // Project asset(s) in objectsToSearchSet - private HashSet assetsToSearchPathsSet; // assetsToSearchSet's path(s) + // Project asset(s) in objectsToSearchSet + private readonly HashSet assetsToSearchSet = new HashSet(); + // assetsToSearchSet's path(s) + private readonly HashSet assetsToSearchPathsSet = new HashSet(); + // The root prefab objects in assetsToSearch that will be used to search for prefab references + private readonly List assetsToSearchRootPrefabs = new List( 4 ); - private SearchResultGroup currentSearchResultGroup; // Results for the currently searched scene + // Results for the currently searched scene + private SearchResultGroup currentSearchResultGroup; - private Dictionary typeToVariables; // An optimization to fetch & filter fields and properties of a class only once - private Dictionary searchedObjects; // An optimization to search an object only once (key is a hash of the searched object) - private Dictionary assetDependencyCache; // An optimization to fetch the dependencies of an asset only once (key is the path of the asset) + // An optimization to fetch & filter fields and properties of a class only once + private readonly Dictionary typeToVariables = new Dictionary( 4096 ); + // An optimization to search an object only once (key is a hash of the searched object) + private readonly Dictionary searchedObjects = new Dictionary( 32768 ); + // An optimization to fetch the dependencies of an asset only once (key is the path of the asset) + private Dictionary assetDependencyCache; - private Dictionary> typeToSearchFunction; // Dictionary to quickly find the function to search a specific type with + // Dictionary to quickly find the function to search a specific type with + private Dictionary> typeToSearchFunction; - private List callStack; // Stack of SearchObject function parameters to avoid infinite loops (which happens when same object is passed as parameter to function) + // Stack of SearchObject function parameters to avoid infinite loops (which happens when same object is passed as parameter to function) + private readonly List callStack = new List( 64 ); private bool searchPrefabConnections; private bool searchMonoBehavioursForScript; @@ -150,6 +151,12 @@ namespace AssetUsageDetectorNamespace private Object currentObject; private int currentDepth; + private bool isInPlayMode; +#if UNITY_2018_3_OR_NEWER + private UnityEditor.Experimental.SceneManagement.PrefabStage openPrefabStage; + private GameObject openPrefabStagePrefabAsset; +#endif + private BindingFlags fieldModifiers, propertyModifiers; private BindingFlags prevFieldModifiers, prevPropertyModifiers; @@ -166,16 +173,53 @@ namespace AssetUsageDetectorNamespace // Search for references! public SearchResult Run( Parameters searchParameters ) { + if( searchParameters == null ) + { + Debug.LogError( "searchParameters must not be null!" ); + return new SearchResult( false, null, null, this, searchParameters ); + } + if( searchParameters.objectsToSearch == null ) { - Debug.LogError( "objectsToSearch list is empty" ); - return new SearchResult( false, null, null ); + Debug.LogError( "objectsToSearch list 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; + openPrefabStage = UnityEditor.Experimental.SceneManagement.PrefabStageUtility.GetCurrentPrefabStage(); + if( openPrefabStage != null ) + { + if( !openPrefabStage.stageHandle.IsValid() ) + openPrefabStage = null; + else + { + 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!" ); + return new SearchResult( false, null, null, this, searchParameters ); + } + + openPrefabStagePrefabAsset = AssetDatabase.LoadAssetAtPath( openPrefabStage.prefabAssetPath ); + openPrefabStageAssetPath = openPrefabStage.prefabAssetPath; + } + } +#endif + // Get the scenes that are open right now - SceneSetup[] initialSceneSetup = !EditorApplication.isPlaying ? EditorSceneManager.GetSceneManagerSetup() : null; + SceneSetup[] initialSceneSetup = !isInPlayMode ? EditorSceneManager.GetSceneManagerSetup() : null; // Make sure the AssetDatabase is up-to-date AssetDatabase.SaveAssets(); @@ -193,45 +237,17 @@ namespace AssetUsageDetectorNamespace // Initialize commonly used variables searchResult = new List(); // Overall search results - if( typeToVariables == null ) - typeToVariables = new Dictionary( 4096 ); - else if( prevFieldModifiers != fieldModifiers || prevPropertyModifiers != propertyModifiers ) + if( prevFieldModifiers != fieldModifiers || prevPropertyModifiers != propertyModifiers ) typeToVariables.Clear(); - if( searchedObjects == null ) - searchedObjects = new Dictionary( 32768 ); - else - searchedObjects.Clear(); - - if( callStack == null ) - callStack = new List( 64 ); - else - callStack.Clear(); - - if( objectsToSearchSet == null ) - objectsToSearchSet = new HashSet(); - else - objectsToSearchSet.Clear(); - - if( sceneObjectsToSearchSet == null ) - sceneObjectsToSearchSet = new HashSet(); - else - sceneObjectsToSearchSet.Clear(); - - if( sceneObjectsToSearchScenesSet == null ) - sceneObjectsToSearchScenesSet = new HashSet(); - else - sceneObjectsToSearchScenesSet.Clear(); - - if( assetsToSearchSet == null ) - assetsToSearchSet = new HashSet(); - else - assetsToSearchSet.Clear(); - - if( assetsToSearchPathsSet == null ) - assetsToSearchPathsSet = new HashSet(); - else - assetsToSearchPathsSet.Clear(); + searchedObjects.Clear(); + callStack.Clear(); + objectsToSearchSet.Clear(); + sceneObjectsToSearchSet.Clear(); + sceneObjectsToSearchScenesSet.Clear(); + assetsToSearchSet.Clear(); + assetsToSearchPathsSet.Clear(); + assetsToSearchRootPrefabs.Clear(); if( assetDependencyCache == null ) { @@ -330,30 +346,36 @@ namespace AssetUsageDetectorNamespace } // Find the scenes to search for references - HashSet openScenes = null; - if( EditorApplication.isPlaying ) + HashSet scenesToSearch = new HashSet(); + if( searchParameters.searchInScenesSubset != null ) { - // In Play mode, only open scenes can be searched - openScenes = new HashSet(); - for( int i = 0; i < EditorSceneManager.loadedSceneCount; i++ ) + foreach( Object obj in searchParameters.searchInScenesSubset ) { - Scene scene = EditorSceneManager.GetSceneAt( i ); - if( scene.IsValid() ) - openScenes.Add( scene.path ); + if( obj == null || obj.Equals( null ) ) + continue; + + if( !obj.IsAsset() ) + continue; + + if( obj.IsFolder() ) + { + string[] folderContents = AssetDatabase.FindAssets( "t:SceneAsset", new string[] { AssetDatabase.GetAssetPath( obj ) } ); + if( folderContents == null ) + continue; + + for( int i = 0; i < folderContents.Length; i++ ) + scenesToSearch.Add( AssetDatabase.GUIDToAssetPath( folderContents[i] ) ); + } + else if( obj is SceneAsset ) + scenesToSearch.Add( AssetDatabase.GetAssetPath( obj ) ); } } - - HashSet scenesToSearch = new HashSet(); - if( ( searchParameters.searchInScenes & SceneSearchMode.AllScenes ) == SceneSearchMode.AllScenes ) + else if( ( searchParameters.searchInScenes & SceneSearchMode.AllScenes ) == SceneSearchMode.AllScenes ) { // Get all scenes from the Assets folder string[] sceneGuids = AssetDatabase.FindAssets( "t:SceneAsset" ); for( int i = 0; i < sceneGuids.Length; i++ ) - { - string scenePath = AssetDatabase.GUIDToAssetPath( sceneGuids[i] ); - if( !EditorApplication.isPlaying || openScenes.Contains( scenePath ) ) - scenesToSearch.Add( scenePath ); - } + scenesToSearch.Add( AssetDatabase.GUIDToAssetPath( sceneGuids[i] ) ); } else { @@ -375,12 +397,35 @@ namespace AssetUsageDetectorNamespace EditorBuildSettingsScene[] scenesTemp = EditorBuildSettings.scenes; for( int i = 0; i < scenesTemp.Length; i++ ) { - if( ( searchInScenesInBuildTickedAll || scenesTemp[i].enabled ) && ( !EditorApplication.isPlaying || openScenes.Contains( scenesTemp[i].path ) ) ) + if( ( searchInScenesInBuildTickedAll || scenesTemp[i].enabled ) ) scenesToSearch.Add( scenesTemp[i].path ); } } } + // In Play mode, only open scenes can be searched + if( isInPlayMode ) + { + HashSet openScenes = new HashSet(); + for( int i = 0; i < EditorSceneManager.loadedSceneCount; i++ ) + { + Scene scene = EditorSceneManager.GetSceneAt( i ); + if( scene.IsValid() ) + openScenes.Add( scene.path ); + } + + scenesToSearch.RemoveWhere( ( path ) => + { + if( !openScenes.Contains( path ) ) + { + Debug.Log( "Can't search unloaded scenes while in play mode, skipped " + path ); + return true; + } + + return false; + } ); + } + // By default, search only serializable variables for references searchSerializableVariablesOnly = !searchParameters.searchNonSerializableVariables; @@ -403,21 +448,23 @@ namespace AssetUsageDetectorNamespace // Progressbar values int searchProgress = 0; int searchTotalProgress = scenesToSearch.Count; - if( EditorApplication.isPlaying ) + if( isInPlayMode && searchParameters.searchInScenes != SceneSearchMode.None ) searchTotalProgress++; // DontDestroyOnLoad scene // Don't search assets if searched object(s) are all scene objects as assets can't hold references to scene objects if( searchParameters.searchInAssetsFolder && assetsToSearchSet.Count > 0 ) { - currentSearchResultGroup = new SearchResultGroup( "Project View (Assets)", false ); + currentSearchResultGroup = new SearchResultGroup( "Project Window (Assets)", SearchResultGroup.GroupType.Assets ); // Get the paths of all assets that are to be searched IEnumerable assetPaths; if( searchParameters.searchInAssetsSubset == null ) { string[] allAssetPaths = AssetDatabase.GetAllAssetPaths(); - searchTotalProgress += allAssetPaths.Length; assetPaths = allAssetPaths; + + if( searchParameters.showDetailedProgressBar ) + searchTotalProgress += allAssetPaths.Length; } else { @@ -437,8 +484,10 @@ namespace AssetUsageDetectorNamespace folderContentsSet.Add( AssetDatabase.GetAssetPath( obj ) ); } - searchTotalProgress += folderContentsSet.Count; assetPaths = folderContentsSet; + + if( searchParameters.showDetailedProgressBar ) + searchTotalProgress += folderContentsSet.Count; } // Calculate the path(s) of the assets that won't be searched for references @@ -463,9 +512,12 @@ namespace AssetUsageDetectorNamespace if( searchParameters.dontSearchInSourceAssets ) excludedAssetsPathsSet.UnionWith( assetsToSearchPathsSet ); + if( EditorUtility.DisplayCancelableProgressBar( "Please wait...", "Searching assets", 0f ) ) + throw new Exception( "Search aborted" ); + foreach( string path in assetPaths ) { - if( searchParameters.showProgressBar && ++searchProgress % 30 == 1 && EditorUtility.DisplayCancelableProgressBar( "Please wait...", "Searching assets", (float) searchProgress / searchTotalProgress ) ) + if( searchParameters.showDetailedProgressBar && ++searchProgress % 30 == 1 && EditorUtility.DisplayCancelableProgressBar( "Please wait...", "Searching assets", (float) searchProgress / searchTotalProgress ) ) throw new Exception( "Search aborted" ); if( excludedAssetsPathsSet.Contains( path ) ) @@ -498,7 +550,7 @@ namespace AssetUsageDetectorNamespace } // Search non-serializable variables for references only if we are currently searching a scene and the editor is in play mode - if( EditorApplication.isPlaying ) + if( isInPlayMode ) searchSerializableVariablesOnly = false; if( scenesToSearch.Count > 0 ) @@ -531,7 +583,7 @@ namespace AssetUsageDetectorNamespace foreach( string scenePath in scenesToSearch ) { - if( searchParameters.showProgressBar && EditorUtility.DisplayCancelableProgressBar( "Please wait...", "Searching scene: " + scenePath, (float) ++searchProgress / searchTotalProgress ) ) + if( EditorUtility.DisplayCancelableProgressBar( "Please wait...", "Searching scene: " + scenePath, (float) ++searchProgress / searchTotalProgress ) ) throw new Exception( "Search aborted" ); // Search scene for references @@ -541,17 +593,17 @@ namespace AssetUsageDetectorNamespace if( excludedScenesPathsSet.Contains( scenePath ) ) continue; - SearchScene( scenePath, searchResult, initialSceneSetup ); + SearchScene( scenePath, searchResult, searchParameters.lazySceneSearch, initialSceneSetup ); } } // Search through all the GameObjects under the DontDestroyOnLoad scene (if exists) - if( EditorApplication.isPlaying ) + if( isInPlayMode && searchParameters.searchInScenes != SceneSearchMode.None ) { - if( searchParameters.showProgressBar && EditorUtility.DisplayCancelableProgressBar( "Please wait...", "Searching scene: DontDestroyOnLoad", 1f ) ) + if( searchParameters.showDetailedProgressBar && EditorUtility.DisplayCancelableProgressBar( "Please wait...", "Searching scene: DontDestroyOnLoad", 1f ) ) throw new Exception( "Search aborted" ); - currentSearchResultGroup = new SearchResultGroup( "DontDestroyOnLoad", false ); + currentSearchResultGroup = new SearchResultGroup( "DontDestroyOnLoad", SearchResultGroup.GroupType.DontDestroyOnLoad ); GameObject[] rootGameObjects = GetDontDestroyOnLoadObjects(); for( int i = 0; i < rootGameObjects.Length; i++ ) @@ -566,12 +618,32 @@ namespace AssetUsageDetectorNamespace // Log some c00l stuff to console Debug.Log( "Searched " + searchedObjectsCount + " objects in " + ( EditorApplication.timeSinceStartup - searchStartTime ).ToString( "F2" ) + " seconds" ); - return new SearchResult( true, searchResult, initialSceneSetup ); + return new SearchResult( true, searchResult, initialSceneSetup, this, searchParameters ); } catch( Exception e ) { Debug.LogException( e ); + if( callStack.Count > 0 ) + { + StringBuilder sb = new StringBuilder( callStack.Count * 50 ); + sb.AppendLine( "Stack contents: " ); + for( int i = 0; i < callStack.Count; i++ ) + { + sb.Append( i ).Append( ": " ); + + Object unityObject = callStack[i] as Object; + if( unityObject != null ) + sb.Append( unityObject.name ).Append( " (" ).Append( unityObject.GetType() ).AppendLine( ")" ); + else if( callStack[i] != null ) + sb.Append( callStack[i].GetType() ).AppendLine( " object" ); + else + sb.AppendLine( "<>" ); + } + + Debug.LogError( sb.ToString() ); + } + try { InitializeSearchResultNodes( searchResult ); @@ -579,7 +651,7 @@ namespace AssetUsageDetectorNamespace catch { } - return new SearchResult( false, searchResult, initialSceneSetup ); + return new SearchResult( false, searchResult, initialSceneSetup, this, searchParameters ); } finally { @@ -587,6 +659,12 @@ namespace AssetUsageDetectorNamespace currentObject = null; EditorUtility.ClearProgressBar(); + +#if UNITY_2018_3_OR_NEWER + // If a prefab stage was open when the search was triggered, try reopening the prefab stage after the search is completed + if( !string.IsNullOrEmpty( openPrefabStageAssetPath ) ) + AssetDatabase.OpenAsset( AssetDatabase.LoadAssetAtPath( openPrefabStageAssetPath ) ); +#endif } } @@ -598,7 +676,7 @@ namespace AssetUsageDetectorNamespace // If there are any empty groups after node initialization, remove those groups for( int i = searchResult.Count - 1; i >= 0; i-- ) { - if( searchResult[i].NumberOfReferences == 0 ) + if( !searchResult[i].PendingSearch && searchResult[i].NumberOfReferences == 0 ) searchResult.RemoveAtFast( i ); } } @@ -614,6 +692,16 @@ namespace AssetUsageDetectorNamespace objectsToSearchSet.Add( obj ); +#if UNITY_2018_3_OR_NEWER + // When searching for references of a prefab stage object, try adding its corresponding prefab asset to the searched assets, as well + if( openPrefabStage != null && openPrefabStagePrefabAsset != null && obj is GameObject && openPrefabStage.IsPartOfPrefabContents( (GameObject) obj ) ) + { + GameObject prefabStageObjectSource = ( (GameObject) obj ).FollowSymmetricHierarchy( openPrefabStagePrefabAsset ); + if( prefabStageObjectSource != null ) + AddSearchedObjectToFilteredSets( prefabStageObjectSource ); + } +#endif + bool isAsset = obj.IsAsset(); if( isAsset ) { @@ -622,6 +710,34 @@ namespace AssetUsageDetectorNamespace string assetPath = AssetDatabase.GetAssetPath( obj ); if( !string.IsNullOrEmpty( assetPath ) ) assetsToSearchPathsSet.Add( assetPath ); + + GameObject go = null; + if( obj is GameObject ) + go = (GameObject) obj; + else if( obj is Component ) + go = ( (Component) obj ).gameObject; + + if( go != null ) + { + Transform transform = go.transform; + bool shouldAddRootPrefabEntry = true; + for( int i = assetsToSearchRootPrefabs.Count - 1; i >= 0; i-- ) + { + Transform rootTransform = assetsToSearchRootPrefabs[i].transform; + + if( transform.IsChildOf( rootTransform ) ) + { + shouldAddRootPrefabEntry = false; + break; + } + + if( rootTransform.IsChildOf( transform ) ) + assetsToSearchRootPrefabs.RemoveAt( i ); + } + + if( shouldAddRootPrefabEntry ) + assetsToSearchRootPrefabs.Add( go ); + } } else { @@ -653,24 +769,32 @@ namespace AssetUsageDetectorNamespace } // Search a scene for references - private void SearchScene( string scenePath, List searchResult, SceneSetup[] initialSceneSetup ) + private void SearchScene( string scenePath, List searchResult, bool lazySearch, SceneSetup[] initialSceneSetup ) { Scene scene = EditorSceneManager.GetSceneByPath( scenePath ); - if( EditorApplication.isPlaying && !scene.isLoaded ) + if( isInPlayMode && !scene.isLoaded ) return; bool canContainSceneObjectReference = scene.isLoaded && ( !EditorSceneManager.preventCrossSceneReferences || sceneObjectsToSearchScenesSet.Contains( scenePath ) ); if( !canContainSceneObjectReference ) { - bool canContainAssetReference = assetsToSearchSet.Count > 0 && ( EditorApplication.isPlaying || AssetHasAnyReference( scenePath ) ); + bool canContainAssetReference = assetsToSearchSet.Count > 0 && ( isInPlayMode || AssetHasAnyReference( scenePath ) ); if( !canContainAssetReference ) return; } - if( !EditorApplication.isPlaying ) - scene = EditorSceneManager.OpenScene( scenePath, OpenSceneMode.Additive ); + if( !scene.isLoaded ) + { + if( lazySearch ) + { + searchResult.Add( new SearchResultGroup( scenePath, SearchResultGroup.GroupType.Scene, true, true ) ); + return; + } - currentSearchResultGroup = new SearchResultGroup( scenePath, true ); + scene = EditorSceneManager.OpenScene( scenePath, OpenSceneMode.Additive ); + } + + currentSearchResultGroup = new SearchResultGroup( scenePath, SearchResultGroup.GroupType.Scene ); // Search through all the GameObjects in the scene GameObject[] rootGameObjects = scene.GetRootGameObjects(); @@ -680,7 +804,7 @@ namespace AssetUsageDetectorNamespace // If no references are found in the scene and if the scene is not part of the initial scene setup, close it if( currentSearchResultGroup.NumberOfReferences == 0 ) { - if( !EditorApplication.isPlaying ) + if( !isInPlayMode ) { bool sceneIsOneOfInitials = false; for( int i = 0; i < initialSceneSetup.Length; i++ ) @@ -790,7 +914,7 @@ namespace AssetUsageDetectorNamespace else { result = PopReferenceNode( unityObject ); - SearchFieldsAndPropertiesOf( result ); + SearchWithSerializedObject( result ); } callStack.RemoveAt( callStack.Count - 1 ); @@ -836,11 +960,10 @@ namespace AssetUsageDetectorNamespace { #if UNITY_2018_3_OR_NEWER Object prefab = PrefabUtility.GetCorrespondingObjectFromSource( go ); - if( objectsToSearchSet.Contains( prefab ) && go == PrefabUtility.GetNearestPrefabInstanceRoot( go ) ) #else Object prefab = PrefabUtility.GetPrefabParent( go ); - if( objectsToSearchSet.Contains( prefab ) && go == PrefabUtility.FindRootGameObjectWithSameParentPrefab( go ) ) #endif + if( objectsToSearchSet.Contains( prefab ) && assetsToSearchRootPrefabs.ContainsFast( prefab as GameObject ) ) referenceNode.AddLinkTo( GetReferenceNode( prefab ), "Prefab object" ); } @@ -915,7 +1038,7 @@ namespace AssetUsageDetectorNamespace } #endif - SearchFieldsAndPropertiesOf( referenceNode ); + SearchWithSerializedObject( referenceNode ); return referenceNode; } @@ -1097,6 +1220,56 @@ namespace AssetUsageDetectorNamespace } #endif + // Search through field and properties of an object for references with SerializedObject + private void SearchWithSerializedObject( ReferenceNode referenceNode ) + { + if( !isInPlayMode || referenceNode.nodeObject.IsAsset() ) + { + SerializedObject so = new SerializedObject( (Object) referenceNode.nodeObject ); + SerializedProperty iterator = so.GetIterator(); + if( iterator.NextVisible( true ) ) + { + bool enterChildren; + do + { + ReferenceNode searchResult; + switch( iterator.propertyType ) + { + case SerializedPropertyType.ObjectReference: + searchResult = SearchObject( iterator.objectReferenceValue ); + enterChildren = false; + break; + case SerializedPropertyType.ExposedReference: + searchResult = SearchObject( iterator.exposedReferenceValue ); + enterChildren = false; + break; + case SerializedPropertyType.Generic: + searchResult = null; + enterChildren = true; + break; + default: + searchResult = null; + enterChildren = false; + break; + } + + if( searchResult != null ) + { + if( searchResult != referenceNode ) + referenceNode.AddLinkTo( searchResult, "Variable: " + iterator.propertyPath ); + else + PoolReferenceNode( searchResult ); + } + } while( iterator.NextVisible( enterChildren ) ); + + return; + } + } + + // Use reflection algorithm as fallback + SearchFieldsAndPropertiesOf( referenceNode ); + } + // Search through field and properties of an object for references private void SearchFieldsAndPropertiesOf( ReferenceNode referenceNode ) { @@ -1114,14 +1287,35 @@ namespace AssetUsageDetectorNamespace if( variableValue == null ) continue; - if( !( variableValue is IEnumerable ) || variableValue is Transform ) - referenceNode.AddLinkTo( SearchObject( variableValue ), ( variables[i].isProperty ? "Property: " : "Variable: " ) + variables[i].name ); - else + // Values stored inside ICollection objects are searched using IEnumerable, + // no need to have duplicate search entries + if( !( variableValue is ICollection ) ) + { + ReferenceNode searchResult = SearchObject( variableValue ); + if( searchResult != null ) + { + if( searchResult != referenceNode ) + referenceNode.AddLinkTo( searchResult, ( variables[i].isProperty ? "Property: " : "Variable: " ) + variables[i].name ); + else + PoolReferenceNode( searchResult ); + } + } + + if( variableValue is IEnumerable && !( variableValue is Transform ) ) { // If the field is IEnumerable (possibly an array or collection), search through members of it // Note that Transform IEnumerable (children of the transform) is not iterated - foreach( object arrayItem in (IEnumerable) variableValue ) - referenceNode.AddLinkTo( SearchObject( arrayItem ), ( variables[i].isProperty ? "Property (IEnumerable): " : "Variable (IEnumerable): " ) + variables[i].name ); + foreach( object element in (IEnumerable) variableValue ) + { + ReferenceNode searchResult = SearchObject( element ); + if( searchResult != null ) + { + if( searchResult != referenceNode ) + referenceNode.AddLinkTo( searchResult, ( variables[i].isProperty ? "Property (IEnumerable): " : "Variable (IEnumerable): " ) + variables[i].name ); + else + PoolReferenceNode( searchResult ); + } + } } } catch( UnassignedReferenceException ) @@ -1282,6 +1476,10 @@ namespace AssetUsageDetectorNamespace // Check if the asset at specified path depends on any of the references private bool AssetHasAnyReference( string assetPath ) { + // "Find references of" assets can contain internal references + if( assetsToSearchPathsSet.Contains( assetPath ) ) + return true; + CacheEntry cacheEntry; if( !assetDependencyCache.TryGetValue( assetPath, out cacheEntry ) ) { @@ -1479,7 +1677,7 @@ namespace AssetUsageDetectorNamespace { for( int i = 0; i < allAssets.Length; i++ ) { - if( i % 30 == 0 && EditorUtility.DisplayCancelableProgressBar( "Please wait...", "Generating cache for the first time", (float) i / allAssets.Length ) ) + if( i % 30 == 0 && EditorUtility.DisplayCancelableProgressBar( "Please wait...", "Generating cache for the first time (optional)", (float) i / allAssets.Length ) ) { EditorUtility.ClearProgressBar(); Debug.LogWarning( "Initial cache generation cancelled, cache will be generated on the fly as more and more assets are searched." ); diff --git a/Plugins/AssetUsageDetector/Editor/AssetUsageDetectorWindow.cs b/Plugins/AssetUsageDetector/Editor/AssetUsageDetectorWindow.cs index 070958a..02bdf1b 100644 --- a/Plugins/AssetUsageDetector/Editor/AssetUsageDetectorWindow.cs +++ b/Plugins/AssetUsageDetector/Editor/AssetUsageDetectorWindow.cs @@ -21,6 +21,7 @@ namespace AssetUsageDetectorNamespace.Extras private const string PREFS_SEARCH_FIELDS = "AUD_Fields"; private const string PREFS_SEARCH_PROPERTIES = "AUD_Properties"; private const string PREFS_SEARCH_NON_SERIALIZABLES = "AUD_NonSerializables"; + private const string PREFS_LAZY_SCENE_SEARCH = "AUD_LazySceneSearch"; private const string PREFS_PATH_DRAWING_MODE = "AUD_PathDrawing"; private const string PREFS_SHOW_PROGRESS = "AUD_Progress"; private const string PREFS_SHOW_TOOLTIPS = "AUD_Tooltips"; @@ -36,7 +37,7 @@ namespace AssetUsageDetectorNamespace.Extras private bool searchInScenesInBuild = true; // Scenes in build private bool searchInScenesInBuildTickedOnly = true; // Scenes in build (ticked only or not) private bool searchInAllScenes = true; // All scenes (including scenes that are not in build) - private bool searchInAssetsFolder = true; // Assets in Project view + private bool searchInAssetsFolder = true; // Assets in Project window private bool dontSearchInSourceAssets = false; // objectsToSearch won't be searched for internal references private List searchInAssetsSubset = new List() { null }; // If not empty, only these assets are searched for references @@ -49,13 +50,14 @@ namespace AssetUsageDetectorNamespace.Extras private string errorMessage = string.Empty; + private bool lazySceneSearch = false; private bool searchNonSerializableVariables = true; private bool noAssetDatabaseChanges = false; - private bool showProgressBar = false; + private bool showDetailedProgressBar = false; private BindingFlags fieldModifiers, propertyModifiers; - private SearchResultDrawParameters searchResultDrawParameters = new SearchResultDrawParameters( PathDrawingMode.ShortRelevantParts, false ); + private SearchResultDrawParameters searchResultDrawParameters = new SearchResultDrawParameters( PathDrawingMode.ShortRelevantParts, false, false ); private double nextPlayModeRefreshTime = 0f; @@ -76,20 +78,31 @@ namespace AssetUsageDetectorNamespace.Extras window.titleContent = new GUIContent( "Asset Usage Detector" ); window.minSize = new Vector2( 325f, 220f ); - window.LoadPrefs(); window.Show(); } // Quickly initiate search for the selected assets + [MenuItem( "GameObject/Search for References", priority = 49 )] [MenuItem( "Assets/Search for References", priority = 1000 )] - private static void SearchSelectedAssetReferences() + private static void SearchSelectedAssetReferences( MenuCommand command ) { - ShowAndSearch( Selection.objects ); + // This happens when this button is clicked via hierarchy's right click context menu + // and is called once for each object in the selection. We don't want that, we want + // the function to be called only once so that there aren't multiple empty parents + // generated in one call + if( command.context ) + { + EditorApplication.update -= CallSearchSelectedAssetReferencesOnce; + EditorApplication.update += CallSearchSelectedAssetReferencesOnce; + } + else + ShowAndSearch( Selection.objects ); } // Show the menu item only if there is a selection in the Editor + [MenuItem( "GameObject/Search for References", validate = true )] [MenuItem( "Assets/Search for References", validate = true )] - private static bool SearchSelectedAssetReferencesValidate() + private static bool SearchSelectedAssetReferencesValidate( MenuCommand command ) { return Selection.objects.Length > 0; } @@ -112,6 +125,12 @@ namespace AssetUsageDetectorNamespace.Extras ShowAndSearchInternal( searchParameters.objectsToSearch, searchParameters ); } + private static void CallSearchSelectedAssetReferencesOnce() + { + EditorApplication.update -= CallSearchSelectedAssetReferencesOnce; + SearchSelectedAssetReferences( new MenuCommand( null ) ); + } + private static void ShowAndSearchInternal( IEnumerable searchObjects, AssetUsageDetector.Parameters searchParameters ) { if( visibleWindow != null && !visibleWindow.ReturnToSetupPhase( true ) ) @@ -138,8 +157,9 @@ namespace AssetUsageDetectorNamespace.Extras visibleWindow.fieldModifiers = searchParameters.fieldModifiers; visibleWindow.propertyModifiers = searchParameters.propertyModifiers; visibleWindow.searchNonSerializableVariables = searchParameters.searchNonSerializableVariables; + visibleWindow.lazySceneSearch = searchParameters.lazySceneSearch; visibleWindow.noAssetDatabaseChanges = searchParameters.noAssetDatabaseChanges; - visibleWindow.showProgressBar = searchParameters.showProgressBar; + visibleWindow.showDetailedProgressBar = searchParameters.showDetailedProgressBar; visibleWindow.searchInAssetsSubset.Clear(); if( searchParameters.searchInAssetsSubset != null ) @@ -166,6 +186,11 @@ namespace AssetUsageDetectorNamespace.Extras visibleWindow.InitiateSearch(); } + private void Awake() + { + LoadPrefs(); + } + private void OnEnable() { visibleWindow = this; @@ -197,8 +222,9 @@ namespace AssetUsageDetectorNamespace.Extras EditorPrefs.SetInt( PREFS_SEARCH_PROPERTIES, (int) propertyModifiers ); EditorPrefs.SetInt( PREFS_PATH_DRAWING_MODE, (int) searchResultDrawParameters.pathDrawingMode ); EditorPrefs.SetBool( PREFS_SEARCH_NON_SERIALIZABLES, searchNonSerializableVariables ); + EditorPrefs.SetBool( PREFS_LAZY_SCENE_SEARCH, lazySceneSearch ); EditorPrefs.SetBool( PREFS_SHOW_TOOLTIPS, searchResultDrawParameters.showTooltips ); - EditorPrefs.SetBool( PREFS_SHOW_PROGRESS, showProgressBar ); + EditorPrefs.SetBool( PREFS_SHOW_PROGRESS, showDetailedProgressBar ); } private void LoadPrefs() @@ -223,8 +249,9 @@ namespace AssetUsageDetectorNamespace.Extras } searchNonSerializableVariables = EditorPrefs.GetBool( PREFS_SEARCH_NON_SERIALIZABLES, true ); + lazySceneSearch = EditorPrefs.GetBool( PREFS_LAZY_SCENE_SEARCH, false ); searchResultDrawParameters.showTooltips = EditorPrefs.GetBool( PREFS_SHOW_TOOLTIPS, false ); - showProgressBar = EditorPrefs.GetBool( PREFS_SHOW_PROGRESS, false ); + showDetailedProgressBar = EditorPrefs.GetBool( PREFS_SHOW_PROGRESS, false ); } private SceneSearchMode GetSceneSearchMode( bool hideOptionsInPlayMode ) @@ -279,7 +306,7 @@ namespace AssetUsageDetectorNamespace.Extras if( currentPhase == Phase.Processing ) { // If we are stuck at this phase, then we have encountered an exception - GUILayout.Label( ". . . Something went wrong, check console . . ." ); + GUILayout.Label( ". . . Search in progress or something went wrong (check console) . . ." ); restoreInitialSceneSetup = EditorGUILayout.ToggleLeft( "Restore initial scene setup (Recommended)", restoreInitialSceneSetup ); @@ -295,7 +322,7 @@ namespace AssetUsageDetectorNamespace.Extras GUILayout.Box( "SEARCH IN", Utilities.BoxGUIStyle, Utilities.GL_EXPAND_WIDTH ); - searchInAssetsFolder = EditorGUILayout.ToggleLeft( "Project view (Assets folder)", searchInAssetsFolder ); + searchInAssetsFolder = EditorGUILayout.ToggleLeft( "Project window (Assets folder)", searchInAssetsFolder ); if( searchInAssetsFolder ) { @@ -350,58 +377,66 @@ namespace AssetUsageDetectorNamespace.Extras GUILayout.Space( 10 ); - GUILayout.Box( "SEARCH SETTINGS", Utilities.BoxGUIStyle, Utilities.GL_EXPAND_WIDTH ); + //GUILayout.Box( "SEARCH SETTINGS", Utilities.BoxGUIStyle, Utilities.GL_EXPAND_WIDTH ); - GUILayout.BeginHorizontal(); + //GUILayout.BeginHorizontal(); - GUILayout.Label( new GUIContent( "> Search depth: " + searchDepthLimit, "Depth limit for recursively searching variables of objects" ), Utilities.GL_WIDTH_250 ); + //GUILayout.Label( new GUIContent( "> Search depth: " + searchDepthLimit, "Depth limit for recursively searching variables of objects" ), Utilities.GL_WIDTH_250 ); - searchDepthLimit = (int) GUILayout.HorizontalSlider( searchDepthLimit, 0, 4 ); + //searchDepthLimit = (int) GUILayout.HorizontalSlider( searchDepthLimit, 0, 4 ); - GUILayout.EndHorizontal(); + //GUILayout.EndHorizontal(); - GUILayout.Label( "> Search variables:" ); + //GUILayout.Label( "> Search variables:" ); - GUILayout.BeginHorizontal(); + //GUILayout.BeginHorizontal(); - GUILayout.Space( 35 ); + //GUILayout.Space( 35 ); - if( EditorGUILayout.ToggleLeft( "Public", ( fieldModifiers & BindingFlags.Public ) == BindingFlags.Public, Utilities.GL_WIDTH_100 ) ) - fieldModifiers |= BindingFlags.Public; - else - fieldModifiers &= ~BindingFlags.Public; + //if( EditorGUILayout.ToggleLeft( "Public", ( fieldModifiers & BindingFlags.Public ) == BindingFlags.Public, Utilities.GL_WIDTH_100 ) ) + // fieldModifiers |= BindingFlags.Public; + //else + // fieldModifiers &= ~BindingFlags.Public; - if( EditorGUILayout.ToggleLeft( "Non-public", ( fieldModifiers & BindingFlags.NonPublic ) == BindingFlags.NonPublic, Utilities.GL_WIDTH_100 ) ) - fieldModifiers |= BindingFlags.NonPublic; - else - fieldModifiers &= ~BindingFlags.NonPublic; + //if( EditorGUILayout.ToggleLeft( "Non-public", ( fieldModifiers & BindingFlags.NonPublic ) == BindingFlags.NonPublic, Utilities.GL_WIDTH_100 ) ) + // fieldModifiers |= BindingFlags.NonPublic; + //else + // fieldModifiers &= ~BindingFlags.NonPublic; - GUILayout.EndHorizontal(); + //GUILayout.EndHorizontal(); - GUILayout.Label( "> Search properties:" ); + //GUILayout.Label( "> Search properties:" ); - GUILayout.BeginHorizontal(); + //GUILayout.BeginHorizontal(); - GUILayout.Space( 35 ); + //GUILayout.Space( 35 ); - if( EditorGUILayout.ToggleLeft( "Public", ( propertyModifiers & BindingFlags.Public ) == BindingFlags.Public, Utilities.GL_WIDTH_100 ) ) - propertyModifiers |= BindingFlags.Public; - else - propertyModifiers &= ~BindingFlags.Public; + //if( EditorGUILayout.ToggleLeft( "Public", ( propertyModifiers & BindingFlags.Public ) == BindingFlags.Public, Utilities.GL_WIDTH_100 ) ) + // propertyModifiers |= BindingFlags.Public; + //else + // propertyModifiers &= ~BindingFlags.Public; - if( EditorGUILayout.ToggleLeft( "Non-public", ( propertyModifiers & BindingFlags.NonPublic ) == BindingFlags.NonPublic, Utilities.GL_WIDTH_100 ) ) - propertyModifiers |= BindingFlags.NonPublic; - else - propertyModifiers &= ~BindingFlags.NonPublic; + //if( EditorGUILayout.ToggleLeft( "Non-public", ( propertyModifiers & BindingFlags.NonPublic ) == BindingFlags.NonPublic, Utilities.GL_WIDTH_100 ) ) + // propertyModifiers |= BindingFlags.NonPublic; + //else + // propertyModifiers &= ~BindingFlags.NonPublic; - GUILayout.EndHorizontal(); + //GUILayout.EndHorizontal(); + + //GUILayout.Space( 10 ); + + //searchNonSerializableVariables = EditorGUILayout.ToggleLeft( "Search non-serializable fields and properties", searchNonSerializableVariables ); + + //GUILayout.Space( 10 ); + + GUILayout.Box( "SETTINGS", Utilities.BoxGUIStyle, Utilities.GL_EXPAND_WIDTH ); + + 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 ); GUILayout.Space( 10 ); - searchNonSerializableVariables = EditorGUILayout.ToggleLeft( "Include non-serializable fields and properties in search (slower search)", searchNonSerializableVariables ); - noAssetDatabaseChanges = EditorGUILayout.ToggleLeft( "I haven't modified any assets/scenes since the last search (faster search)", noAssetDatabaseChanges ); - showProgressBar = EditorGUILayout.ToggleLeft( "Show progress bar (slower search)", showProgressBar ); - // Don't let the user press the GO button without any valid search location if( !searchInAllScenes && !searchInOpenScenes && !searchInScenesInBuild && !searchInAssetsFolder ) GUI.enabled = false; @@ -437,35 +472,39 @@ namespace AssetUsageDetectorNamespace.Extras GUILayout.Box( "Don't forget to save scene(s) if you made any changes!", Utilities.BoxGUIStyle, Utilities.GL_EXPAND_WIDTH ); GUI.color = c; - GUILayout.Space( 10 ); - if( searchResult.NumberOfGroups == 0 ) - GUILayout.Box( "No results found...", Utilities.BoxGUIStyle, Utilities.GL_EXPAND_WIDTH ); + { + GUILayout.Space( 10 ); + GUILayout.Box( "No references found...", Utilities.BoxGUIStyle, Utilities.GL_EXPAND_WIDTH ); + } else { - GUILayout.BeginHorizontal(); + //GUILayout.Space( 10 ); + //GUILayout.BeginHorizontal(); - // Select all the references after filtering them (select only the GameObject's) - if( GUILayout.Button( "Select All\n(GameObject-wise)", Utilities.GL_HEIGHT_35 ) ) - { - GameObject[] objects = searchResult.SelectAllAsGameObjects(); - if( objects != null && objects.Length > 0 ) - Selection.objects = objects; - } + //// Select all the references after filtering them (select only the GameObject's) + //if( GUILayout.Button( "Select All\n(GameObject-wise)", Utilities.GL_HEIGHT_35 ) ) + //{ + // GameObject[] objects = searchResult.SelectAllAsGameObjects(); + // if( objects != null && objects.Length > 0 ) + // Selection.objects = objects; + //} - // Select all the references without filtering them - if( GUILayout.Button( "Select All\n(Object-wise)", Utilities.GL_HEIGHT_35 ) ) - { - Object[] objects = searchResult.SelectAllAsObjects(); - if( objects != null && objects.Length > 0 ) - Selection.objects = objects; - } + //// Select all the references without filtering them + //if( GUILayout.Button( "Select All\n(Object-wise)", Utilities.GL_HEIGHT_35 ) ) + //{ + // Object[] objects = searchResult.SelectAllAsObjects(); + // if( objects != null && objects.Length > 0 ) + // Selection.objects = objects; + //} - GUILayout.EndHorizontal(); + //GUILayout.EndHorizontal(); - GUILayout.Space( 10 ); + //GUILayout.Space( 10 ); searchResultDrawParameters.showTooltips = EditorGUILayout.ToggleLeft( "Show tooltips", searchResultDrawParameters.showTooltips ); + noAssetDatabaseChanges = EditorGUILayout.ToggleLeft( "I haven't modified any assets/scenes since the last search (faster Refresh)", noAssetDatabaseChanges ); + searchResultDrawParameters.noAssetDatabaseChanges = noAssetDatabaseChanges; GUILayout.Space( 10 ); @@ -525,22 +564,45 @@ namespace AssetUsageDetectorNamespace.Extras SavePrefs(); +#if UNITY_2018_3_OR_NEWER + // Try replacing prefab stage objects with their corresponding prefab assets + var openPrefabStage = UnityEditor.Experimental.SceneManagement.PrefabStageUtility.GetCurrentPrefabStage(); + if( openPrefabStage != null && openPrefabStage.stageHandle.IsValid() ) + { + GameObject openPrefabStagePrefabAsset = AssetDatabase.LoadAssetAtPath( openPrefabStage.prefabAssetPath ); + if( openPrefabStagePrefabAsset != null ) + { + for( int i = 0; i < objectsToSearch.Count; i++ ) + { + if( objectsToSearch[i].obj != null && !objectsToSearch[i].obj.Equals( null ) && + objectsToSearch[i].obj is GameObject && openPrefabStage.IsPartOfPrefabContents( (GameObject) objectsToSearch[i].obj ) ) + { + GameObject prefabStageObjectSource = ( (GameObject) objectsToSearch[i].obj ).FollowSymmetricHierarchy( openPrefabStagePrefabAsset ); + if( prefabStageObjectSource != null ) + objectsToSearch[i].obj = prefabStageObjectSource; + } + } + } + } +#endif + // Start searching searchResult = core.Run( new AssetUsageDetector.Parameters() { - objectsToSearch = !objectsToSearch.IsEmpty() ? new ObjectToSearchEnumerator( objectsToSearch ) : null, + objectsToSearch = new ObjectToSearchEnumerator( objectsToSearch ).ToArray(), searchInScenes = GetSceneSearchMode( true ), searchInAssetsFolder = searchInAssetsFolder, - searchInAssetsSubset = !searchInAssetsSubset.IsEmpty() ? searchInAssetsSubset : null, - excludedAssetsFromSearch = !excludedAssets.IsEmpty() ? excludedAssets : null, + searchInAssetsSubset = !searchInAssetsSubset.IsEmpty() ? searchInAssetsSubset.ToArray() : null, + excludedAssetsFromSearch = !excludedAssets.IsEmpty() ? excludedAssets.ToArray() : null, dontSearchInSourceAssets = dontSearchInSourceAssets, - excludedScenesFromSearch = !excludedScenes.IsEmpty() ? excludedScenes : null, - fieldModifiers = fieldModifiers, - propertyModifiers = propertyModifiers, - searchDepthLimit = searchDepthLimit, - searchNonSerializableVariables = searchNonSerializableVariables, + excludedScenesFromSearch = !excludedScenes.IsEmpty() ? excludedScenes.ToArray() : null, + //fieldModifiers = fieldModifiers, + //propertyModifiers = propertyModifiers, + //searchDepthLimit = searchDepthLimit, + //searchNonSerializableVariables = searchNonSerializableVariables, + lazySceneSearch = lazySceneSearch, noAssetDatabaseChanges = noAssetDatabaseChanges, - showProgressBar = showProgressBar + showDetailedProgressBar = showDetailedProgressBar } ); currentPhase = Phase.Complete; diff --git a/Plugins/AssetUsageDetector/Editor/Enumerators.cs b/Plugins/AssetUsageDetector/Editor/Enumerators.cs index 42df39d..f493424 100644 --- a/Plugins/AssetUsageDetector/Editor/Enumerators.cs +++ b/Plugins/AssetUsageDetector/Editor/Enumerators.cs @@ -112,5 +112,19 @@ namespace AssetUsageDetectorNamespace.Extras { return GetEnumerator(); } + + public Object[] ToArray() + { + int count = 0; + foreach( Object obj in this ) + count++; + + Object[] result = new Object[count]; + int index = 0; + foreach( Object obj in this ) + result[index++] = obj; + + return result; + } } } \ No newline at end of file diff --git a/Plugins/AssetUsageDetector/Editor/ListDrawer.cs b/Plugins/AssetUsageDetector/Editor/ListDrawer.cs index 3553263..e120415 100644 --- a/Plugins/AssetUsageDetector/Editor/ListDrawer.cs +++ b/Plugins/AssetUsageDetector/Editor/ListDrawer.cs @@ -46,8 +46,22 @@ namespace AssetUsageDetectorNamespace.Extras { if( draggedObjects[i] != null && !draggedObjects[i].Equals( null ) ) { + bool replacedNullElement = false; + for( int j = 0; j < list.Count; j++ ) + { + if( IsElementNull( list[j] ) ) + { + list[j] = CreateElement( draggedObjects[i] ); + + replacedNullElement = true; + break; + } + } + + if( !replacedNullElement ) + list.Add( CreateElement( draggedObjects[i] ) ); + hasChanged = true; - list.Add( CreateElement( draggedObjects[i] ) ); } } } @@ -107,6 +121,7 @@ namespace AssetUsageDetectorNamespace.Extras protected abstract T CreateElement( Object source ); protected abstract Object GetObjectFromElement( T element ); protected abstract void SetObjectOfElement( List list, int index, Object value ); + protected abstract bool IsElementNull( T element ); protected abstract void PostElementDrawer( T element ); } @@ -131,6 +146,11 @@ namespace AssetUsageDetectorNamespace.Extras list[index] = value; } + protected override bool IsElementNull( Object element ) + { + return element == null || element.Equals( null ); + } + protected override void PostElementDrawer( Object element ) { } @@ -158,6 +178,11 @@ namespace AssetUsageDetectorNamespace.Extras list[index].RefreshSubAssets(); } + protected override bool IsElementNull( ObjectToSearch element ) + { + return element == null || element.obj == null || element.obj.Equals( null ); + } + protected override void PostElementDrawer( ObjectToSearch element ) { List subAssetsToSearch = element.subAssets; diff --git a/Plugins/AssetUsageDetector/Editor/SearchResult.cs b/Plugins/AssetUsageDetector/Editor/SearchResult.cs index d181544..b445e69 100644 --- a/Plugins/AssetUsageDetector/Editor/SearchResult.cs +++ b/Plugins/AssetUsageDetector/Editor/SearchResult.cs @@ -11,14 +11,17 @@ namespace AssetUsageDetectorNamespace [Serializable] public class SearchResultDrawParameters { + public SearchResult searchResult; public PathDrawingMode pathDrawingMode; public bool showTooltips; + public bool noAssetDatabaseChanges; public string tooltip; - public SearchResultDrawParameters( PathDrawingMode pathDrawingMode, bool showTooltips ) + public SearchResultDrawParameters( PathDrawingMode pathDrawingMode, bool showTooltips, bool noAssetDatabaseChanges ) { this.pathDrawingMode = pathDrawingMode; this.showTooltips = showTooltips; + this.noAssetDatabaseChanges = noAssetDatabaseChanges; } } @@ -31,7 +34,9 @@ namespace AssetUsageDetectorNamespace public class SerializableResultGroup { public string title; - public bool clickable; + public SearchResultGroup.GroupType type; + public bool isExpanded; + public bool pendingSearch; public List initialSerializedNodes; } @@ -51,6 +56,9 @@ namespace AssetUsageDetectorNamespace private List result; private SceneSetup[] initialSceneSetup; + private AssetUsageDetector searchHandler; + private AssetUsageDetector.Parameters m_searchParameters; + private List serializedNodes; private List serializedGroups; @@ -59,8 +67,9 @@ namespace AssetUsageDetectorNamespace public bool SearchCompletedSuccessfully { get { return success; } } public bool InitialSceneSetupConfigured { get { return initialSceneSetup != null && initialSceneSetup.Length > 0; } } + public AssetUsageDetector.Parameters SearchParameters { get { return m_searchParameters; } } - public SearchResult( bool success, List result, SceneSetup[] initialSceneSetup ) + public SearchResult( bool success, List result, SceneSetup[] initialSceneSetup, AssetUsageDetector searchHandler, AssetUsageDetector.Parameters searchParameters ) { if( result == null ) result = new List( 0 ); @@ -68,10 +77,107 @@ namespace AssetUsageDetectorNamespace this.success = success; this.result = result; this.initialSceneSetup = initialSceneSetup; + this.searchHandler = searchHandler; + this.m_searchParameters = searchParameters; + } + + public void RefreshSearchResultGroup( SearchResultGroup searchResultGroup, bool noAssetDatabaseChanges ) + { + if( searchResultGroup == null ) + { + Debug.LogError( "SearchResultGroup is null!" ); + return; + } + + int searchResultGroupIndex = -1; + for( int i = 0; i < result.Count; i++ ) + { + if( result[i] == searchResultGroup ) + { + searchResultGroupIndex = i; + break; + } + } + + if( searchResultGroupIndex < 0 ) + { + Debug.LogError( "SearchResultGroup is not a part of SearchResult!" ); + return; + } + + if( searchResultGroup.Type == SearchResultGroup.GroupType.Scene && EditorApplication.isPlaying && !EditorSceneManager.GetSceneByPath( searchResultGroup.Title ).isLoaded ) + { + Debug.LogError( "Can't search unloaded scene while in Play Mode!" ); + return; + } + + if( searchHandler == null ) + searchHandler = new AssetUsageDetector(); + + SceneSearchMode searchInScenes = m_searchParameters.searchInScenes; + Object[] searchInScenesSubset = m_searchParameters.searchInScenesSubset; + bool searchInAssetsFolder = m_searchParameters.searchInAssetsFolder; + Object[] searchInAssetsSubset = m_searchParameters.searchInAssetsSubset; + + try + { + if( searchResultGroup.Type == SearchResultGroup.GroupType.Assets ) + { + m_searchParameters.searchInScenes = SceneSearchMode.None; + m_searchParameters.searchInScenesSubset = null; + } + else if( searchResultGroup.Type == SearchResultGroup.GroupType.Scene ) + { + m_searchParameters.searchInScenes = SceneSearchMode.None; + m_searchParameters.searchInScenesSubset = new Object[1] { AssetDatabase.LoadAssetAtPath( searchResultGroup.Title ) }; + m_searchParameters.searchInAssetsFolder = false; + m_searchParameters.searchInAssetsSubset = null; + } + else + { + m_searchParameters.searchInScenes = (SceneSearchMode) 1024; // A unique value to search only the DontDestroyOnLoad scene + m_searchParameters.searchInScenesSubset = null; + m_searchParameters.searchInAssetsFolder = false; + m_searchParameters.searchInAssetsSubset = null; + } + + m_searchParameters.lazySceneSearch = false; + m_searchParameters.noAssetDatabaseChanges = noAssetDatabaseChanges; + + // Make sure the AssetDatabase is up-to-date + AssetDatabase.SaveAssets(); + + List searchResult = searchHandler.Run( m_searchParameters ).result; + if( searchResult != null ) + { + int newSearchResultGroupIndex = -1; + for( int i = 0; i < searchResult.Count; i++ ) + { + if( searchResultGroup.Title == searchResult[i].Title ) + { + newSearchResultGroupIndex = i; + break; + } + } + + if( newSearchResultGroupIndex >= 0 ) + result[searchResultGroupIndex] = searchResult[newSearchResultGroupIndex]; + else + searchResultGroup.Clear(); + } + } + finally + { + m_searchParameters.searchInScenes = searchInScenes; + m_searchParameters.searchInScenesSubset = searchInScenesSubset; + m_searchParameters.searchInAssetsFolder = searchInAssetsFolder; + m_searchParameters.searchInAssetsSubset = searchInAssetsSubset; + } } public void DrawOnGUI( SearchResultDrawParameters parameters ) { + parameters.searchResult = this; parameters.tooltip = null; for( int i = 0; i < result.Count; i++ ) @@ -232,7 +338,7 @@ namespace AssetUsageDetectorNamespace for( int i = 0; i < serializedGroups.Count; i++ ) { - result.Add( new SearchResultGroup( serializedGroups[i].title, serializedGroups[i].clickable ) ); + result.Add( new SearchResultGroup( serializedGroups[i].title, serializedGroups[i].type, serializedGroups[i].isExpanded, serializedGroups[i].pendingSearch ) ); result[i].Deserialize( serializedGroups[i], allNodes ); } @@ -244,6 +350,8 @@ namespace AssetUsageDetectorNamespace // Custom class to hold the results for a single scene or Assets folder public class SearchResultGroup { + public enum GroupType { Assets = 0, Scene = 1, DontDestroyOnLoad = 2 }; + // Custom struct to hold a single path to a reference public struct ReferencePath { @@ -257,8 +365,10 @@ namespace AssetUsageDetectorNamespace } } - private readonly string title; - private readonly bool clickable; + public string Title { get; private set; } + public GroupType Type { get; private set; } + public bool IsExpanded { get; private set; } + public bool PendingSearch { get; private set; } private readonly List references; private List referencePathsShortUnique; @@ -267,10 +377,12 @@ namespace AssetUsageDetectorNamespace public int NumberOfReferences { get { return references.Count; } } public ReferenceNode this[int index] { get { return references[index]; } } - public SearchResultGroup( string title, bool clickable ) + public SearchResultGroup( string title, GroupType type, bool isExpanded = true, bool pendingSearch = false ) { - this.title = title; - this.clickable = clickable; + Title = title; + Type = type; + IsExpanded = isExpanded; + PendingSearch = pendingSearch; references = new List(); referencePathsShortUnique = null; @@ -283,6 +395,17 @@ namespace AssetUsageDetectorNamespace references.Add( node ); } + // Removes all nodes + public void Clear() + { + references.Clear(); + + if( referencePathsShortUnique != null ) + referencePathsShortUnique.Clear(); + if( referencePathsShortest != null ) + referencePathsShortest.Clear(); + } + // Initializes commonly used variables of the nodes public void InitializeNodes( Func nodeGetter ) { @@ -368,6 +491,9 @@ namespace AssetUsageDetectorNamespace // Add all the Object's in this container to the set public void AddObjectsTo( HashSet objectsSet ) { + if( PendingSearch ) + return; + CalculateShortestPathsToReferences(); for( int i = 0; i < referencePathsShortUnique.Count; i++ ) @@ -381,6 +507,9 @@ namespace AssetUsageDetectorNamespace // Add all the GameObject's in this container to the set public void AddGameObjectsTo( HashSet gameObjectsSet ) { + if( PendingSearch ) + return; + CalculateShortestPathsToReferences(); for( int i = 0; i < referencePathsShortUnique.Count; i++ ) @@ -397,7 +526,7 @@ namespace AssetUsageDetectorNamespace } // Calculate short unique paths to the references - public void CalculateShortestPathsToReferences() + private void CalculateShortestPathsToReferences() { if( referencePathsShortUnique != null ) return; @@ -439,51 +568,83 @@ namespace AssetUsageDetectorNamespace Color c = GUI.color; GUI.color = Color.cyan; - if( GUILayout.Button( title, Utilities.BoxGUIStyle, Utilities.GL_EXPAND_WIDTH, Utilities.GL_HEIGHT_40 ) && clickable ) + Rect rect = EditorGUILayout.GetControlRect( Utilities.GL_EXPAND_WIDTH, Utilities.GL_HEIGHT_40 ); + float width = rect.width; + rect.width = 40f; + if( GUI.Button( rect, IsExpanded ? "v" : ">" ) ) + { + IsExpanded = !IsExpanded; + GUIUtility.ExitGUI(); + } + + rect.x += 40f; + rect.width = width - ( parameters.searchResult != null ? 140f : 40f ); + if( GUI.Button( rect, Title, Utilities.BoxGUIStyle ) && Type == GroupType.Scene ) { // If the container (scene, usually) is clicked, highlight it on Project view - AssetDatabase.LoadAssetAtPath( title ).SelectInEditor(); + AssetDatabase.LoadAssetAtPath( Title ).SelectInEditor(); } - GUI.color = Color.yellow; - - if( parameters.pathDrawingMode == PathDrawingMode.Full ) + if( parameters.searchResult != null ) { - for( int i = 0; i < references.Count; i++ ) + rect.x += width - 140f; + rect.width = 100f; + if( GUI.Button( rect, "Refresh" ) ) { - GUILayout.Space( 5 ); - references[i].DrawOnGUIRecursively( parameters, null ); + parameters.searchResult.RefreshSearchResultGroup( this, parameters.noAssetDatabaseChanges ); + GUIUtility.ExitGUI(); } } - else + + if( IsExpanded ) { - if( referencePathsShortUnique == null ) - CalculateShortestPathsToReferences(); + GUI.color = Color.yellow; - List pathsToDraw; - if( parameters.pathDrawingMode == PathDrawingMode.ShortRelevantParts ) - pathsToDraw = referencePathsShortUnique; + if( PendingSearch ) + GUILayout.Box( "Lazy Search: this scene potentially has some references, hit Refresh to find them", Utilities.BoxGUIStyle ); + else if( references.Count == 0 ) + GUILayout.Box( "No references found...", Utilities.BoxGUIStyle ); else - pathsToDraw = referencePathsShortest; - - for( int i = 0; i < pathsToDraw.Count; i++ ) { - GUILayout.Space( 5 ); - - GUILayout.BeginHorizontal(); - - ReferencePath path = pathsToDraw[i]; - path.startNode.DrawOnGUI( parameters, null ); - - ReferenceNode currentNode = path.startNode; - for( int j = 0; j < path.pathLinksToFollow.Length; j++ ) + if( parameters.pathDrawingMode == PathDrawingMode.Full ) { - ReferenceNode.Link link = currentNode[path.pathLinksToFollow[j]]; - link.targetNode.DrawOnGUI( parameters, link.description ); - currentNode = link.targetNode; + for( int i = 0; i < references.Count; i++ ) + { + GUILayout.Space( 5 ); + references[i].DrawOnGUIRecursively( parameters, null ); + } } + else + { + if( referencePathsShortUnique == null ) + CalculateShortestPathsToReferences(); - GUILayout.EndHorizontal(); + List pathsToDraw; + if( parameters.pathDrawingMode == PathDrawingMode.ShortRelevantParts ) + pathsToDraw = referencePathsShortUnique; + else + pathsToDraw = referencePathsShortest; + + for( int i = 0; i < pathsToDraw.Count; i++ ) + { + GUILayout.Space( 5 ); + + GUILayout.BeginHorizontal(); + + ReferencePath path = pathsToDraw[i]; + path.startNode.DrawOnGUI( parameters, null ); + + ReferenceNode currentNode = path.startNode; + for( int j = 0; j < path.pathLinksToFollow.Length; j++ ) + { + ReferenceNode.Link link = currentNode[path.pathLinksToFollow[j]]; + link.targetNode.DrawOnGUI( parameters, link.description ); + currentNode = link.targetNode; + } + + GUILayout.EndHorizontal(); + } + } } } @@ -497,8 +658,10 @@ namespace AssetUsageDetectorNamespace { SearchResult.SerializableResultGroup serializedResultGroup = new SearchResult.SerializableResultGroup() { - title = title, - clickable = clickable + title = Title, + type = Type, + isExpanded = IsExpanded, + pendingSearch = PendingSearch }; if( references != null ) diff --git a/Plugins/AssetUsageDetector/Editor/Utilities.cs b/Plugins/AssetUsageDetector/Editor/Utilities.cs index 1a06515..0f2b8cb 100644 --- a/Plugins/AssetUsageDetector/Editor/Utilities.cs +++ b/Plugins/AssetUsageDetector/Editor/Utilities.cs @@ -12,26 +12,37 @@ namespace AssetUsageDetectorNamespace.Extras public static class Utilities { // A set of commonly used Unity types - private static readonly HashSet primitiveUnityTypes = new HashSet() { - typeof( string ), typeof( Vector4 ), typeof( Vector3 ), typeof( Vector2 ), typeof( Rect ), - typeof( Quaternion ), typeof( Color ), typeof( Color32 ), typeof( LayerMask ), - typeof( Matrix4x4 ), typeof( AnimationCurve ), typeof( Gradient ), typeof( RectOffset ), - typeof( bool[] ), typeof( byte[] ), typeof( sbyte[] ), typeof( char[] ), typeof( decimal[] ), - typeof( double[] ), typeof( float[] ), typeof( int[] ), typeof( uint[] ), typeof( long[] ), - typeof( ulong[] ), typeof( short[] ), typeof( ushort[] ), typeof( string[] ), - typeof( Vector4[] ), typeof( Vector3[] ), typeof( Vector2[] ), typeof( Rect[] ), - typeof( Quaternion[] ), typeof( Color[] ), typeof( Color32[] ), typeof( LayerMask[] ), - typeof( Matrix4x4[] ), typeof( AnimationCurve[] ), typeof( Gradient[] ), typeof( RectOffset[] ), - typeof( List ), typeof( List ), typeof( List ), typeof( List ), typeof( List ), - typeof( List ), typeof( List ), typeof( List ), typeof( List ), typeof( List ), - typeof( List ), typeof( List ), typeof( List ), typeof( List ), - typeof( List ), typeof( List ), typeof( List ), typeof( List ), - typeof( List ), typeof( List ), typeof( List ), typeof( List ), - typeof( List ), typeof( List ), typeof( List ), typeof( List ) + private static readonly HashSet primitiveUnityTypes = new HashSet() + { + typeof( string ), typeof( Vector4 ), typeof( Vector3 ), typeof( Vector2 ), typeof( Rect ), + typeof( Quaternion ), typeof( Color ), typeof( Color32 ), typeof( LayerMask ), typeof( Bounds ), + typeof( Matrix4x4 ), typeof( AnimationCurve ), typeof( Gradient ), typeof( RectOffset ), + typeof( bool[] ), typeof( byte[] ), typeof( sbyte[] ), typeof( char[] ), typeof( decimal[] ), + typeof( double[] ), typeof( float[] ), typeof( int[] ), typeof( uint[] ), typeof( long[] ), + typeof( ulong[] ), typeof( short[] ), typeof( ushort[] ), typeof( string[] ), + typeof( Vector4[] ), typeof( Vector3[] ), typeof( Vector2[] ), typeof( Rect[] ), + typeof( Quaternion[] ), typeof( Color[] ), typeof( Color32[] ), typeof( LayerMask[] ), typeof( Bounds[] ), + typeof( Matrix4x4[] ), typeof( AnimationCurve[] ), typeof( Gradient[] ), typeof( RectOffset[] ), + typeof( List ), typeof( List ), typeof( List ), typeof( List ), typeof( List ), + typeof( List ), typeof( List ), typeof( List ), typeof( List ), typeof( List ), + typeof( List ), typeof( List ), typeof( List ), typeof( List ), + typeof( List ), typeof( List ), typeof( List ), typeof( List ), + typeof( List ), typeof( List ), typeof( List ), typeof( List ), typeof( List ), + typeof( List ), typeof( List ), typeof( List ), typeof( List ), +#if UNITY_2017_2_OR_NEWER + typeof( Vector3Int ), typeof( Vector2Int ), typeof( RectInt ), typeof( BoundsInt ), + typeof( Vector3Int[] ), typeof( Vector2Int[] ), typeof( RectInt[] ), typeof( BoundsInt[] ), + typeof( List ), typeof( List ), typeof( List ), typeof( List ) +#endif }; private static readonly HashSet folderContentsSet = new HashSet(); +#if UNITY_2018_3_OR_NEWER + private static int previousPingedPrefabInstanceId; + private static double previousPingedPrefabPingTime; +#endif + public static readonly GUILayoutOption GL_EXPAND_WIDTH = GUILayout.ExpandWidth( true ); public static readonly GUILayoutOption GL_EXPAND_HEIGHT = GUILayout.ExpandHeight( true ); public static readonly GUILayoutOption GL_WIDTH_25 = GUILayout.Width( 25 ); @@ -142,9 +153,9 @@ namespace AssetUsageDetectorNamespace.Extras Event e = Event.current; - // If CTRL key is pressed, do a multi-select; + // If CTRL or Shift keys are pressed, do a multi-select; // otherwise select only the clicked object and ping it in editor - if( !e.control ) + if( !e.control && !e.shift ) Selection.activeObject = obj.PingInEditor(); else { @@ -211,23 +222,26 @@ namespace AssetUsageDetectorNamespace.Extras { string assetPath = AssetDatabase.GetAssetPath( objTR.gameObject ); var openPrefabStage = UnityEditor.Experimental.SceneManagement.PrefabStageUtility.GetCurrentPrefabStage(); + + // Try to open the prefab stage of pinged prefabs if they are double clicked + if( previousPingedPrefabInstanceId == objTR.GetInstanceID() && EditorApplication.timeSinceStartup - previousPingedPrefabPingTime <= 0.3f && + ( openPrefabStage == null || !openPrefabStage.stageHandle.IsValid() || assetPath != openPrefabStage.prefabAssetPath ) ) + { + AssetDatabase.OpenAsset( objTR.gameObject ); + openPrefabStage = UnityEditor.Experimental.SceneManagement.PrefabStageUtility.GetCurrentPrefabStage(); + } + + previousPingedPrefabInstanceId = objTR.GetInstanceID(); + previousPingedPrefabPingTime = EditorApplication.timeSinceStartup; + if( openPrefabStage != null && openPrefabStage.stageHandle.IsValid() && assetPath == openPrefabStage.prefabAssetPath ) { - // Ping the object in prefab stage - Transform targetParent = objTR; - Transform selectedObject = ( (GameObject) obj ).transform; - objTR = openPrefabStage.prefabContentsRoot.transform; - while( targetParent != selectedObject ) + GameObject prefabStageGO = FollowSymmetricHierarchy( (GameObject) obj, openPrefabStage.prefabContentsRoot ); + if( prefabStageGO != null ) { - Transform temp = selectedObject; - while( temp.parent != targetParent ) - temp = temp.parent; - - objTR = objTR.GetChild( temp.GetSiblingIndex() ); - targetParent = temp; + objTR = prefabStageGO.transform; + selection = objTR.gameObject; } - - selection = objTR.gameObject; } #if UNITY_2019_1_OR_NEWER else if( obj != objTR.gameObject ) @@ -253,6 +267,38 @@ namespace AssetUsageDetectorNamespace.Extras return selection; } + public static GameObject FollowSymmetricHierarchy( this GameObject go, GameObject symmetricRoot ) + { + Transform target = go.transform; + Transform root1 = target.root; + Transform root2 = symmetricRoot.transform; + while( root1 != target ) + { + Transform temp = target; + while( temp.parent != root1 ) + temp = temp.parent; + + Transform newRoot2; + int siblingIndex = temp.GetSiblingIndex(); + if( siblingIndex < root2.childCount ) + { + newRoot2 = root2.GetChild( siblingIndex ); + if( newRoot2.name != temp.name ) + newRoot2 = root2.Find( temp.name ); + } + else + newRoot2 = root2.Find( temp.name ); + + if( newRoot2 == null ) + return null; + + root2 = newRoot2; + root1 = temp; + } + + return root2.gameObject; + } + // Check if the field is serializable public static bool IsSerializable( this FieldInfo fieldInfo ) { diff --git a/Plugins/AssetUsageDetector/Editor/VariableGetter.cs b/Plugins/AssetUsageDetector/Editor/VariableGetter.cs index 6a51b26..d86da03 100644 --- a/Plugins/AssetUsageDetector/Editor/VariableGetter.cs +++ b/Plugins/AssetUsageDetector/Editor/VariableGetter.cs @@ -1,5 +1,6 @@ using System; using System.Reflection; +using UnityEngine; namespace AssetUsageDetectorNamespace.Extras { @@ -32,7 +33,15 @@ namespace AssetUsageDetectorNamespace.Extras public object Get( object obj ) { - return getter( obj ); + try + { + return getter( obj ); + } + catch( Exception e ) + { + Debug.LogException( e ); + return null; + } } } diff --git a/Plugins/AssetUsageDetector/README.txt b/Plugins/AssetUsageDetector/README.txt index 6589e4a..27f5a03 100644 --- a/Plugins/AssetUsageDetector/README.txt +++ b/Plugins/AssetUsageDetector/README.txt @@ -7,7 +7,7 @@ E-mail: yasirkula@gmail.com 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 -Open "Window-Asset Usage Detector" window, configure the settings and hit GO! You can also use the "Assets-Search For References" shortcut to find the selected object(s)' references. +Open "Window-Asset Usage Detector" window, configure the settings and hit GO! You can also right click an object and select "Search For References". 3. KNOWN LIMITATIONS - static variables are not searched diff --git a/README.md b/README.md index 36189c9..0771330 100644 --- a/README.md +++ b/README.md @@ -14,14 +14,12 @@ This editor extension helps you figure out at which places an asset or GameObjec - Import [AssetUsageDetector.unitypackage](https://github.com/yasirkula/UnityAssetUsageDetector/releases) to your project - Open **Window - Asset Usage Detector** window, configure the settings and hit **GO!** - - or, use the **Assets - Search For References** shortcut to find the selected object(s)' references - -**NOTE:** If your project uses an older version of AssetUsageDetector, delete the older version before updating the plugin. + - or, right click an object and select **Search For References** ### C. FEATURES - You can search for references of any object that extends *UnityEngine.Object* -- Seaches every corner of your project with its *reflection* based search algorithm (even non-Unity objects, structs and data types like dictionaries are searched) +- Extensive search algorithm that uses *SerializedObject* and *reflection* to find references - Can search in multiple scenes at once - Can show complete paths to the references or only the most relevant parts of the paths (see the demonstration below) @@ -31,4 +29,4 @@ This editor extension helps you figure out at which places an asset or GameObjec - *static* variables are not searched - GUIText materials are not searched -- Textures in Lens Flare's can not be searched +- Textures in Lens Flare's can not be searched \ No newline at end of file diff --git a/screenshots/img1.png b/screenshots/img1.png index a9ba309..c830e91 100644 Binary files a/screenshots/img1.png and b/screenshots/img1.png differ