mirror of
https://github.com/yasirkula/UnityAssetUsageDetector.git
synced 2026-11-21 15:32:38 +08:00
Compare commits
4 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| f4129574fb | |||
| 7738da9d19 | |||
| 077505a217 | |||
| 003cedd363 |
@@ -548,7 +548,7 @@ namespace AssetUsageDetectorNamespace
|
|||||||
catch( Exception e )
|
catch( Exception e )
|
||||||
{
|
{
|
||||||
StringBuilder sb = new StringBuilder( objectsToSearchSet.Count * 50 + callStack.Count * 50 + 500 );
|
StringBuilder sb = new StringBuilder( objectsToSearchSet.Count * 50 + callStack.Count * 50 + 500 );
|
||||||
sb.AppendLine( "<b>AssetUsageDetector Error:</b>" ).AppendLine();
|
sb.AppendLine( "<b>AssetUsageDetector Error:</b>" ).AppendLine().Append( e ).AppendLine();
|
||||||
if( callStack.Count > 0 )
|
if( callStack.Count > 0 )
|
||||||
{
|
{
|
||||||
sb.AppendLine( "Stack contents: " );
|
sb.AppendLine( "Stack contents: " );
|
||||||
@@ -575,9 +575,6 @@ namespace AssetUsageDetectorNamespace
|
|||||||
sb.Append( obj.name ).Append( " (" ).Append( obj.GetType() ).AppendLine( ")" );
|
sb.Append( obj.name ).Append( " (" ).Append( obj.GetType() ).AppendLine( ")" );
|
||||||
}
|
}
|
||||||
|
|
||||||
sb.AppendLine();
|
|
||||||
sb.Append( e ).AppendLine();
|
|
||||||
|
|
||||||
Debug.LogError( sb.ToString() );
|
Debug.LogError( sb.ToString() );
|
||||||
|
|
||||||
try
|
try
|
||||||
@@ -619,7 +616,7 @@ namespace AssetUsageDetectorNamespace
|
|||||||
|
|
||||||
if( shouldOpenPrefabStageWithoutContext )
|
if( shouldOpenPrefabStageWithoutContext )
|
||||||
#endif
|
#endif
|
||||||
AssetDatabase.OpenAsset( AssetDatabase.LoadAssetAtPath<GameObject>( openPrefabStageAssetPath ) );
|
AssetDatabase.OpenAsset( AssetDatabase.LoadAssetAtPath<GameObject>( openPrefabStageAssetPath ) );
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -382,6 +382,14 @@ namespace AssetUsageDetectorNamespace
|
|||||||
if( objectsToSearchSet.Contains( script ) )
|
if( objectsToSearchSet.Contains( script ) )
|
||||||
referenceNode.AddLinkTo( GetReferenceNode( script ) );
|
referenceNode.AddLinkTo( GetReferenceNode( script ) );
|
||||||
}
|
}
|
||||||
|
else if( component is ParticleSystemRenderer )
|
||||||
|
{
|
||||||
|
// Search ParticleSystemRenderer's custom meshes for references (they aren't searched by SerializedObject, unfortunately)
|
||||||
|
Mesh[] meshes = new Mesh[( (ParticleSystemRenderer) component ).meshCount];
|
||||||
|
int meshCount = ( (ParticleSystemRenderer) component ).GetMeshes( meshes );
|
||||||
|
for( int i = 0; i < meshCount; i++ )
|
||||||
|
referenceNode.AddLinkTo( SearchObject( meshes[i] ), "Custom particle mesh" );
|
||||||
|
}
|
||||||
else if( searchRenderers && component is Renderer )
|
else if( searchRenderers && component is Renderer )
|
||||||
{
|
{
|
||||||
// If an asset is a shader, texture or material, and this component is a Renderer,
|
// If an asset is a shader, texture or material, and this component is a Renderer,
|
||||||
@@ -392,7 +400,7 @@ namespace AssetUsageDetectorNamespace
|
|||||||
}
|
}
|
||||||
else if( component is Animation )
|
else if( component is Animation )
|
||||||
{
|
{
|
||||||
// If this component is an Animation, search its animation clips for references
|
// Search animation clips for references
|
||||||
foreach( AnimationState anim in (Animation) component )
|
foreach( AnimationState anim in (Animation) component )
|
||||||
referenceNode.AddLinkTo( SearchObject( anim.clip ) );
|
referenceNode.AddLinkTo( SearchObject( anim.clip ) );
|
||||||
|
|
||||||
@@ -401,7 +409,7 @@ namespace AssetUsageDetectorNamespace
|
|||||||
}
|
}
|
||||||
else if( component is Animator )
|
else if( component is Animator )
|
||||||
{
|
{
|
||||||
// If this component is an Animator, search its animation clips for references (via AnimatorController)
|
// Search animation clips for references (via AnimatorController)
|
||||||
referenceNode.AddLinkTo( SearchObject( ( (Animator) component ).runtimeAnimatorController ) );
|
referenceNode.AddLinkTo( SearchObject( ( (Animator) component ).runtimeAnimatorController ) );
|
||||||
|
|
||||||
// Search the objects that are animated by this Animator component for references
|
// Search the objects that are animated by this Animator component for references
|
||||||
@@ -410,7 +418,7 @@ namespace AssetUsageDetectorNamespace
|
|||||||
#if UNITY_2017_2_OR_NEWER
|
#if UNITY_2017_2_OR_NEWER
|
||||||
else if( component is Tilemap )
|
else if( component is Tilemap )
|
||||||
{
|
{
|
||||||
// If this component is a Tilemap, search its tiles for references
|
// Search the tiles for references
|
||||||
TileBase[] tiles = new TileBase[( (Tilemap) component ).GetUsedTilesCount()];
|
TileBase[] tiles = new TileBase[( (Tilemap) component ).GetUsedTilesCount()];
|
||||||
( (Tilemap) component ).GetUsedTilesNonAlloc( tiles );
|
( (Tilemap) component ).GetUsedTilesNonAlloc( tiles );
|
||||||
|
|
||||||
@@ -424,7 +432,7 @@ namespace AssetUsageDetectorNamespace
|
|||||||
#if UNITY_2017_1_OR_NEWER
|
#if UNITY_2017_1_OR_NEWER
|
||||||
else if( component is PlayableDirector )
|
else if( component is PlayableDirector )
|
||||||
{
|
{
|
||||||
// If this component is a PlayableDirectory, search its PlayableAsset's scene bindings for references
|
// Search the PlayableAsset's scene bindings for references
|
||||||
PlayableAsset playableAsset = ( (PlayableDirector) component ).playableAsset;
|
PlayableAsset playableAsset = ( (PlayableDirector) component ).playableAsset;
|
||||||
if( playableAsset != null && !playableAsset.Equals( null ) )
|
if( playableAsset != null && !playableAsset.Equals( null ) )
|
||||||
{
|
{
|
||||||
@@ -536,7 +544,7 @@ namespace AssetUsageDetectorNamespace
|
|||||||
{
|
{
|
||||||
Object defaultValue = scriptImporter.GetDefaultReference( variables[i].name );
|
Object defaultValue = scriptImporter.GetDefaultReference( variables[i].name );
|
||||||
if( objectsToSearchSet.Contains( defaultValue ) )
|
if( objectsToSearchSet.Contains( defaultValue ) )
|
||||||
referenceNode.AddLinkTo( GetReferenceNode( defaultValue ), "Default Variable Value: " + variables[i].name );
|
referenceNode.AddLinkTo( GetReferenceNode( defaultValue ), "Default variable value: " + variables[i].name );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -719,9 +727,12 @@ namespace AssetUsageDetectorNamespace
|
|||||||
#else
|
#else
|
||||||
string assemblyPath = CompilationPipeline.GetAssemblyDefinitionFilePathFromAssemblyName( assemblyDefinitionFile.references[i] );
|
string assemblyPath = CompilationPipeline.GetAssemblyDefinitionFilePathFromAssemblyName( assemblyDefinitionFile.references[i] );
|
||||||
#endif
|
#endif
|
||||||
Object searchedAssemblyDefinitionFile;
|
if( !string.IsNullOrEmpty( assemblyPath ) )
|
||||||
if( assemblyDefinitionFilesToSearch.TryGetValue( assemblyPath, out searchedAssemblyDefinitionFile ) )
|
{
|
||||||
referenceNode.AddLinkTo( GetReferenceNode( searchedAssemblyDefinitionFile ), "Referenced Assembly" );
|
Object searchedAssemblyDefinitionFile;
|
||||||
|
if( assemblyDefinitionFilesToSearch.TryGetValue( assemblyPath, out searchedAssemblyDefinitionFile ) )
|
||||||
|
referenceNode.AddLinkTo( GetReferenceNode( searchedAssemblyDefinitionFile ), "Referenced Assembly" );
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1035,7 +1046,7 @@ namespace AssetUsageDetectorNamespace
|
|||||||
|
|
||||||
// m_RD.texture is a redundant reference that shows up when searching sprites
|
// m_RD.texture is a redundant reference that shows up when searching sprites
|
||||||
if( !propertyPath.EndsWithFast( "m_RD.texture" ) )
|
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 ) );
|
} while( iterator.Next( enterChildren ) );
|
||||||
|
|
||||||
|
|||||||
@@ -124,14 +124,13 @@ namespace AssetUsageDetectorNamespace
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Quickly initiate search for the selected assets
|
// 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 )]
|
[MenuItem( "Assets/Search for References", priority = 1000 )]
|
||||||
private static void SearchSelectedAssetReferences( MenuCommand command )
|
private static void SearchSelectedAssetReferences( MenuCommand command )
|
||||||
{
|
{
|
||||||
// This happens when this button is clicked via hierarchy's right click context menu
|
// 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
|
// 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
|
// the function to be called only once
|
||||||
// generated in one call
|
|
||||||
if( command.context )
|
if( command.context )
|
||||||
{
|
{
|
||||||
EditorApplication.update -= CallSearchSelectedAssetReferencesOnce;
|
EditorApplication.update -= CallSearchSelectedAssetReferencesOnce;
|
||||||
@@ -141,8 +140,21 @@ namespace AssetUsageDetectorNamespace
|
|||||||
ShowAndSearch( Selection.objects );
|
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
|
// 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/This Object Only", validate = true )]
|
||||||
|
[MenuItem( "GameObject/Search for References/Include Children", validate = true )]
|
||||||
[MenuItem( "Assets/Search for References", validate = true )]
|
[MenuItem( "Assets/Search for References", validate = true )]
|
||||||
private static bool SearchSelectedAssetReferencesValidate( MenuCommand command )
|
private static bool SearchSelectedAssetReferencesValidate( MenuCommand command )
|
||||||
{
|
{
|
||||||
@@ -150,13 +162,13 @@ namespace AssetUsageDetectorNamespace
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Quickly show the AssetUsageDetector window and initiate a search
|
// Quickly show the AssetUsageDetector window and initiate a search
|
||||||
public static void ShowAndSearch( IEnumerable<Object> searchObjects )
|
public static void ShowAndSearch( IEnumerable<Object> searchObjects, bool? shouldSearchChildren = null )
|
||||||
{
|
{
|
||||||
ShowAndSearchInternal( searchObjects, null );
|
ShowAndSearchInternal( searchObjects, null, shouldSearchChildren );
|
||||||
}
|
}
|
||||||
|
|
||||||
// Quickly show the AssetUsageDetector window and initiate a search
|
// 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 )
|
if( searchParameters == null )
|
||||||
{
|
{
|
||||||
@@ -164,7 +176,7 @@ namespace AssetUsageDetectorNamespace
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
ShowAndSearchInternal( searchParameters.objectsToSearch, searchParameters );
|
ShowAndSearchInternal( searchParameters.objectsToSearch, searchParameters, shouldSearchChildren );
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void CallSearchSelectedAssetReferencesOnce()
|
private static void CallSearchSelectedAssetReferencesOnce()
|
||||||
@@ -173,7 +185,13 @@ namespace AssetUsageDetectorNamespace
|
|||||||
SearchSelectedAssetReferences( new MenuCommand( null ) );
|
SearchSelectedAssetReferences( new MenuCommand( null ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void ShowAndSearchInternal( IEnumerable<Object> searchObjects, AssetUsageDetector.Parameters searchParameters )
|
private static void CallSearchSelectedAssetReferencesWithChildrenOnce()
|
||||||
|
{
|
||||||
|
EditorApplication.update -= CallSearchSelectedAssetReferencesWithChildrenOnce;
|
||||||
|
SearchSelectedAssetReferencesWithChildren( new MenuCommand( null ) );
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void ShowAndSearchInternal( IEnumerable<Object> searchObjects, AssetUsageDetector.Parameters searchParameters, bool? shouldSearchChildren )
|
||||||
{
|
{
|
||||||
if( mainWindow != null && !mainWindow.ReturnToSetupPhase( true ) )
|
if( mainWindow != null && !mainWindow.ReturnToSetupPhase( true ) )
|
||||||
{
|
{
|
||||||
@@ -187,7 +205,7 @@ namespace AssetUsageDetectorNamespace
|
|||||||
if( searchObjects != null )
|
if( searchObjects != null )
|
||||||
{
|
{
|
||||||
foreach( Object obj in searchObjects )
|
foreach( Object obj in searchObjects )
|
||||||
mainWindow.objectsToSearch.Add( new ObjectToSearch( obj ) );
|
mainWindow.objectsToSearch.Add( new ObjectToSearch( obj, shouldSearchChildren ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
if( searchParameters != null )
|
if( searchParameters != null )
|
||||||
|
|||||||
@@ -29,13 +29,13 @@ namespace AssetUsageDetectorNamespace
|
|||||||
private static MonoScript[] monoScriptsInProject;
|
private static MonoScript[] monoScriptsInProject;
|
||||||
private static HashSet<Object> currentSubAssets;
|
private static HashSet<Object> currentSubAssets;
|
||||||
|
|
||||||
public ObjectToSearch( Object obj )
|
public ObjectToSearch( Object obj, bool? shouldSearchChildren = null )
|
||||||
{
|
{
|
||||||
this.obj = obj;
|
this.obj = obj;
|
||||||
RefreshSubAssets();
|
RefreshSubAssets( shouldSearchChildren );
|
||||||
}
|
}
|
||||||
|
|
||||||
public void RefreshSubAssets()
|
public void RefreshSubAssets( bool? shouldSearchChildren = null )
|
||||||
{
|
{
|
||||||
if( subAssets == null )
|
if( subAssets == null )
|
||||||
subAssets = new List<SubAsset>();
|
subAssets = new List<SubAsset>();
|
||||||
@@ -47,11 +47,11 @@ namespace AssetUsageDetectorNamespace
|
|||||||
else
|
else
|
||||||
currentSubAssets.Clear();
|
currentSubAssets.Clear();
|
||||||
|
|
||||||
AddSubAssets( obj, false );
|
AddSubAssets( obj, false, shouldSearchChildren );
|
||||||
currentSubAssets.Clear();
|
currentSubAssets.Clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void AddSubAssets( Object target, bool includeTarget )
|
private void AddSubAssets( Object target, bool includeTarget, bool? shouldSearchChildren )
|
||||||
{
|
{
|
||||||
if( target == null || target.Equals( null ) )
|
if( target == null || target.Equals( null ) )
|
||||||
return;
|
return;
|
||||||
@@ -65,13 +65,13 @@ namespace AssetUsageDetectorNamespace
|
|||||||
// If this is a scene object, add its child objects to the sub-assets list
|
// If this is a scene object, add its child objects to the sub-assets list
|
||||||
// but don't include them in the search by default
|
// but don't include them in the search by default
|
||||||
Transform goTransform = go.transform;
|
Transform goTransform = go.transform;
|
||||||
Transform[] children = go.GetComponentsInChildren<Transform>();
|
Transform[] children = go.GetComponentsInChildren<Transform>( true );
|
||||||
for( int i = 0; i < children.Length; i++ )
|
for( int i = 0; i < children.Length; i++ )
|
||||||
{
|
{
|
||||||
if( ReferenceEquals( children[i], goTransform ) )
|
if( ReferenceEquals( children[i], goTransform ) )
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
subAssets.Add( new SubAsset( children[i].gameObject, false ) );
|
subAssets.Add( new SubAsset( children[i].gameObject, shouldSearchChildren ?? false ) );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@@ -83,7 +83,7 @@ namespace AssetUsageDetectorNamespace
|
|||||||
{
|
{
|
||||||
if( !currentSubAssets.Contains( target ) )
|
if( !currentSubAssets.Contains( target ) )
|
||||||
{
|
{
|
||||||
subAssets.Add( new SubAsset( target, true ) );
|
subAssets.Add( new SubAsset( target, shouldSearchChildren ?? true ) );
|
||||||
currentSubAssets.Add( target );
|
currentSubAssets.Add( target );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -93,7 +93,7 @@ namespace AssetUsageDetectorNamespace
|
|||||||
if( target.IsFolder() )
|
if( target.IsFolder() )
|
||||||
{
|
{
|
||||||
foreach( string filePath in Utilities.EnumerateFolderContents( target ) )
|
foreach( string filePath in Utilities.EnumerateFolderContents( target ) )
|
||||||
AddSubAssets( AssetDatabase.LoadAssetAtPath<Object>( filePath ), true );
|
AddSubAssets( AssetDatabase.LoadAssetAtPath<Object>( filePath ), true, shouldSearchChildren );
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -112,7 +112,7 @@ namespace AssetUsageDetectorNamespace
|
|||||||
|
|
||||||
if( asset != target )
|
if( asset != target )
|
||||||
{
|
{
|
||||||
subAssets.Add( new SubAsset( asset, true ) );
|
subAssets.Add( new SubAsset( asset, shouldSearchChildren ?? true ) );
|
||||||
currentSubAssets.Add( asset );
|
currentSubAssets.Add( asset );
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -142,7 +142,7 @@ namespace AssetUsageDetectorNamespace
|
|||||||
|
|
||||||
if( !currentSubAssets.Contains( monoScriptsInProject[j] ) )
|
if( !currentSubAssets.Contains( monoScriptsInProject[j] ) )
|
||||||
{
|
{
|
||||||
subAssets.Add( new SubAsset( monoScriptsInProject[j], true ) );
|
subAssets.Add( new SubAsset( monoScriptsInProject[j], shouldSearchChildren ?? true ) );
|
||||||
currentSubAssets.Add( monoScriptsInProject[j] );
|
currentSubAssets.Add( monoScriptsInProject[j] );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -415,8 +415,8 @@ namespace AssetUsageDetectorNamespace
|
|||||||
if( typeof( Type ).IsAssignableFrom( type ) || type.Namespace == reflectionNamespace )
|
if( typeof( Type ).IsAssignableFrom( type ) || type.Namespace == reflectionNamespace )
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
// Searching pointer variables for reference throws ArgumentException
|
// Searching pointers or ref variables for reference throws ArgumentException
|
||||||
if( type.IsPointer )
|
if( type.IsPointer || type.IsByRef )
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
|
|||||||
+1
-1
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "com.yasirkula.assetusagedetector",
|
"name": "com.yasirkula.assetusagedetector",
|
||||||
"displayName": "Asset Usage Detector",
|
"displayName": "Asset Usage Detector",
|
||||||
"version": "1.8.4",
|
"version": "1.8.8",
|
||||||
"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!"
|
"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!"
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user