diff --git a/Plugins/AssetUsageDetector/Editor/AssetUsageDetectorSearchFunctions.cs b/Plugins/AssetUsageDetector/Editor/AssetUsageDetectorSearchFunctions.cs index 09c4e8b..2020670 100644 --- a/Plugins/AssetUsageDetector/Editor/AssetUsageDetectorSearchFunctions.cs +++ b/Plugins/AssetUsageDetector/Editor/AssetUsageDetectorSearchFunctions.cs @@ -1035,7 +1035,7 @@ namespace AssetUsageDetectorNamespace // m_RD.texture is a redundant reference that shows up when searching sprites if( !propertyPath.EndsWithFast( "m_RD.texture" ) ) - referenceNode.AddLinkTo( searchResult, "Variable: " + propertyPath ); + referenceNode.AddLinkTo( searchResult, "Variable: " + propertyPath.Replace( ".Array.data[", "[" ) ); // "arrayVariable.Array.data[0]" becomes "arrayVariable[0]" } } while( iterator.Next( enterChildren ) ); diff --git a/Plugins/AssetUsageDetector/Editor/AssetUsageDetectorWindow.cs b/Plugins/AssetUsageDetector/Editor/AssetUsageDetectorWindow.cs index 903bfbc..4031f5d 100644 --- a/Plugins/AssetUsageDetector/Editor/AssetUsageDetectorWindow.cs +++ b/Plugins/AssetUsageDetector/Editor/AssetUsageDetectorWindow.cs @@ -124,14 +124,13 @@ namespace AssetUsageDetectorNamespace } // Quickly initiate search for the selected assets - [MenuItem( "GameObject/Search for References", priority = 49 )] + [MenuItem( "GameObject/Search for References/This Object Only", priority = 49 )] [MenuItem( "Assets/Search for References", priority = 1000 )] private static void SearchSelectedAssetReferences( MenuCommand command ) { // 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 + // the function to be called only once if( command.context ) { EditorApplication.update -= CallSearchSelectedAssetReferencesOnce; @@ -141,8 +140,21 @@ namespace AssetUsageDetectorNamespace ShowAndSearch( Selection.objects ); } + [MenuItem( "GameObject/Search for References/Include Children", priority = 49 )] + private static void SearchSelectedAssetReferencesWithChildren( MenuCommand command ) + { + if( command.context ) + { + EditorApplication.update -= CallSearchSelectedAssetReferencesWithChildrenOnce; + EditorApplication.update += CallSearchSelectedAssetReferencesWithChildrenOnce; + } + else + ShowAndSearch( Selection.objects, true ); + } + // Show the menu item only if there is a selection in the Editor [MenuItem( "GameObject/Search for References", validate = true )] + [MenuItem( "GameObject/Search for References (Include Children)", validate = true )] [MenuItem( "Assets/Search for References", validate = true )] private static bool SearchSelectedAssetReferencesValidate( MenuCommand command ) { @@ -150,13 +162,13 @@ namespace AssetUsageDetectorNamespace } // Quickly show the AssetUsageDetector window and initiate a search - public static void ShowAndSearch( IEnumerable searchObjects ) + public static void ShowAndSearch( IEnumerable searchObjects, bool? shouldSearchChildren = null ) { - ShowAndSearchInternal( searchObjects, null ); + ShowAndSearchInternal( searchObjects, null, shouldSearchChildren ); } // Quickly show the AssetUsageDetector window and initiate a search - public static void ShowAndSearch( AssetUsageDetector.Parameters searchParameters ) + public static void ShowAndSearch( AssetUsageDetector.Parameters searchParameters, bool? shouldSearchChildren = null ) { if( searchParameters == null ) { @@ -164,7 +176,7 @@ namespace AssetUsageDetectorNamespace return; } - ShowAndSearchInternal( searchParameters.objectsToSearch, searchParameters ); + ShowAndSearchInternal( searchParameters.objectsToSearch, searchParameters, shouldSearchChildren ); } private static void CallSearchSelectedAssetReferencesOnce() @@ -173,7 +185,13 @@ namespace AssetUsageDetectorNamespace SearchSelectedAssetReferences( new MenuCommand( null ) ); } - private static void ShowAndSearchInternal( IEnumerable searchObjects, AssetUsageDetector.Parameters searchParameters ) + private static void CallSearchSelectedAssetReferencesWithChildrenOnce() + { + EditorApplication.update -= CallSearchSelectedAssetReferencesWithChildrenOnce; + SearchSelectedAssetReferencesWithChildren( new MenuCommand( null ) ); + } + + private static void ShowAndSearchInternal( IEnumerable searchObjects, AssetUsageDetector.Parameters searchParameters, bool? shouldSearchChildren ) { if( mainWindow != null && !mainWindow.ReturnToSetupPhase( true ) ) { @@ -187,7 +205,7 @@ namespace AssetUsageDetectorNamespace if( searchObjects != null ) { foreach( Object obj in searchObjects ) - mainWindow.objectsToSearch.Add( new ObjectToSearch( obj ) ); + mainWindow.objectsToSearch.Add( new ObjectToSearch( obj, shouldSearchChildren ) ); } if( searchParameters != null ) diff --git a/Plugins/AssetUsageDetector/Editor/ObjectToSearch.cs b/Plugins/AssetUsageDetector/Editor/ObjectToSearch.cs index 72803bf..8867dc0 100644 --- a/Plugins/AssetUsageDetector/Editor/ObjectToSearch.cs +++ b/Plugins/AssetUsageDetector/Editor/ObjectToSearch.cs @@ -29,13 +29,13 @@ namespace AssetUsageDetectorNamespace private static MonoScript[] monoScriptsInProject; private static HashSet currentSubAssets; - public ObjectToSearch( Object obj ) + public ObjectToSearch( Object obj, bool? shouldSearchChildren = null ) { this.obj = obj; - RefreshSubAssets(); + RefreshSubAssets( shouldSearchChildren ); } - public void RefreshSubAssets() + public void RefreshSubAssets( bool? shouldSearchChildren = null ) { if( subAssets == null ) subAssets = new List(); @@ -47,11 +47,11 @@ namespace AssetUsageDetectorNamespace else currentSubAssets.Clear(); - AddSubAssets( obj, false ); + AddSubAssets( obj, false, shouldSearchChildren ); currentSubAssets.Clear(); } - private void AddSubAssets( Object target, bool includeTarget ) + private void AddSubAssets( Object target, bool includeTarget, bool? shouldSearchChildren ) { if( target == null || target.Equals( null ) ) return; @@ -71,7 +71,7 @@ namespace AssetUsageDetectorNamespace if( ReferenceEquals( children[i], goTransform ) ) continue; - subAssets.Add( new SubAsset( children[i].gameObject, false ) ); + subAssets.Add( new SubAsset( children[i].gameObject, shouldSearchChildren ?? false ) ); } } else @@ -83,7 +83,7 @@ namespace AssetUsageDetectorNamespace { if( !currentSubAssets.Contains( target ) ) { - subAssets.Add( new SubAsset( target, true ) ); + subAssets.Add( new SubAsset( target, shouldSearchChildren ?? true ) ); currentSubAssets.Add( target ); } } @@ -93,7 +93,7 @@ namespace AssetUsageDetectorNamespace if( target.IsFolder() ) { foreach( string filePath in Utilities.EnumerateFolderContents( target ) ) - AddSubAssets( AssetDatabase.LoadAssetAtPath( filePath ), true ); + AddSubAssets( AssetDatabase.LoadAssetAtPath( filePath ), true, shouldSearchChildren ); return; } @@ -112,7 +112,7 @@ namespace AssetUsageDetectorNamespace if( asset != target ) { - subAssets.Add( new SubAsset( asset, true ) ); + subAssets.Add( new SubAsset( asset, shouldSearchChildren ?? true ) ); currentSubAssets.Add( asset ); } @@ -142,7 +142,7 @@ namespace AssetUsageDetectorNamespace if( !currentSubAssets.Contains( monoScriptsInProject[j] ) ) { - subAssets.Add( new SubAsset( monoScriptsInProject[j], true ) ); + subAssets.Add( new SubAsset( monoScriptsInProject[j], shouldSearchChildren ?? true ) ); currentSubAssets.Add( monoScriptsInProject[j] ); } } diff --git a/package.json b/package.json index 2c75b9b..e722c7a 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "com.yasirkula.assetusagedetector", "displayName": "Asset Usage Detector", - "version": "1.8.4", + "version": "1.8.5", "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!" }