mirror of
https://github.com/yasirkula/UnityAssetUsageDetector.git
synced 2026-11-19 14:32:37 +08:00
Compare commits
11 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 3c4292159a | |||
| 1a2eba24bd | |||
| cf0fea56ab | |||
| 956aea1ced | |||
| 466a152ba6 | |||
| 5eda0c1cb0 | |||
| 42e3278129 | |||
| f6a999f053 | |||
| 8441e4701c | |||
| d57a707678 | |||
| 3fa3344507 |
Binary file not shown.
|
Before Width: | Height: | Size: 20 KiB |
+1
-14
@@ -8,7 +8,7 @@
|
||||
|
||||
**Discord:** https://discord.gg/UJJt549AaV
|
||||
|
||||
**[Support the Developer ☕](https://yasirkula.itch.io/unity3d)**
|
||||
**[GitHub Sponsors ☕](https://github.com/sponsors/yasirkula)**
|
||||
|
||||
## ABOUT
|
||||
|
||||
@@ -37,18 +37,6 @@ There are 5 ways to install this plugin:
|
||||
|
||||

|
||||
|
||||
## ADDRESSABLES SUPPORT
|
||||
|
||||
This plugin has experimental support for *Addressables* package. However, the search may take significantly longer to finish when Addressables are searched. Some manual modifications are needed to enable Addressables support:
|
||||
|
||||
- The plugin mustn't be installed as a package, i.e. it must reside inside the *Assets* folder and not the *Packages* folder (it can reside inside a subfolder of Assets like *Assets/Plugins*)
|
||||
- Modify the **AssetUsageDetector.Editor** Assembly Definition File as follows:
|
||||
|
||||

|
||||
|
||||
- If *Version Defines* isn't present (on older Unity versions), manually add `ASSET_USAGE_ADDRESSABLES` compiler directive to **Player Settings/Scripting Define Symbols** (these symbols are platform specific, so if you change the active platform later, you'll have to add the compiler directive again)
|
||||
- Enable the "Addressables support" option in Asset Usage Detector window
|
||||
|
||||
## SEARCH REFACTORING
|
||||
|
||||
While searching for references using the Scripting API, it's possible to get notified of the found references *during* the search (some references like *Assembly Definition File* references or *Shader Graph* references aren't supported) and in most cases, refactor them (e.g. changing all usages of a searched object with something else or *null*). Disabling *Lazy Scene Search* is recommended while using this feature and it's advised to backup your project beforehand.
|
||||
@@ -78,7 +66,6 @@ void ReplaceFontUsages( Font from, Font to )
|
||||
|
||||
## KNOWN LIMITATIONS
|
||||
|
||||
- *Addressables* aren't supported
|
||||
- *static* variables aren't searched
|
||||
- *Resources.Load* usages can't be found
|
||||
- *GUIText* materials aren't searched
|
||||
|
||||
@@ -1,6 +1,9 @@
|
||||
{
|
||||
"name": "AssetUsageDetector.Editor",
|
||||
"references": [],
|
||||
"rootNamespace": "",
|
||||
"references": [
|
||||
"Unity.Addressables"
|
||||
],
|
||||
"includePlatforms": [
|
||||
"Editor"
|
||||
],
|
||||
@@ -10,6 +13,17 @@
|
||||
"precompiledReferences": [],
|
||||
"autoReferenced": true,
|
||||
"defineConstraints": [],
|
||||
"versionDefines": [],
|
||||
"versionDefines": [
|
||||
{
|
||||
"name": "com.unity.addressables",
|
||||
"expression": "0.0.0",
|
||||
"define": "ASSET_USAGE_ADDRESSABLES"
|
||||
},
|
||||
{
|
||||
"name": "com.unity.visualeffectgraph",
|
||||
"expression": "0.0.0",
|
||||
"define": "ASSET_USAGE_VFX_GRAPH"
|
||||
}
|
||||
],
|
||||
"noEngineReferences": false
|
||||
}
|
||||
@@ -289,10 +289,10 @@ namespace AssetUsageDetectorNamespace
|
||||
if( ( searchParameters.searchInScenes & SceneSearchMode.OpenScenes ) == SceneSearchMode.OpenScenes )
|
||||
{
|
||||
// Get all open (and loaded) scenes
|
||||
for( int i = 0; i < EditorSceneManager.loadedSceneCount; i++ )
|
||||
for( int i = 0; i < SceneManager.sceneCount; i++ )
|
||||
{
|
||||
Scene scene = EditorSceneManager.GetSceneAt( i );
|
||||
if( scene.IsValid() )
|
||||
Scene scene = SceneManager.GetSceneAt( i );
|
||||
if( scene.IsValid() && scene.isLoaded )
|
||||
scenesToSearch.Add( scene.path );
|
||||
}
|
||||
}
|
||||
@@ -314,10 +314,10 @@ namespace AssetUsageDetectorNamespace
|
||||
if( isInPlayMode )
|
||||
{
|
||||
HashSet<string> openScenes = new HashSet<string>();
|
||||
for( int i = 0; i < EditorSceneManager.loadedSceneCount; i++ )
|
||||
for( int i = 0; i < SceneManager.sceneCount; i++ )
|
||||
{
|
||||
Scene scene = EditorSceneManager.GetSceneAt( i );
|
||||
if( scene.IsValid() )
|
||||
Scene scene = SceneManager.GetSceneAt( i );
|
||||
if( scene.IsValid() && scene.isLoaded )
|
||||
openScenes.Add( scene.path );
|
||||
}
|
||||
|
||||
@@ -350,7 +350,7 @@ namespace AssetUsageDetectorNamespace
|
||||
|
||||
// Initialize the nodes of searched asset(s)
|
||||
foreach( Object obj in objectsToSearchSet )
|
||||
searchedUnityObjects.Add( obj.GetHashCode(), PopReferenceNode( obj ) );
|
||||
searchedUnityObjects.Add( obj.GetInstanceID(), PopReferenceNode( obj ) );
|
||||
|
||||
// Progressbar values
|
||||
int searchProgress = 0;
|
||||
@@ -672,7 +672,7 @@ namespace AssetUsageDetectorNamespace
|
||||
else
|
||||
{
|
||||
for( Transform parent = ( (GameObject) obj ).transform.parent; parent != null; parent = parent.parent )
|
||||
usedObjectPathsSet.Add( parent.gameObject.GetHashCode().ToString() );
|
||||
usedObjectPathsSet.Add( parent.gameObject.GetInstanceID().ToString() );
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -739,13 +739,13 @@ namespace AssetUsageDetectorNamespace
|
||||
if( !searchedTopmostGameObject )
|
||||
{
|
||||
if( obj is GameObject )
|
||||
unusedMainObjectNodes[obj.GetHashCode().ToString()] = node;
|
||||
unusedMainObjectNodes[obj.GetInstanceID().ToString()] = node;
|
||||
else
|
||||
currentSearchResultGroup.AddReference( node );
|
||||
}
|
||||
else // List child GameObject scene objects under their parent GameObject
|
||||
{
|
||||
string dictionaryKey = searchedTopmostGameObject.GetHashCode().ToString();
|
||||
string dictionaryKey = searchedTopmostGameObject.GetInstanceID().ToString();
|
||||
List<ReferenceNode> unusedSubObjectNodesAtPath;
|
||||
if( !unusedSubObjectNodes.TryGetValue( dictionaryKey, out unusedSubObjectNodesAtPath ) )
|
||||
unusedSubObjectNodes[dictionaryKey] = unusedSubObjectNodesAtPath = new List<ReferenceNode>( 2 );
|
||||
@@ -985,9 +985,13 @@ namespace AssetUsageDetectorNamespace
|
||||
if( obj == null || obj.Equals( null ) )
|
||||
return null;
|
||||
|
||||
// Avoid recursion (which leads to stackoverflow exception) using a stack
|
||||
if( callStack.ContainsFast( obj ) )
|
||||
return null;
|
||||
// Avoid recursion (which leads to stackoverflow exception) using a stack (initially, I was using callStack.ContainsFast
|
||||
// here but it returned false for objects that do exist in the call stack if VFX Graph window was open)
|
||||
for( int i = callStack.Count - 1; i >= 0; i-- )
|
||||
{
|
||||
if( callStack[i].Equals( obj ) )
|
||||
return null;
|
||||
}
|
||||
|
||||
bool searchingSourceAsset = searchingSourceAssets && ReferenceEquals( currentSearchedObject, obj );
|
||||
|
||||
@@ -1012,14 +1016,14 @@ namespace AssetUsageDetectorNamespace
|
||||
{
|
||||
if( assetsToSearchSet.Count == 0 )
|
||||
{
|
||||
searchedUnityObjects.Add( unityObject.GetHashCode(), null );
|
||||
searchedUnityObjects.Add( unityObject.GetInstanceID(), null );
|
||||
return null;
|
||||
}
|
||||
|
||||
assetPath = AssetDatabase.GetAssetPath( unityObject );
|
||||
if( excludedAssetsPathsSet.Contains( assetPath ) || !AssetHasAnyReference( assetPath ) )
|
||||
{
|
||||
searchedUnityObjects.Add( unityObject.GetHashCode(), null );
|
||||
searchedUnityObjects.Add( unityObject.GetInstanceID(), null );
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -1027,7 +1031,7 @@ namespace AssetUsageDetectorNamespace
|
||||
callStack.Add( unityObject );
|
||||
|
||||
// Search the Object in detail
|
||||
Func<Object, ReferenceNode> searchFunction;
|
||||
Func<object, ReferenceNode> searchFunction;
|
||||
if( assetPath != null && extensionToSearchFunction.TryGetValue( Utilities.GetFileExtension( assetPath ), out searchFunction ) && AssetDatabase.IsMainAsset( unityObject ) )
|
||||
result = searchFunction( unityObject );
|
||||
else if( typeToSearchFunction.TryGetValue( unityObject.GetType(), out searchFunction ) )
|
||||
@@ -1089,13 +1093,13 @@ namespace AssetUsageDetectorNamespace
|
||||
if( !searchingSourceAsset )
|
||||
{
|
||||
if( obj is Object )
|
||||
searchedUnityObjects.Add( unityObject.GetHashCode(), result );
|
||||
searchedUnityObjects.Add( unityObject.GetInstanceID(), result );
|
||||
else
|
||||
searchedObjects.Add( GetNodeObjectHash( obj ), result );
|
||||
}
|
||||
else if( result != null )
|
||||
{
|
||||
result.CopyReferencesTo( searchedUnityObjects[unityObject.GetHashCode()] );
|
||||
result.CopyReferencesTo( searchedUnityObjects[unityObject.GetInstanceID()] );
|
||||
PoolReferenceNode( result );
|
||||
}
|
||||
}
|
||||
@@ -1229,7 +1233,7 @@ namespace AssetUsageDetectorNamespace
|
||||
{
|
||||
if( nodeObject is Object )
|
||||
{
|
||||
if( searchedUnityObjects.TryGetValue( nodeObject.GetHashCode(), out referenceNode ) )
|
||||
if( searchedUnityObjects.TryGetValue( ( (Object) nodeObject ).GetInstanceID(), out referenceNode ) )
|
||||
return true;
|
||||
}
|
||||
else if( searchedObjects.TryGetValue( GetNodeObjectHash( nodeObject ), out referenceNode ) )
|
||||
@@ -1245,7 +1249,7 @@ namespace AssetUsageDetectorNamespace
|
||||
ReferenceNode result;
|
||||
if( nodeObject is Object )
|
||||
{
|
||||
int hash = nodeObject.GetHashCode();
|
||||
int hash = ( (Object) nodeObject ).GetInstanceID();
|
||||
if( !searchedUnityObjects.TryGetValue( hash, out result ) || result == null )
|
||||
{
|
||||
result = PopReferenceNode( nodeObject );
|
||||
|
||||
@@ -161,9 +161,9 @@ namespace AssetUsageDetectorNamespace
|
||||
#endregion
|
||||
|
||||
// Dictionary to quickly find the function to search a specific type with
|
||||
private Dictionary<Type, Func<Object, ReferenceNode>> typeToSearchFunction;
|
||||
private Dictionary<Type, Func<object, ReferenceNode>> typeToSearchFunction;
|
||||
// Dictionary to associate special file extensions with their search functions
|
||||
private Dictionary<string, Func<Object, ReferenceNode>> extensionToSearchFunction;
|
||||
private Dictionary<string, Func<object, ReferenceNode>> extensionToSearchFunction;
|
||||
|
||||
// An optimization to fetch & filter fields and properties of a class only once
|
||||
private readonly Dictionary<Type, VariableGetterHolder[]> typeToVariables = new Dictionary<Type, VariableGetterHolder[]>( 4096 );
|
||||
@@ -199,19 +199,28 @@ namespace AssetUsageDetectorNamespace
|
||||
|
||||
// Unity's internal function that returns a SerializedProperty's corresponding FieldInfo
|
||||
private delegate FieldInfo FieldInfoGetter( SerializedProperty p, out Type t );
|
||||
private FieldInfoGetter fieldInfoGetter;
|
||||
#if UNITY_2019_3_OR_NEWER
|
||||
private readonly FieldInfoGetter fieldInfoGetter = (FieldInfoGetter) Delegate.CreateDelegate( typeof( FieldInfoGetter ), typeof( Editor ).Assembly.GetType( "UnityEditor.ScriptAttributeUtility" ).GetMethod( "GetFieldInfoAndStaticTypeFromProperty", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static ) );
|
||||
#else
|
||||
private readonly FieldInfoGetter fieldInfoGetter = (FieldInfoGetter) Delegate.CreateDelegate( typeof( FieldInfoGetter ), typeof( Editor ).Assembly.GetType( "UnityEditor.ScriptAttributeUtility" ).GetMethod( "GetFieldInfoFromProperty", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static ) );
|
||||
#endif
|
||||
|
||||
#if ASSET_USAGE_ADDRESSABLES
|
||||
private delegate Sprite[] SpriteAtlasPackedSpritesGetter( SpriteAtlas atlas );
|
||||
private SpriteAtlasPackedSpritesGetter spriteAtlasPackedSpritesGetter;
|
||||
private PropertyInfo assetReferenceSubObjectTypeGetter;
|
||||
private readonly Func<SpriteAtlas, Sprite[]> spriteAtlasPackedSpritesGetter = (Func<SpriteAtlas, Sprite[]>) Delegate.CreateDelegate( typeof( Func<SpriteAtlas, Sprite[]> ), typeof( SpriteAtlasExtensions ).GetMethod( "GetPackedSprites", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static ) );
|
||||
private readonly PropertyInfo assetReferenceSubObjectTypeGetter = typeof( AssetReference ).GetProperty( "SubOjbectType", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance );
|
||||
#endif
|
||||
|
||||
#if ASSET_USAGE_VFX_GRAPH
|
||||
private readonly Func<string, object> vfxResourceGetter = (Func<string, object>) Delegate.CreateDelegate( typeof( Func<string, object> ), typeof( Editor ).Assembly.GetType( "UnityEditor.VFX.VisualEffectResource" ).GetMethod( "GetResourceAtPath", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static ) );
|
||||
private readonly MethodInfo vfxResourceContentsGetter = typeof( Editor ).Assembly.GetType( "UnityEditor.VFX.VisualEffectResource" ).GetMethod( "GetContents", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance );
|
||||
private readonly MethodInfo vfxSerializableObjectValueGetter = Array.Find( Array.Find( AppDomain.CurrentDomain.GetAssemblies(), ( assembly ) => assembly.GetName().Name == "Unity.VisualEffectGraph.Editor" ).GetType( "UnityEditor.VFX.VFXSerializableObject" ).GetMethods( BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance ), ( methodInfo ) => methodInfo.Name == "Get" && !methodInfo.IsGenericMethod );
|
||||
#endif
|
||||
|
||||
private void InitializeSearchFunctionsData( Parameters searchParameters )
|
||||
{
|
||||
if( typeToSearchFunction == null )
|
||||
{
|
||||
typeToSearchFunction = new Dictionary<Type, Func<Object, ReferenceNode>>()
|
||||
typeToSearchFunction = new Dictionary<Type, Func<object, ReferenceNode>>()
|
||||
{
|
||||
{ typeof( GameObject ), SearchGameObject },
|
||||
{ typeof( Material ), SearchMaterial },
|
||||
@@ -234,7 +243,7 @@ namespace AssetUsageDetectorNamespace
|
||||
|
||||
if( extensionToSearchFunction == null )
|
||||
{
|
||||
extensionToSearchFunction = new Dictionary<string, Func<Object, ReferenceNode>>()
|
||||
extensionToSearchFunction = new Dictionary<string, Func<object, ReferenceNode>>()
|
||||
{
|
||||
{ "compute", SearchShaderSecondaryAsset },
|
||||
{ "cginc", SearchShaderSecondaryAsset },
|
||||
@@ -250,6 +259,11 @@ namespace AssetUsageDetectorNamespace
|
||||
#if UNITY_2018_1_OR_NEWER
|
||||
{ "shadergraph", SearchShaderGraph },
|
||||
{ "shadersubgraph", SearchShaderGraph },
|
||||
#endif
|
||||
#if ASSET_USAGE_VFX_GRAPH
|
||||
{ "vfx", SearchVFXGraphAsset },
|
||||
{ "vfxoperator", SearchVFXGraphAsset },
|
||||
{ "vfxblock", SearchVFXGraphAsset },
|
||||
#endif
|
||||
};
|
||||
}
|
||||
@@ -271,6 +285,9 @@ namespace AssetUsageDetectorNamespace
|
||||
#if UNITY_2018_1_OR_NEWER
|
||||
searchShaderGraphsForSubGraphs = false;
|
||||
#endif
|
||||
#if ASSET_USAGE_VFX_GRAPH
|
||||
bool searchVFXGraphs = false;
|
||||
#endif
|
||||
|
||||
foreach( Object obj in objectsToSearchSet )
|
||||
{
|
||||
@@ -292,6 +309,10 @@ namespace AssetUsageDetectorNamespace
|
||||
#if UNITY_2017_3_OR_NEWER
|
||||
else if( obj is UnityEditorInternal.AssemblyDefinitionAsset )
|
||||
assemblyDefinitionFilesToSearch[AssetDatabase.GetAssetPath( obj )] = obj;
|
||||
#endif
|
||||
#if ASSET_USAGE_VFX_GRAPH
|
||||
else if( !searchVFXGraphs && ( obj is Shader || obj is Mesh || obj.GetType().Name.StartsWithFast( "PointCache" ) || obj.GetType().Name == "ShaderGraphVfxAsset" ) )
|
||||
searchVFXGraphs = true;
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -349,23 +370,19 @@ namespace AssetUsageDetectorNamespace
|
||||
}
|
||||
#endif
|
||||
|
||||
#if UNITY_2019_3_OR_NEWER
|
||||
MethodInfo fieldInfoGetterMethod = typeof( Editor ).Assembly.GetType( "UnityEditor.ScriptAttributeUtility" ).GetMethod( "GetFieldInfoAndStaticTypeFromProperty", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static );
|
||||
#else
|
||||
MethodInfo fieldInfoGetterMethod = typeof( Editor ).Assembly.GetType( "UnityEditor.ScriptAttributeUtility" ).GetMethod( "GetFieldInfoFromProperty", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static );
|
||||
#endif
|
||||
fieldInfoGetter = (FieldInfoGetter) Delegate.CreateDelegate( typeof( FieldInfoGetter ), fieldInfoGetterMethod );
|
||||
|
||||
#if ASSET_USAGE_ADDRESSABLES
|
||||
MethodInfo spriteAtlasPackedSpritesGetterMethod = typeof( SpriteAtlasExtensions ).GetMethod( "GetPackedSprites", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static );
|
||||
spriteAtlasPackedSpritesGetter = (SpriteAtlasPackedSpritesGetter) Delegate.CreateDelegate( typeof( SpriteAtlasPackedSpritesGetter ), spriteAtlasPackedSpritesGetterMethod );
|
||||
assetReferenceSubObjectTypeGetter = typeof( AssetReference ).GetProperty( "SubOjbectType", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance );
|
||||
#if ASSET_USAGE_VFX_GRAPH
|
||||
if( searchTextureReferences || searchVFXGraphs )
|
||||
{
|
||||
alwaysSearchedExtensionsSet.Add( "vfx" );
|
||||
alwaysSearchedExtensionsSet.Add( "vfxoperator" );
|
||||
alwaysSearchedExtensionsSet.Add( "vfxblock" );
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
private ReferenceNode SearchGameObject( Object unityObject )
|
||||
private ReferenceNode SearchGameObject( object obj )
|
||||
{
|
||||
GameObject go = (GameObject) unityObject;
|
||||
GameObject go = (GameObject) obj;
|
||||
ReferenceNode referenceNode = PopReferenceNode( go );
|
||||
|
||||
// Check if this GameObject's prefab is one of the selected assets
|
||||
@@ -397,9 +414,9 @@ namespace AssetUsageDetectorNamespace
|
||||
return referenceNode;
|
||||
}
|
||||
|
||||
private ReferenceNode SearchComponent( Object unityObject )
|
||||
private ReferenceNode SearchComponent( object obj )
|
||||
{
|
||||
Component component = (Component) unityObject;
|
||||
Component component = (Component) obj;
|
||||
|
||||
// Ignore Transform component (no object field to search for)
|
||||
if( component is Transform )
|
||||
@@ -610,11 +627,11 @@ namespace AssetUsageDetectorNamespace
|
||||
return referenceNode;
|
||||
}
|
||||
|
||||
private ReferenceNode SearchMaterial( Object unityObject )
|
||||
private ReferenceNode SearchMaterial( object obj )
|
||||
{
|
||||
const string TEXTURE_PROPERTY_PREFIX = "m_SavedProperties.m_TexEnvs[";
|
||||
|
||||
Material material = (Material) unityObject;
|
||||
Material material = (Material) obj;
|
||||
ReferenceNode referenceNode = PopReferenceNode( material );
|
||||
|
||||
// We used to search only the shader and the Texture properties in this function but it has changed for 2 major reasons:
|
||||
@@ -689,14 +706,14 @@ namespace AssetUsageDetectorNamespace
|
||||
}
|
||||
|
||||
// Searches default Texture values assigned to shader properties, as well as #include references in shader source code
|
||||
private ReferenceNode SearchShader( Object unityObject )
|
||||
private ReferenceNode SearchShader( object obj )
|
||||
{
|
||||
Shader shader = (Shader) unityObject;
|
||||
Shader shader = (Shader) obj;
|
||||
ReferenceNode referenceNode = PopReferenceNode( shader );
|
||||
|
||||
if( searchTextureReferences )
|
||||
{
|
||||
ShaderImporter shaderImporter = AssetImporter.GetAtPath( AssetDatabase.GetAssetPath( unityObject ) ) as ShaderImporter;
|
||||
ShaderImporter shaderImporter = AssetImporter.GetAtPath( AssetDatabase.GetAssetPath( shader ) ) as ShaderImporter;
|
||||
if( shaderImporter != null )
|
||||
{
|
||||
int shaderPropertyCount = ShaderUtil.GetPropertyCount( shader );
|
||||
@@ -731,20 +748,20 @@ namespace AssetUsageDetectorNamespace
|
||||
}
|
||||
|
||||
// Searches .compute, .cginc, .cg, .hlsl and .glslinc assets for #include references
|
||||
private ReferenceNode SearchShaderSecondaryAsset( Object unityObject )
|
||||
private ReferenceNode SearchShaderSecondaryAsset( object obj )
|
||||
{
|
||||
if( shaderIncludesToSearchSet.Count == 0 )
|
||||
return null;
|
||||
|
||||
ReferenceNode referenceNode = PopReferenceNode( unityObject );
|
||||
ReferenceNode referenceNode = PopReferenceNode( obj );
|
||||
SearchShaderSourceCodeForCGIncludes( referenceNode );
|
||||
return referenceNode;
|
||||
}
|
||||
|
||||
// Searches class/interface inheritances and default UnityEngine.Object values assigned to script variables
|
||||
private ReferenceNode SearchMonoScript( Object unityObject )
|
||||
private ReferenceNode SearchMonoScript( object obj )
|
||||
{
|
||||
MonoScript script = (MonoScript) unityObject;
|
||||
MonoScript script = (MonoScript) obj;
|
||||
Type scriptType = script.GetClass();
|
||||
if( scriptType == null || ( !scriptType.IsSubclassOf( typeof( MonoBehaviour ) ) && !scriptType.IsSubclassOf( typeof( ScriptableObject ) ) ) )
|
||||
return null;
|
||||
@@ -758,7 +775,7 @@ namespace AssetUsageDetectorNamespace
|
||||
referenceNode.AddLinkTo( GetReferenceNode( monoScriptsToSearch[i] ), monoScriptsToSearchTypes[i].IsInterface ? "Implements interface" : "Extends class" );
|
||||
}
|
||||
|
||||
MonoImporter scriptImporter = AssetImporter.GetAtPath( AssetDatabase.GetAssetPath( unityObject ) ) as MonoImporter;
|
||||
MonoImporter scriptImporter = AssetImporter.GetAtPath( AssetDatabase.GetAssetPath( script ) ) as MonoImporter;
|
||||
if( scriptImporter != null )
|
||||
{
|
||||
VariableGetterHolder[] variables = GetFilteredVariablesForType( scriptType );
|
||||
@@ -781,9 +798,9 @@ namespace AssetUsageDetectorNamespace
|
||||
return referenceNode;
|
||||
}
|
||||
|
||||
private ReferenceNode SearchAnimatorController( Object unityObject )
|
||||
private ReferenceNode SearchAnimatorController( object obj )
|
||||
{
|
||||
RuntimeAnimatorController controller = (RuntimeAnimatorController) unityObject;
|
||||
RuntimeAnimatorController controller = (RuntimeAnimatorController) obj;
|
||||
ReferenceNode referenceNode = PopReferenceNode( controller );
|
||||
|
||||
if( controller is AnimatorController )
|
||||
@@ -845,9 +862,9 @@ namespace AssetUsageDetectorNamespace
|
||||
return referenceNode;
|
||||
}
|
||||
|
||||
private ReferenceNode SearchAnimatorStateMachine( Object unityObject )
|
||||
private ReferenceNode SearchAnimatorStateMachine( object obj )
|
||||
{
|
||||
AnimatorStateMachine animatorStateMachine = (AnimatorStateMachine) unityObject;
|
||||
AnimatorStateMachine animatorStateMachine = (AnimatorStateMachine) obj;
|
||||
ReferenceNode referenceNode = PopReferenceNode( animatorStateMachine );
|
||||
|
||||
ChildAnimatorStateMachine[] stateMachines = animatorStateMachine.stateMachines;
|
||||
@@ -877,9 +894,9 @@ namespace AssetUsageDetectorNamespace
|
||||
return referenceNode;
|
||||
}
|
||||
|
||||
private ReferenceNode SearchAnimatorState( Object unityObject )
|
||||
private ReferenceNode SearchAnimatorState( object obj )
|
||||
{
|
||||
AnimatorState animatorState = (AnimatorState) unityObject;
|
||||
AnimatorState animatorState = (AnimatorState) obj;
|
||||
ReferenceNode referenceNode = PopReferenceNode( animatorState );
|
||||
|
||||
referenceNode.AddLinkTo( SearchObject( animatorState.motion ), "Motion" );
|
||||
@@ -906,15 +923,15 @@ namespace AssetUsageDetectorNamespace
|
||||
return referenceNode;
|
||||
}
|
||||
|
||||
private ReferenceNode SearchAnimatorStateTransition( Object unityObject )
|
||||
private ReferenceNode SearchAnimatorStateTransition( object obj )
|
||||
{
|
||||
// Don't search AnimatorStateTransition objects, it will just return duplicate results of SearchAnimatorStateMachine
|
||||
return PopReferenceNode( unityObject );
|
||||
return PopReferenceNode( obj );
|
||||
}
|
||||
|
||||
private ReferenceNode SearchBlendTree( Object unityObject )
|
||||
private ReferenceNode SearchBlendTree( object obj )
|
||||
{
|
||||
BlendTree blendTree = (BlendTree) unityObject;
|
||||
BlendTree blendTree = (BlendTree) obj;
|
||||
ReferenceNode referenceNode = PopReferenceNode( blendTree );
|
||||
|
||||
ChildMotion[] children = blendTree.children;
|
||||
@@ -929,9 +946,9 @@ namespace AssetUsageDetectorNamespace
|
||||
return referenceNode;
|
||||
}
|
||||
|
||||
private ReferenceNode SearchAnimationClip( Object unityObject )
|
||||
private ReferenceNode SearchAnimationClip( object obj )
|
||||
{
|
||||
AnimationClip clip = (AnimationClip) unityObject;
|
||||
AnimationClip clip = (AnimationClip) obj;
|
||||
ReferenceNode referenceNode = PopReferenceNode( clip );
|
||||
|
||||
// Get all curves from animation clip
|
||||
@@ -983,17 +1000,17 @@ namespace AssetUsageDetectorNamespace
|
||||
}
|
||||
|
||||
// TerrainData's properties like tree/detail/layer definitions aren't exposed to SerializedObject so use reflection instead
|
||||
private ReferenceNode SearchTerrainData( Object unityObject )
|
||||
private ReferenceNode SearchTerrainData( object obj )
|
||||
{
|
||||
ReferenceNode referenceNode = PopReferenceNode( unityObject );
|
||||
ReferenceNode referenceNode = PopReferenceNode( obj );
|
||||
SearchVariablesWithReflection( referenceNode );
|
||||
return referenceNode;
|
||||
}
|
||||
|
||||
#if UNITY_2017_1_OR_NEWER
|
||||
private ReferenceNode SearchSpriteAtlas( Object unityObject )
|
||||
private ReferenceNode SearchSpriteAtlas( object obj )
|
||||
{
|
||||
SpriteAtlas spriteAtlas = (SpriteAtlas) unityObject;
|
||||
SpriteAtlas spriteAtlas = (SpriteAtlas) obj;
|
||||
ReferenceNode referenceNode = PopReferenceNode( spriteAtlas );
|
||||
|
||||
SerializedObject spriteAtlasSO = new SerializedObject( spriteAtlas );
|
||||
@@ -1083,13 +1100,13 @@ namespace AssetUsageDetectorNamespace
|
||||
|
||||
#if UNITY_2017_3_OR_NEWER
|
||||
// Find references from an Assembly Definition File to its Assembly Definition References
|
||||
private ReferenceNode SearchAssemblyDefinitionFile( Object unityObject )
|
||||
private ReferenceNode SearchAssemblyDefinitionFile( object obj )
|
||||
{
|
||||
if( assemblyDefinitionFilesToSearch.Count == 0 )
|
||||
return null;
|
||||
|
||||
AssemblyDefinitionReferences assemblyDefinitionFile = JsonUtility.FromJson<AssemblyDefinitionReferences>( ( (TextAsset) unityObject ).text );
|
||||
ReferenceNode referenceNode = PopReferenceNode( unityObject );
|
||||
AssemblyDefinitionReferences assemblyDefinitionFile = JsonUtility.FromJson<AssemblyDefinitionReferences>( ( (TextAsset) obj ).text );
|
||||
ReferenceNode referenceNode = PopReferenceNode( obj );
|
||||
|
||||
if( !string.IsNullOrEmpty( assemblyDefinitionFile.reference ) )
|
||||
{
|
||||
@@ -1123,15 +1140,15 @@ namespace AssetUsageDetectorNamespace
|
||||
|
||||
#if UNITY_2018_1_OR_NEWER
|
||||
// Searches Shader Graph assets for references
|
||||
private ReferenceNode SearchShaderGraph( Object unityObject )
|
||||
private ReferenceNode SearchShaderGraph( object obj )
|
||||
{
|
||||
if( !searchTextureReferences && !searchShaderGraphsForSubGraphs && shaderIncludesToSearchSet.Count == 0 )
|
||||
return null;
|
||||
|
||||
ReferenceNode referenceNode = PopReferenceNode( unityObject );
|
||||
ReferenceNode referenceNode = PopReferenceNode( obj );
|
||||
|
||||
// Shader Graph assets are JSON files, they must be crawled manually to find references
|
||||
string graphJson = File.ReadAllText( AssetDatabase.GetAssetPath( unityObject ) );
|
||||
string graphJson = File.ReadAllText( AssetDatabase.GetAssetPath( (Object) obj ) );
|
||||
if( graphJson.IndexOf( "\"m_ObjectId\"", 0, Mathf.Min( 200, graphJson.Length ) ) >= 0 )
|
||||
{
|
||||
// New Shader Graph serialization format is used: https://github.com/Unity-Technologies/Graphics/pull/222
|
||||
@@ -1252,6 +1269,19 @@ namespace AssetUsageDetectorNamespace
|
||||
}
|
||||
#endif
|
||||
|
||||
#if ASSET_USAGE_VFX_GRAPH
|
||||
private ReferenceNode SearchVFXGraphAsset( object obj )
|
||||
{
|
||||
ReferenceNode referenceNode = PopReferenceNode( obj );
|
||||
|
||||
object vfxResource = vfxResourceGetter( AssetDatabase.GetAssetPath( (Object) obj ) );
|
||||
foreach( Object vfxResourceContent in (Object[]) vfxResourceContentsGetter.Invoke( vfxResource, null ) )
|
||||
referenceNode.AddLinkTo( SearchObject( vfxResourceContent ) );
|
||||
|
||||
return referenceNode;
|
||||
}
|
||||
#endif
|
||||
|
||||
// Find references from an Animation/Animator component to the objects that it animates
|
||||
private void SearchAnimatedObjects( ReferenceNode referenceNode )
|
||||
{
|
||||
@@ -1419,21 +1449,31 @@ namespace AssetUsageDetectorNamespace
|
||||
break;
|
||||
#if UNITY_2019_3_OR_NEWER
|
||||
case SerializedPropertyType.ManagedReference:
|
||||
propertyValue = GetRawSerializedPropertyValue( iterator ) as Object;
|
||||
searchResult = SearchObject( PreferablyGameObject( propertyValue ) );
|
||||
object managedReferenceValue = GetRawSerializedPropertyValue( iterator );
|
||||
propertyValue = managedReferenceValue as Object;
|
||||
searchResult = SearchObject( PreferablyGameObject( managedReferenceValue ) );
|
||||
enterChildren = false;
|
||||
break;
|
||||
#endif
|
||||
case SerializedPropertyType.Generic:
|
||||
#if ASSET_USAGE_ADDRESSABLES
|
||||
AssetReference assetReference;
|
||||
if( searchParameters.addressablesSupport && iterator.type.StartsWithFast( "AssetReference" ) && ( assetReference = GetRawSerializedPropertyValue( iterator ) as AssetReference ) != null )
|
||||
if( searchParameters.addressablesSupport && iterator.type.StartsWithFast( "AssetReference" ) && GetRawSerializedPropertyValue( iterator ) is AssetReference assetReference )
|
||||
{
|
||||
propertyValue = GetAddressablesAssetReferenceValue( assetReference );
|
||||
searchResult = SearchObject( PreferablyGameObject( propertyValue ) );
|
||||
enterChildren = false;
|
||||
}
|
||||
else
|
||||
#endif
|
||||
#if ASSET_USAGE_VFX_GRAPH
|
||||
if( vfxSerializableObjectValueGetter != null && iterator.type == "VFXSerializableObject" && GetRawSerializedPropertyValue( iterator ) is object vfxSerializableObject )
|
||||
{
|
||||
object vfxSerializableObjectValue = vfxSerializableObjectValueGetter.Invoke( vfxSerializableObject, null );
|
||||
propertyValue = vfxSerializableObjectValue as Object;
|
||||
searchResult = SearchObject( PreferablyGameObject( vfxSerializableObjectValue ) );
|
||||
enterChildren = false;
|
||||
}
|
||||
else
|
||||
#endif
|
||||
{
|
||||
propertyValue = null;
|
||||
|
||||
@@ -96,6 +96,13 @@ namespace AssetUsageDetectorNamespace
|
||||
#endregion
|
||||
|
||||
#region Other Settings
|
||||
private static bool? m_showRootAssetName = null;
|
||||
public static bool ShowRootAssetName
|
||||
{
|
||||
get { if( m_showRootAssetName == null ) m_showRootAssetName = EditorPrefs.GetBool( "AUD_ShowRootAssetName", false ); return m_showRootAssetName.Value; }
|
||||
set { if( m_showRootAssetName == value ) return; m_showRootAssetName = value; EditorPrefs.SetBool( "AUD_ShowRootAssetName", value ); }
|
||||
}
|
||||
|
||||
private static bool? m_pingClickedObjects = null;
|
||||
public static bool PingClickedObjects
|
||||
{
|
||||
@@ -179,7 +186,9 @@ namespace AssetUsageDetectorNamespace
|
||||
|
||||
EditorGUI.BeginChangeCheck();
|
||||
|
||||
SettingsHeaderColor = ColorField( "Settings Header Color", SettingsHeaderColor, Color.cyan );
|
||||
EditorGUIUtility.labelWidth += 140f;
|
||||
ShowRootAssetName = EditorGUILayout.Toggle( "Show Root Asset's Name For Sub-Assets (Requires Refresh)", ShowRootAssetName );
|
||||
EditorGUIUtility.labelWidth -= 140f;
|
||||
|
||||
EditorGUILayout.Space();
|
||||
|
||||
@@ -202,6 +211,7 @@ namespace AssetUsageDetectorNamespace
|
||||
|
||||
EditorGUILayout.Space();
|
||||
|
||||
SettingsHeaderColor = ColorField( "Settings Header Color", SettingsHeaderColor, Color.cyan );
|
||||
SearchResultGroupHeaderColor = ColorField( "Group Header Color", SearchResultGroupHeaderColor, Color.cyan );
|
||||
RootRowsBackgroundColor = ColorField( "Root Rows Background Color", RootRowsBackgroundColor, EditorGUIUtility.isProSkin ? new Color( 0f, 1f, 1f, 0.15f ) : new Color( 0f, 1f, 1f, 0.25f ) );
|
||||
RootRowsBorderColor = ColorField( "Root Rows Border Color", RootRowsBorderColor, EditorGUIUtility.isProSkin ? new Color( 0.15f, 0.15f, 0.15f, 1f ) : new Color( 0.375f, 0.375f, 0.375f, 1f ) );
|
||||
|
||||
@@ -570,7 +570,7 @@ namespace AssetUsageDetectorNamespace
|
||||
lazySceneSearch = WordWrappingToggleLeft( "Lazy scene search: scenes are searched in detail only when they are manually refreshed (faster search)", lazySceneSearch );
|
||||
#if ASSET_USAGE_ADDRESSABLES
|
||||
EditorGUI.EndDisabledGroup();
|
||||
addressablesSupport = WordWrappingToggleLeft( "Addressables support (WARNING: 'Lazy scene search' will be disabled) (slower search)", addressablesSupport );
|
||||
addressablesSupport = WordWrappingToggleLeft( "Addressables support (Experimental) (WARNING: 'Lazy scene search' will be disabled) (slower search)", addressablesSupport );
|
||||
#endif
|
||||
calculateUnusedObjects = WordWrappingToggleLeft( "Calculate unused objects", calculateUnusedObjects );
|
||||
hideDuplicateRows = WordWrappingToggleLeft( "Hide duplicate rows in search results", hideDuplicateRows );
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Text;
|
||||
using UnityEditor;
|
||||
using UnityEditor.IMGUI.Controls;
|
||||
@@ -802,7 +803,12 @@ namespace AssetUsageDetectorNamespace
|
||||
}
|
||||
}
|
||||
|
||||
if( Type == GroupType.Scene && !EditorApplication.isPlaying && EditorSceneManager.loadedSceneCount > 1 )
|
||||
#if UNITY_2022_2_OR_NEWER
|
||||
int loadedSceneCount = SceneManager.loadedSceneCount;
|
||||
#else
|
||||
int loadedSceneCount = EditorSceneManager.loadedSceneCount;
|
||||
#endif
|
||||
if( Type == GroupType.Scene && !EditorApplication.isPlaying && loadedSceneCount > 1 )
|
||||
{
|
||||
// Show context menu when SearchResultGroup's header is right clicked
|
||||
Scene scene = EditorSceneManager.GetSceneByPath( ScenePath );
|
||||
@@ -1221,6 +1227,13 @@ namespace AssetUsageDetectorNamespace
|
||||
{
|
||||
instanceId = unityObject.GetInstanceID();
|
||||
Label = unityObject.name + " (" + unityObject.GetType().Name + ")";
|
||||
|
||||
if( AssetUsageDetectorSettings.ShowRootAssetName && unityObject.IsAsset() && !AssetDatabase.IsMainAsset( unityObject ) )
|
||||
{
|
||||
string mainAssetName = Path.GetFileNameWithoutExtension( AssetDatabase.GetAssetPath( unityObject ) );
|
||||
if( unityObject.name != mainAssetName )
|
||||
Label += " <" + mainAssetName + ">";
|
||||
}
|
||||
}
|
||||
else if( nodeObject != null )
|
||||
{
|
||||
|
||||
@@ -299,7 +299,7 @@ namespace AssetUsageDetectorNamespace
|
||||
if( linkDescriptions.Count > 0 )
|
||||
{
|
||||
Object prefabObject = PrefabUtility.GetCorrespondingObjectFromSource( unityObject );
|
||||
if( prefabObject && parentData.node.HasLinkToObjectWithDescriptions( prefabObject.GetHashCode(), linkDescriptions ) )
|
||||
if( prefabObject && parentData.node.HasLinkToObjectWithDescriptions( prefabObject.GetInstanceID(), linkDescriptions ) )
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -177,6 +177,12 @@ namespace AssetUsageDetectorNamespace
|
||||
selection = objTR.gameObject;
|
||||
#endif
|
||||
}
|
||||
else if( prefabAssetType == PrefabAssetType.Model )
|
||||
{
|
||||
objTR = ( (GameObject) obj ).transform;
|
||||
while( objTR.parent != null && objTR.parent.parent != null )
|
||||
objTR = objTR.parent;
|
||||
}
|
||||
#else
|
||||
Transform objTR = ( (GameObject) obj ).transform;
|
||||
while( objTR.parent != null && objTR.parent.parent != null )
|
||||
@@ -190,6 +196,11 @@ namespace AssetUsageDetectorNamespace
|
||||
// Can't ping assets that are hidden from Project window (e.g. animator states of AnimatorController), ping the main asset at that path instead
|
||||
pingTarget = AssetDatabase.LoadMainAssetAtPath( AssetDatabase.GetAssetPath( obj ) );
|
||||
}
|
||||
else if( !AssetDatabase.IsMainAsset( obj ) && Array.IndexOf( AssetDatabase.LoadAllAssetRepresentationsAtPath( AssetDatabase.GetAssetPath( obj ) ), obj ) < 0 )
|
||||
{
|
||||
// VFX Graph assets' nodes are serialized as part of the graph but they are invisible in the Project window even though their hideFlags is None (I don't know how)
|
||||
pingTarget = AssetDatabase.LoadMainAssetAtPath( AssetDatabase.GetAssetPath( obj ) );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -405,9 +416,9 @@ namespace AssetUsageDetectorNamespace
|
||||
// Check if all open scenes are saved (not dirty)
|
||||
public static bool AreScenesSaved()
|
||||
{
|
||||
for( int i = 0; i < EditorSceneManager.loadedSceneCount; i++ )
|
||||
for( int i = 0; i < SceneManager.sceneCount; i++ )
|
||||
{
|
||||
Scene scene = EditorSceneManager.GetSceneAt( i );
|
||||
Scene scene = SceneManager.GetSceneAt( i );
|
||||
if( scene.isDirty || string.IsNullOrEmpty( scene.path ) )
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
= Asset Usage Detector (v2.3.0) =
|
||||
= Asset Usage Detector (v2.4.2) =
|
||||
|
||||
Online documentation available at: https://github.com/yasirkula/UnityAssetUsageDetector
|
||||
E-mail: yasirkula@gmail.com
|
||||
@@ -8,15 +8,6 @@ E-mail: yasirkula@gmail.com
|
||||
This tool helps you find usages of the selected asset(s) and/or scene object(s), i.e. lists the objects that refer to them.
|
||||
|
||||
|
||||
### ADDRESSABLES SUPPORT
|
||||
This plugin has experimental support for Addressables package. However, the search may take significantly longer to finish when Addressables are searched. Some manual modifications are needed to enable Addressables support:
|
||||
|
||||
- The plugin mustn't be installed as a package, i.e. it must reside inside the Assets folder and not the Packages folder (it can reside inside a subfolder of Assets like Assets/Plugins)
|
||||
- Add ASSET_USAGE_ADDRESSABLES compiler directive to "Player Settings/Scripting Define Symbols" (these symbols are platform specific, so if you change the active platform later, you'll have to add the compiler directive again)
|
||||
- Add "Unity.Addressables" assembly to "AssetUsageDetector.Editor" Assembly Definition File's "Assembly Definition References" list
|
||||
- Enable the "Addressables support" option in Asset Usage Detector window
|
||||
|
||||
|
||||
### HOW TO
|
||||
- Open "Window-Asset Usage Detector" window, configure the settings and hit "GO!". You can also right click an object and select "Search For References"
|
||||
|
||||
|
||||
+1
-1
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"name": "com.yasirkula.assetusagedetector",
|
||||
"displayName": "Asset Usage Detector",
|
||||
"version": "2.3.0",
|
||||
"version": "2.4.2",
|
||||
"documentationUrl": "https://github.com/yasirkula/UnityAssetUsageDetector",
|
||||
"changelogUrl": "https://github.com/yasirkula/UnityAssetUsageDetector/releases",
|
||||
"licensesUrl": "https://github.com/yasirkula/UnityAssetUsageDetector/blob/master/LICENSE.txt",
|
||||
|
||||
Reference in New Issue
Block a user