mirror of
https://github.com/yasirkula/UnityAssetUsageDetector.git
synced 2026-11-19 22:42:37 +08:00
Compare commits
22 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| ace8ac4947 | |||
| 02167c28a2 | |||
| 092b80ba29 | |||
| 524965aee7 | |||
| efad9fa158 | |||
| 6cd2b407cc | |||
| 3c4292159a | |||
| 1a2eba24bd | |||
| cf0fea56ab | |||
| 956aea1ced | |||
| 466a152ba6 | |||
| 5eda0c1cb0 | |||
| 42e3278129 | |||
| f6a999f053 | |||
| 8441e4701c | |||
| d57a707678 | |||
| 3fa3344507 | |||
| 8072530c2c | |||
| 28a73e2843 | |||
| c7e52466ef | |||
| 875f3e6794 | |||
| 635d0653fa |
+2
-2
@@ -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
|
||||
|
||||
@@ -66,8 +66,8 @@ void ReplaceFontUsages( Font from, Font to )
|
||||
|
||||
## KNOWN LIMITATIONS
|
||||
|
||||
- *Addressables* aren't supported
|
||||
- *static* variables aren't searched
|
||||
- *Resources.Load* usages can't be found
|
||||
- *ref struct*s can't be searched
|
||||
- *GUIText* materials aren't searched
|
||||
- Textures in *Lens Flares* can't be 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
|
||||
}
|
||||
@@ -31,6 +31,7 @@ namespace AssetUsageDetectorNamespace
|
||||
public SceneSearchMode searchInScenes = SceneSearchMode.AllScenes;
|
||||
public Object[] searchInScenesSubset = null;
|
||||
public Object[] excludedScenesFromSearch = null;
|
||||
public bool searchInSceneLightingSettings = true;
|
||||
public bool searchInAssetsFolder = true;
|
||||
public Object[] searchInAssetsSubset = null;
|
||||
public Object[] excludedAssetsFromSearch = null;
|
||||
@@ -47,6 +48,9 @@ namespace AssetUsageDetectorNamespace
|
||||
public SearchRefactoring searchRefactoring = null;
|
||||
|
||||
public bool lazySceneSearch = true;
|
||||
#if ASSET_USAGE_ADDRESSABLES
|
||||
public bool addressablesSupport = false;
|
||||
#endif
|
||||
public bool calculateUnusedObjects = false;
|
||||
public bool hideDuplicateRows = true;
|
||||
public bool hideReduntantPrefabVariantLinks = true;
|
||||
@@ -159,6 +163,7 @@ namespace AssetUsageDetectorNamespace
|
||||
|
||||
// Get the scenes that are open right now
|
||||
SceneSetup[] initialSceneSetup = !isInPlayMode ? EditorSceneManager.GetSceneManagerSetup() : null;
|
||||
Scene activeScene = EditorSceneManager.GetActiveScene();
|
||||
|
||||
// Make sure that the AssetDatabase is up-to-date
|
||||
AssetDatabase.SaveAssets();
|
||||
@@ -286,10 +291,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 );
|
||||
}
|
||||
}
|
||||
@@ -311,10 +316,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 );
|
||||
}
|
||||
|
||||
@@ -347,7 +352,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;
|
||||
@@ -521,7 +526,7 @@ namespace AssetUsageDetectorNamespace
|
||||
if( excludedScenesPathsSet.Contains( scenePath ) )
|
||||
continue;
|
||||
|
||||
SearchScene( scenePath, searchResult, searchParameters.lazySceneSearch, initialSceneSetup );
|
||||
SearchScene( scenePath, searchResult, searchParameters, initialSceneSetup );
|
||||
}
|
||||
}
|
||||
|
||||
@@ -604,6 +609,10 @@ namespace AssetUsageDetectorNamespace
|
||||
|
||||
EditorUtility.ClearProgressBar();
|
||||
|
||||
// If the active scene was changed during search, reset it
|
||||
if( EditorSceneManager.GetActiveScene() != activeScene )
|
||||
EditorSceneManager.SetActiveScene( activeScene );
|
||||
|
||||
#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 ) )
|
||||
@@ -669,7 +678,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() );
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -736,13 +745,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 );
|
||||
@@ -892,7 +901,7 @@ namespace AssetUsageDetectorNamespace
|
||||
}
|
||||
|
||||
// Search a scene for references
|
||||
private void SearchScene( string scenePath, List<SearchResultGroup> searchResult, bool lazySearch, SceneSetup[] initialSceneSetup )
|
||||
private void SearchScene( string scenePath, List<SearchResultGroup> searchResult, Parameters searchParameters, SceneSetup[] initialSceneSetup )
|
||||
{
|
||||
Scene scene = EditorSceneManager.GetSceneByPath( scenePath );
|
||||
if( isInPlayMode && !scene.isLoaded )
|
||||
@@ -908,7 +917,7 @@ namespace AssetUsageDetectorNamespace
|
||||
|
||||
if( !scene.isLoaded )
|
||||
{
|
||||
if( lazySearch )
|
||||
if( searchParameters.lazySceneSearch )
|
||||
{
|
||||
searchResult.Add( new SearchResultGroup( scenePath, SearchResultGroup.GroupType.Scene, true, true ) );
|
||||
return;
|
||||
@@ -924,6 +933,16 @@ namespace AssetUsageDetectorNamespace
|
||||
for( int i = 0; i < rootGameObjects.Length; i++ )
|
||||
SearchGameObjectRecursively( rootGameObjects[i] );
|
||||
|
||||
// Search through Lighting Settings (it requires changing the active scene but don't do that in play mode)
|
||||
if( searchParameters.searchInSceneLightingSettings && ( !isInPlayMode || SceneManager.GetActiveScene() == scene ) )
|
||||
{
|
||||
if( !isInPlayMode && EditorSceneManager.GetActiveScene() != scene )
|
||||
EditorSceneManager.SetActiveScene( scene );
|
||||
|
||||
BeginSearchObject( lightmapSettingsGetter() );
|
||||
BeginSearchObject( renderSettingsGetter() );
|
||||
}
|
||||
|
||||
// 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 )
|
||||
{
|
||||
@@ -982,9 +1001,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 );
|
||||
|
||||
@@ -1009,14 +1032,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;
|
||||
}
|
||||
}
|
||||
@@ -1024,7 +1047,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 ) )
|
||||
@@ -1086,13 +1109,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 );
|
||||
}
|
||||
}
|
||||
@@ -1103,6 +1126,11 @@ namespace AssetUsageDetectorNamespace
|
||||
// Check if the asset at specified path depends on any of the references
|
||||
private bool AssetHasAnyReference( string assetPath )
|
||||
{
|
||||
#if ASSET_USAGE_ADDRESSABLES
|
||||
if( searchParameters.addressablesSupport )
|
||||
return true;
|
||||
#endif
|
||||
|
||||
if( assetsToSearchPathsSet.Contains( assetPath ) )
|
||||
return true;
|
||||
|
||||
@@ -1221,7 +1249,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 ) )
|
||||
@@ -1237,7 +1265,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 );
|
||||
|
||||
@@ -21,6 +21,9 @@ using UnityEditor.Compilation;
|
||||
#if UNITY_2017_2_OR_NEWER
|
||||
using UnityEngine.Tilemaps;
|
||||
#endif
|
||||
#if ASSET_USAGE_ADDRESSABLES
|
||||
using UnityEngine.AddressableAssets;
|
||||
#endif
|
||||
using Object = UnityEngine.Object;
|
||||
|
||||
namespace AssetUsageDetectorNamespace
|
||||
@@ -158,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 );
|
||||
@@ -196,13 +199,34 @@ 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
|
||||
|
||||
private readonly Func<Object> lightmapSettingsGetter = (Func<Object>) Delegate.CreateDelegate( typeof( Func<Object> ), typeof( LightmapEditorSettings ).GetMethod( "GetLightmapSettings", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static ) );
|
||||
private readonly Func<Object> renderSettingsGetter = (Func<Object>) Delegate.CreateDelegate( typeof( Func<Object> ), typeof( RenderSettings ).GetMethod( "GetRenderSettings", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static ) );
|
||||
#if UNITY_2021_2_OR_NEWER
|
||||
private readonly Func<Cubemap> defaultReflectionProbeGetter = (Func<Cubemap>) Delegate.CreateDelegate( typeof( Func<Cubemap> ), typeof( RenderSettings ).GetProperty( "defaultReflection", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static ).GetGetMethod( true ) );
|
||||
#endif
|
||||
|
||||
#if ASSET_USAGE_ADDRESSABLES
|
||||
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 },
|
||||
@@ -217,6 +241,8 @@ namespace AssetUsageDetectorNamespace
|
||||
{ typeof( BlendTree ), SearchBlendTree },
|
||||
{ typeof( AnimationClip ), SearchAnimationClip },
|
||||
{ typeof( TerrainData ), SearchTerrainData },
|
||||
{ typeof( LightmapSettings ), SearchLightmapSettings },
|
||||
{ typeof( RenderSettings ), SearchRenderSettings },
|
||||
#if UNITY_2017_1_OR_NEWER
|
||||
{ typeof( SpriteAtlas ), SearchSpriteAtlas },
|
||||
#endif
|
||||
@@ -225,7 +251,7 @@ namespace AssetUsageDetectorNamespace
|
||||
|
||||
if( extensionToSearchFunction == null )
|
||||
{
|
||||
extensionToSearchFunction = new Dictionary<string, Func<Object, ReferenceNode>>()
|
||||
extensionToSearchFunction = new Dictionary<string, Func<object, ReferenceNode>>()
|
||||
{
|
||||
{ "compute", SearchShaderSecondaryAsset },
|
||||
{ "cginc", SearchShaderSecondaryAsset },
|
||||
@@ -241,6 +267,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
|
||||
};
|
||||
}
|
||||
@@ -262,6 +293,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 )
|
||||
{
|
||||
@@ -283,6 +317,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
|
||||
}
|
||||
|
||||
@@ -340,17 +378,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 );
|
||||
#if ASSET_USAGE_VFX_GRAPH
|
||||
if( searchTextureReferences || searchVFXGraphs )
|
||||
{
|
||||
alwaysSearchedExtensionsSet.Add( "vfx" );
|
||||
alwaysSearchedExtensionsSet.Add( "vfxoperator" );
|
||||
alwaysSearchedExtensionsSet.Add( "vfxblock" );
|
||||
}
|
||||
#endif
|
||||
fieldInfoGetter = (FieldInfoGetter) Delegate.CreateDelegate( typeof( FieldInfoGetter ), fieldInfoGetterMethod );
|
||||
}
|
||||
|
||||
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
|
||||
@@ -382,9 +422,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 )
|
||||
@@ -595,11 +635,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:
|
||||
@@ -674,14 +714,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 );
|
||||
@@ -716,20 +756,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;
|
||||
@@ -743,7 +783,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 );
|
||||
@@ -766,9 +806,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 )
|
||||
@@ -830,9 +870,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;
|
||||
@@ -862,9 +902,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" );
|
||||
@@ -891,15 +931,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;
|
||||
@@ -914,9 +954,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
|
||||
@@ -968,17 +1008,47 @@ 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 SearchLightmapSettings( object obj )
|
||||
{
|
||||
SpriteAtlas spriteAtlas = (SpriteAtlas) unityObject;
|
||||
ReferenceNode referenceNode = PopReferenceNode( obj );
|
||||
|
||||
referenceNode.AddLinkTo( SearchObject( LightmapSettings.lightProbes ), "Light Probes" );
|
||||
|
||||
LightmapData[] lightmaps = LightmapSettings.lightmaps;
|
||||
if( lightmaps != null )
|
||||
{
|
||||
for( int i = 0; i < lightmaps.Length; i++ )
|
||||
referenceNode.AddLinkTo( SearchObject( lightmaps[i] ), "Lightmap" );
|
||||
}
|
||||
|
||||
SearchVariablesWithSerializedObject( referenceNode, true );
|
||||
return referenceNode;
|
||||
}
|
||||
|
||||
private ReferenceNode SearchRenderSettings( object obj )
|
||||
{
|
||||
ReferenceNode referenceNode = PopReferenceNode( obj );
|
||||
|
||||
#if UNITY_2021_2_OR_NEWER
|
||||
referenceNode.AddLinkTo( SearchObject( defaultReflectionProbeGetter() ), "Default Reflection Probe" );
|
||||
#else
|
||||
referenceNode.AddLinkTo( SearchObject( ReflectionProbe.defaultTexture ), "Default Reflection Probe" );
|
||||
#endif
|
||||
SearchVariablesWithSerializedObject( referenceNode, true );
|
||||
return referenceNode;
|
||||
}
|
||||
|
||||
#if UNITY_2017_1_OR_NEWER
|
||||
private ReferenceNode SearchSpriteAtlas( object obj )
|
||||
{
|
||||
SpriteAtlas spriteAtlas = (SpriteAtlas) obj;
|
||||
ReferenceNode referenceNode = PopReferenceNode( spriteAtlas );
|
||||
|
||||
SerializedObject spriteAtlasSO = new SerializedObject( spriteAtlas );
|
||||
@@ -1068,13 +1138,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 ) )
|
||||
{
|
||||
@@ -1108,20 +1178,20 @@ 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
|
||||
// Iterate over all these occurrences: "guid\": \"GUID_VALUE\" (\" is used instead of " because it is a nested JSON)
|
||||
IterateOverValuesInString( graphJson, "\"guid\\\"", '"', ( guid ) =>
|
||||
IterateOverValuesInString( graphJson, new string[] { "\"guid\\\"" }, '"', ( guid ) =>
|
||||
{
|
||||
if( guid.Length > 1 )
|
||||
{
|
||||
@@ -1141,7 +1211,7 @@ namespace AssetUsageDetectorNamespace
|
||||
if( shaderIncludesToSearchSet.Count > 0 )
|
||||
{
|
||||
// Iterate over all these occurrences: "m_FunctionSource": "GUID_VALUE" (this one is not nested JSON)
|
||||
IterateOverValuesInString( graphJson, "\"m_FunctionSource\"", '"', ( guid ) =>
|
||||
IterateOverValuesInString( graphJson, new string[] { "\"m_FunctionSource\"" }, '"', ( guid ) =>
|
||||
{
|
||||
string referencePath = AssetDatabase.GUIDToAssetPath( guid );
|
||||
if( !string.IsNullOrEmpty( referencePath ) && assetsToSearchPathsSet.Contains( referencePath ) )
|
||||
@@ -1237,6 +1307,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 )
|
||||
{
|
||||
@@ -1324,8 +1407,8 @@ namespace AssetUsageDetectorNamespace
|
||||
{
|
||||
string shaderPath = AssetDatabase.GetAssetPath( (Object) referenceNode.nodeObject );
|
||||
|
||||
// Iterate over all these occurrences: #include: "INCLUDE_REFERENCE"
|
||||
IterateOverValuesInString( File.ReadAllText( shaderPath ), "#include ", '"', ( include ) =>
|
||||
// Iterate over all these occurrences: #include "INCLUDE_REFERENCE" or #include_with_pragmas "INCLUDE_REFERENCE"
|
||||
IterateOverValuesInString( File.ReadAllText( shaderPath ), new string[] { "#include ", "#include_with_pragmas " }, '"', ( include ) =>
|
||||
{
|
||||
bool isIncludePotentialReference = shaderIncludesToSearchSet.Contains( include );
|
||||
if( !isIncludePotentialReference )
|
||||
@@ -1351,10 +1434,16 @@ namespace AssetUsageDetectorNamespace
|
||||
}
|
||||
|
||||
// Search through variables of an object with SerializedObject
|
||||
private void SearchVariablesWithSerializedObject( ReferenceNode referenceNode )
|
||||
private void SearchVariablesWithSerializedObject( ReferenceNode referenceNode, bool forceUseSerializedObject = false )
|
||||
{
|
||||
if( !isInPlayMode || referenceNode.nodeObject.IsAsset() )
|
||||
if( !isInPlayMode || referenceNode.nodeObject.IsAsset() || forceUseSerializedObject )
|
||||
{
|
||||
#if ASSET_USAGE_ADDRESSABLES
|
||||
// See: https://github.com/yasirkula/UnityAssetUsageDetector/issues/29
|
||||
if( searchParameters.addressablesSupport && ( (Object) referenceNode.nodeObject ).name == "Deprecated EditorExtensionImpl" )
|
||||
return;
|
||||
#endif
|
||||
|
||||
SerializedObject so = new SerializedObject( (Object) referenceNode.nodeObject );
|
||||
SerializedProperty iterator = so.GetIterator();
|
||||
SerializedProperty iteratorVisible = so.GetIterator();
|
||||
@@ -1398,15 +1487,38 @@ 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:
|
||||
propertyValue = null;
|
||||
searchResult = null;
|
||||
enterChildren = true;
|
||||
#if ASSET_USAGE_ADDRESSABLES
|
||||
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;
|
||||
searchResult = null;
|
||||
enterChildren = true;
|
||||
}
|
||||
|
||||
break;
|
||||
default:
|
||||
propertyValue = null;
|
||||
@@ -1459,6 +1571,15 @@ namespace AssetUsageDetectorNamespace
|
||||
// no need to have duplicate search entries
|
||||
if( !( variableValue is ICollection ) )
|
||||
{
|
||||
#if ASSET_USAGE_ADDRESSABLES
|
||||
if( searchParameters.addressablesSupport && variableValue is AssetReference )
|
||||
{
|
||||
variableValue = GetAddressablesAssetReferenceValue( (AssetReference) variableValue );
|
||||
if( variableValue == null || variableValue.Equals( null ) )
|
||||
continue;
|
||||
}
|
||||
#endif
|
||||
|
||||
ReferenceNode searchResult = SearchObject( PreferablyGameObject( variableValue ) );
|
||||
if( searchResult != null && searchResult != referenceNode )
|
||||
{
|
||||
@@ -1556,6 +1677,12 @@ namespace AssetUsageDetectorNamespace
|
||||
if( field.FieldType.IsIgnoredUnityType() )
|
||||
continue;
|
||||
|
||||
#if UNITY_2021_2_OR_NEWER
|
||||
// "ref struct"s can't be accessed via reflection
|
||||
if( field.FieldType.IsByRefLike )
|
||||
continue;
|
||||
#endif
|
||||
|
||||
// Additional filtering for fields:
|
||||
// 1- Ignore "m_RectTransform", "m_CanvasRenderer" and "m_Canvas" fields of Graphic components
|
||||
string fieldName = field.Name;
|
||||
@@ -1590,6 +1717,12 @@ namespace AssetUsageDetectorNamespace
|
||||
if( property.PropertyType.IsIgnoredUnityType() )
|
||||
continue;
|
||||
|
||||
#if UNITY_2021_2_OR_NEWER
|
||||
// "ref struct"s can't be accessed via reflection
|
||||
if( property.PropertyType.IsByRefLike )
|
||||
continue;
|
||||
#endif
|
||||
|
||||
// Skip properties without a getter function
|
||||
MethodInfo propertyGetter = property.GetGetMethod( true );
|
||||
if( propertyGetter == null )
|
||||
@@ -1626,6 +1759,10 @@ namespace AssetUsageDetectorNamespace
|
||||
#endif
|
||||
typeof( Collider2D ).IsAssignableFrom( currType ) ) )
|
||||
continue;
|
||||
// Ignore certain Material properties that are already searched via SearchMaterial function (also, if a material doesn't have a _Color or _BaseColor
|
||||
// property and its "color" property is called, it logs an error to the console, so this rule helps avoid that scenario, as well)
|
||||
else if( ( propertyName == "color" || propertyName == "mainTexture" ) && typeof( Material ).IsAssignableFrom( currType ) )
|
||||
continue;
|
||||
// Ignore "parameters" property of Animator since it doesn't contain any useful data and logs a warning to the console when Animator is inactive
|
||||
else if( typeof( Animator ).IsAssignableFrom( currType ) && propertyName == "parameters" )
|
||||
continue;
|
||||
@@ -1737,29 +1874,71 @@ namespace AssetUsageDetectorNamespace
|
||||
return enumerator.Current;
|
||||
}
|
||||
|
||||
#if ASSET_USAGE_ADDRESSABLES
|
||||
private Object GetAddressablesAssetReferenceValue( AssetReference assetReference )
|
||||
{
|
||||
Object result = assetReference.editorAsset;
|
||||
if( !result )
|
||||
return null;
|
||||
|
||||
string subObjectName = assetReference.SubObjectName;
|
||||
if( !string.IsNullOrEmpty( subObjectName ) )
|
||||
{
|
||||
if( result is SpriteAtlas )
|
||||
{
|
||||
Sprite[] packedSprites = spriteAtlasPackedSpritesGetter( (SpriteAtlas) result );
|
||||
if( packedSprites != null )
|
||||
{
|
||||
for( int i = 0; i < packedSprites.Length; i++ )
|
||||
{
|
||||
if( packedSprites[i] && packedSprites[i].name == subObjectName )
|
||||
return packedSprites[i];
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Type subObjectType = (Type) assetReferenceSubObjectTypeGetter.GetValue( assetReference, null ) ?? typeof( Object );
|
||||
Object[] subAssets = AssetDatabase.LoadAllAssetRepresentationsAtPath( AssetDatabase.GetAssetPath( result ) );
|
||||
for( int k = 0; k < subAssets.Length; k++ )
|
||||
{
|
||||
if( subAssets[k] && subAssets[k].name == subObjectName && subObjectType.IsAssignableFrom( subAssets[k].GetType() ) )
|
||||
return subAssets[k];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
#endif
|
||||
|
||||
// Iterates over all occurrences of specific key-value pairs in string
|
||||
// Example1: #include "VALUE" valuePrefix=#include, valueWrapperChar="
|
||||
// Example2: "guid": "VALUE" valuePrefix="guid", valueWrapperChar="
|
||||
private void IterateOverValuesInString( string str, string valuePrefix, char valueWrapperChar, Action<string> valueAction )
|
||||
private void IterateOverValuesInString( string str, string[] valuePrefixes, char valueWrapperChar, Action<string> valueAction )
|
||||
{
|
||||
int valueStartIndex, valueEndIndex = 0;
|
||||
while( true )
|
||||
for( int i = 0; i < valuePrefixes.Length; i++ )
|
||||
{
|
||||
valueStartIndex = str.IndexOf( valuePrefix, valueEndIndex );
|
||||
if( valueStartIndex < 0 )
|
||||
return;
|
||||
string valuePrefix = valuePrefixes[i];
|
||||
int valueStartIndex, valueEndIndex = 0;
|
||||
while( true )
|
||||
{
|
||||
valueStartIndex = str.IndexOf( valuePrefix, valueEndIndex );
|
||||
if( valueStartIndex < 0 )
|
||||
break;
|
||||
|
||||
valueStartIndex = str.IndexOf( valueWrapperChar, valueStartIndex + valuePrefix.Length );
|
||||
if( valueStartIndex < 0 )
|
||||
return;
|
||||
valueStartIndex = str.IndexOf( valueWrapperChar, valueStartIndex + valuePrefix.Length );
|
||||
if( valueStartIndex < 0 )
|
||||
break;
|
||||
|
||||
valueStartIndex++;
|
||||
valueEndIndex = str.IndexOf( valueWrapperChar, valueStartIndex );
|
||||
if( valueEndIndex < 0 )
|
||||
return;
|
||||
valueStartIndex++;
|
||||
valueEndIndex = str.IndexOf( valueWrapperChar, valueStartIndex );
|
||||
if( valueEndIndex < 0 )
|
||||
break;
|
||||
|
||||
if( valueEndIndex > valueStartIndex )
|
||||
valueAction( str.Substring( valueStartIndex, valueEndIndex - valueStartIndex ) );
|
||||
if( valueEndIndex > valueStartIndex )
|
||||
valueAction( str.Substring( valueStartIndex, valueEndIndex - valueStartIndex ) );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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 ) );
|
||||
|
||||
@@ -22,6 +22,7 @@ namespace AssetUsageDetectorNamespace
|
||||
private enum WindowFilter { AlwaysReturnActive, ReturnActiveIfNotLocked, AlwaysReturnNew };
|
||||
|
||||
private const string PREFS_SEARCH_SCENES = "AUD_SceneSearch";
|
||||
private const string PREFS_SEARCH_SCENE_LIGHTING_SETTINGS = "AUD_LightingSettingsSearch";
|
||||
private const string PREFS_SEARCH_ASSETS = "AUD_AssetsSearch";
|
||||
private const string PREFS_SEARCH_PROJECT_SETTINGS = "AUD_ProjectSettingsSearch";
|
||||
private const string PREFS_DONT_SEARCH_SOURCE_ASSETS = "AUD_AssetsExcludeSrc";
|
||||
@@ -31,6 +32,7 @@ namespace AssetUsageDetectorNamespace
|
||||
private const string PREFS_SEARCH_NON_SERIALIZABLES = "AUD_NonSerializables";
|
||||
private const string PREFS_SEARCH_UNUSED_MATERIAL_PROPERTIES = "AUD_SearchUnusedMaterialProps";
|
||||
private const string PREFS_LAZY_SCENE_SEARCH = "AUD_LazySceneSearch";
|
||||
private const string PREFS_ADDRESSABLES_SUPPORT = "AUD_AddressablesSupport";
|
||||
private const string PREFS_CALCULATE_UNUSED_OBJECTS = "AUD_FindUnusedObjs";
|
||||
private const string PREFS_HIDE_DUPLICATE_ROWS = "AUD_HideDuplicates";
|
||||
private const string PREFS_HIDE_REDUNDANT_PREFAB_VARIANT_LINKS = "AUD_HideRedundantPVariantLinks";
|
||||
@@ -72,6 +74,7 @@ namespace AssetUsageDetectorNamespace
|
||||
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 searchInSceneLightingSettings = true; // Window-Rendering-Lighting settings
|
||||
private bool searchInAssetsFolder = true; // Assets in Project window
|
||||
private bool dontSearchInSourceAssets = true; // objectsToSearch won't be searched for internal references
|
||||
private bool searchInProjectSettings = true; // Player Settings, Graphics Settings etc.
|
||||
@@ -83,6 +86,9 @@ namespace AssetUsageDetectorNamespace
|
||||
private int searchDepthLimit = 4; // Depth limit for recursively searching variables of objects
|
||||
|
||||
private bool lazySceneSearch = true;
|
||||
#if ASSET_USAGE_ADDRESSABLES
|
||||
private bool addressablesSupport = false;
|
||||
#endif
|
||||
private bool searchNonSerializableVariables = true;
|
||||
private bool searchUnusedMaterialProperties = true;
|
||||
private bool calculateUnusedObjects = false;
|
||||
@@ -152,6 +158,14 @@ namespace AssetUsageDetectorNamespace
|
||||
objectsToSearch[i].RefreshSubAssets();
|
||||
} );
|
||||
}
|
||||
else if( currentPhase == Phase.Complete )
|
||||
{
|
||||
if( searchResult != null && searchResult.NumberOfGroups > 0 )
|
||||
{
|
||||
contextMenu.AddSeparator( "" );
|
||||
contextMenu.AddItem( new GUIContent( "Collapse All" ), false, searchResult.CollapseAllSearchResultGroups );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Shows lock button at the top-right corner
|
||||
@@ -301,6 +315,7 @@ namespace AssetUsageDetectorNamespace
|
||||
if( searchParameters != null )
|
||||
{
|
||||
ParseSceneSearchMode( searchParameters.searchInScenes );
|
||||
searchInSceneLightingSettings = searchParameters.searchInSceneLightingSettings;
|
||||
searchInAssetsFolder = searchParameters.searchInAssetsFolder;
|
||||
dontSearchInSourceAssets = searchParameters.dontSearchInSourceAssets;
|
||||
searchInProjectSettings = searchParameters.searchInProjectSettings;
|
||||
@@ -311,6 +326,9 @@ namespace AssetUsageDetectorNamespace
|
||||
searchUnusedMaterialProperties = searchParameters.searchUnusedMaterialProperties;
|
||||
searchRefactoring = searchParameters.searchRefactoring;
|
||||
lazySceneSearch = searchParameters.lazySceneSearch;
|
||||
#if ASSET_USAGE_ADDRESSABLES
|
||||
addressablesSupport = searchParameters.addressablesSupport;
|
||||
#endif
|
||||
calculateUnusedObjects = searchParameters.calculateUnusedObjects;
|
||||
hideDuplicateRows = searchParameters.hideDuplicateRows;
|
||||
hideReduntantPrefabVariantLinks = searchParameters.hideReduntantPrefabVariantLinks;
|
||||
@@ -381,6 +399,7 @@ namespace AssetUsageDetectorNamespace
|
||||
private void SavePrefs()
|
||||
{
|
||||
EditorPrefs.SetInt( PREFS_SEARCH_SCENES, (int) GetSceneSearchMode( false ) );
|
||||
EditorPrefs.SetBool( PREFS_SEARCH_SCENE_LIGHTING_SETTINGS, searchInSceneLightingSettings );
|
||||
EditorPrefs.SetBool( PREFS_SEARCH_ASSETS, searchInAssetsFolder );
|
||||
EditorPrefs.SetBool( PREFS_DONT_SEARCH_SOURCE_ASSETS, dontSearchInSourceAssets );
|
||||
EditorPrefs.SetBool( PREFS_SEARCH_PROJECT_SETTINGS, searchInProjectSettings );
|
||||
@@ -390,6 +409,9 @@ namespace AssetUsageDetectorNamespace
|
||||
EditorPrefs.SetBool( PREFS_SEARCH_NON_SERIALIZABLES, searchNonSerializableVariables );
|
||||
EditorPrefs.SetBool( PREFS_SEARCH_UNUSED_MATERIAL_PROPERTIES, searchUnusedMaterialProperties );
|
||||
EditorPrefs.SetBool( PREFS_LAZY_SCENE_SEARCH, lazySceneSearch );
|
||||
#if ASSET_USAGE_ADDRESSABLES
|
||||
EditorPrefs.SetBool( PREFS_ADDRESSABLES_SUPPORT, addressablesSupport );
|
||||
#endif
|
||||
EditorPrefs.SetBool( PREFS_CALCULATE_UNUSED_OBJECTS, calculateUnusedObjects );
|
||||
EditorPrefs.SetBool( PREFS_HIDE_DUPLICATE_ROWS, hideDuplicateRows );
|
||||
EditorPrefs.SetBool( PREFS_HIDE_REDUNDANT_PREFAB_VARIANT_LINKS, hideReduntantPrefabVariantLinks );
|
||||
@@ -399,7 +421,7 @@ namespace AssetUsageDetectorNamespace
|
||||
private void LoadPrefs()
|
||||
{
|
||||
ParseSceneSearchMode( (SceneSearchMode) EditorPrefs.GetInt( PREFS_SEARCH_SCENES, (int) ( SceneSearchMode.OpenScenes | SceneSearchMode.ScenesInBuildSettingsTickedOnly | SceneSearchMode.AllScenes ) ) );
|
||||
|
||||
searchInSceneLightingSettings = EditorPrefs.GetBool( PREFS_SEARCH_SCENE_LIGHTING_SETTINGS, true );
|
||||
searchInAssetsFolder = EditorPrefs.GetBool( PREFS_SEARCH_ASSETS, true );
|
||||
dontSearchInSourceAssets = EditorPrefs.GetBool( PREFS_DONT_SEARCH_SOURCE_ASSETS, true );
|
||||
searchInProjectSettings = EditorPrefs.GetBool( PREFS_SEARCH_PROJECT_SETTINGS, true );
|
||||
@@ -409,6 +431,9 @@ namespace AssetUsageDetectorNamespace
|
||||
searchNonSerializableVariables = EditorPrefs.GetBool( PREFS_SEARCH_NON_SERIALIZABLES, true );
|
||||
searchUnusedMaterialProperties = EditorPrefs.GetBool( PREFS_SEARCH_UNUSED_MATERIAL_PROPERTIES, true );
|
||||
lazySceneSearch = EditorPrefs.GetBool( PREFS_LAZY_SCENE_SEARCH, true );
|
||||
#if ASSET_USAGE_ADDRESSABLES
|
||||
addressablesSupport = EditorPrefs.GetBool( PREFS_ADDRESSABLES_SUPPORT, false );
|
||||
#endif
|
||||
calculateUnusedObjects = EditorPrefs.GetBool( PREFS_CALCULATE_UNUSED_OBJECTS, false );
|
||||
hideDuplicateRows = EditorPrefs.GetBool( PREFS_HIDE_DUPLICATE_ROWS, true );
|
||||
hideReduntantPrefabVariantLinks = EditorPrefs.GetBool( PREFS_HIDE_REDUNDANT_PREFAB_VARIANT_LINKS, true );
|
||||
@@ -533,6 +558,10 @@ namespace AssetUsageDetectorNamespace
|
||||
GUILayout.EndVertical();
|
||||
GUILayout.EndHorizontal();
|
||||
|
||||
EditorGUI.BeginDisabledGroup( !searchInOpenScenes && !searchInScenesInBuild && !searchInAllScenes );
|
||||
searchInSceneLightingSettings = WordWrappingToggleLeft( "Scene Lighting Settings (WARNING: This may change the active scene during search)", searchInSceneLightingSettings );
|
||||
EditorGUI.EndDisabledGroup();
|
||||
|
||||
Utilities.DrawSeparatorLine();
|
||||
|
||||
searchInProjectSettings = WordWrappingToggleLeft( "Project Settings (Player Settings, Graphics Settings etc.)", searchInProjectSettings );
|
||||
@@ -543,7 +572,14 @@ namespace AssetUsageDetectorNamespace
|
||||
GUILayout.Box( "<b>SETTINGS</b>", Utilities.BoxGUIStyle, Utilities.GL_EXPAND_WIDTH );
|
||||
GUI.backgroundColor = c;
|
||||
|
||||
#if ASSET_USAGE_ADDRESSABLES
|
||||
EditorGUI.BeginDisabledGroup( addressablesSupport );
|
||||
#endif
|
||||
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 (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 );
|
||||
#if UNITY_2018_3_OR_NEWER
|
||||
@@ -667,6 +703,7 @@ namespace AssetUsageDetectorNamespace
|
||||
{
|
||||
objectsToSearch = !objectsToSearch.IsEmpty() ? new ObjectToSearchEnumerator( objectsToSearch ).ToArray() : null,
|
||||
searchInScenes = GetSceneSearchMode( true ),
|
||||
searchInSceneLightingSettings = searchInSceneLightingSettings,
|
||||
searchInAssetsFolder = searchInAssetsFolder,
|
||||
searchInAssetsSubset = !searchInAssetsSubset.IsEmpty() ? searchInAssetsSubset.ToArray() : null,
|
||||
excludedAssetsFromSearch = !excludedAssets.IsEmpty() ? excludedAssets.ToArray() : null,
|
||||
@@ -679,7 +716,12 @@ namespace AssetUsageDetectorNamespace
|
||||
//searchNonSerializableVariables = searchNonSerializableVariables,
|
||||
searchUnusedMaterialProperties = searchUnusedMaterialProperties,
|
||||
searchRefactoring = searchRefactoring,
|
||||
#if ASSET_USAGE_ADDRESSABLES
|
||||
lazySceneSearch = lazySceneSearch && !addressablesSupport,
|
||||
addressablesSupport = addressablesSupport,
|
||||
#else
|
||||
lazySceneSearch = lazySceneSearch,
|
||||
#endif
|
||||
calculateUnusedObjects = calculateUnusedObjects,
|
||||
hideDuplicateRows = hideDuplicateRows,
|
||||
hideReduntantPrefabVariantLinks = hideReduntantPrefabVariantLinks,
|
||||
|
||||
@@ -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;
|
||||
@@ -371,9 +372,15 @@ namespace AssetUsageDetectorNamespace
|
||||
return scrollPosition;
|
||||
}
|
||||
|
||||
public int IndexOf( SearchResultGroup searchResult )
|
||||
public int IndexOf( SearchResultGroup searchResultGroup )
|
||||
{
|
||||
return result.IndexOf( searchResult );
|
||||
return result.IndexOf( searchResultGroup );
|
||||
}
|
||||
|
||||
public void CollapseAllSearchResultGroups()
|
||||
{
|
||||
for( int i = 0; i < result.Count; i++ )
|
||||
result[i].Collapse();
|
||||
}
|
||||
|
||||
public void CancelDelayedTreeViewTooltip()
|
||||
@@ -600,6 +607,11 @@ namespace AssetUsageDetectorNamespace
|
||||
treeViewSearchField = null;
|
||||
}
|
||||
|
||||
public void Collapse()
|
||||
{
|
||||
IsExpanded = false;
|
||||
}
|
||||
|
||||
// Initializes commonly used variables of the nodes
|
||||
public void InitializeNodes( HashSet<Object> objectsToSearchSet )
|
||||
{
|
||||
@@ -725,7 +737,7 @@ namespace AssetUsageDetectorNamespace
|
||||
if( searchResult != null )
|
||||
contextMenu.AddItem( new GUIContent( "Hide" ), false, () => searchResult.RemoveSearchResultGroup( this ) );
|
||||
|
||||
if( references.Count > 0 )
|
||||
if( references.Count > 0 && treeView != null )
|
||||
{
|
||||
if( contextMenu.GetItemCount() > 0 )
|
||||
contextMenu.AddSeparator( "" );
|
||||
@@ -791,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 );
|
||||
@@ -1210,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;
|
||||
}
|
||||
}
|
||||
@@ -966,6 +966,8 @@ namespace AssetUsageDetectorNamespace
|
||||
for( int i = 0; i < item.children.Count; i++ )
|
||||
shouldExpand |= GetMainReferenceIdsRecursive( item.children[i], ids );
|
||||
}
|
||||
else
|
||||
shouldExpand = true; // No main reference is encountered in this branch; expand the whole branch
|
||||
|
||||
if( shouldExpand )
|
||||
ids.Add( item.id );
|
||||
@@ -1178,7 +1180,7 @@ namespace AssetUsageDetectorNamespace
|
||||
SearchResultTreeView isolatedTreeView = new SearchResultTreeView( new SearchResultTreeViewState(), selectedNodes, TreeType.IsolatedView, null, hideDuplicateRows, hideReduntantPrefabVariantLinks, false );
|
||||
isolatedTreeView.ExpandMainReferences();
|
||||
|
||||
SearchResultTreeViewIsolatedView.Show( new Vector2( EditorWindow.focusedWindow.position.width, isolatedTreeView.totalHeight + 1f ), isolatedTreeView, new GUIContent( selectedNodes[0].Label + ( selectedNodes.Count <= 1 ? "" : ( " (and " + ( selectedNodes.Count - 1 ) + " more)" ) ) ) );
|
||||
SearchResultTreeViewIsolatedView.Show( new Vector2( EditorWindow.focusedWindow.position.width, Mathf.Max( isolatedTreeView.totalHeight, EditorGUIUtility.singleLineHeight * 5f ) + 1f ), isolatedTreeView, new GUIContent( selectedNodes[0].Label + ( selectedNodes.Count <= 1 ? "" : ( " (and " + ( selectedNodes.Count - 1 ) + " more)" ) ) ) );
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1332,7 +1334,7 @@ namespace AssetUsageDetectorNamespace
|
||||
SearchResultTreeViewIsolatedView window = CreateInstance<SearchResultTreeViewIsolatedView>();
|
||||
window.treeView = treeView;
|
||||
window.titleContent = title;
|
||||
window.ShowAuxWindow();
|
||||
window.Show();
|
||||
|
||||
window.minSize = new Vector2( 150f, Mathf.Min( preferredSize.y, EditorGUIUtility.singleLineHeight * 2f ) );
|
||||
window.position = new Rect( new Vector2( -9999f, -9999f ), preferredSize );
|
||||
|
||||
@@ -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,5 +1,6 @@
|
||||
using System;
|
||||
using System.Reflection;
|
||||
using System.Text;
|
||||
using UnityEngine;
|
||||
|
||||
namespace AssetUsageDetectorNamespace
|
||||
@@ -39,7 +40,12 @@ namespace AssetUsageDetectorNamespace
|
||||
}
|
||||
catch( Exception e )
|
||||
{
|
||||
Debug.LogException( e );
|
||||
StringBuilder sb = Utilities.stringBuilder;
|
||||
sb.Length = 0;
|
||||
sb.Append( "Error while getting the value of (" ).Append( IsProperty ? ( (PropertyInfo) variable ).PropertyType : ( (FieldInfo) variable ).FieldType ).Append( ") " )
|
||||
.Append( variable.DeclaringType ).Append( "." ).Append( Name ).Append( ": " ).Append( e );
|
||||
|
||||
Debug.LogError( sb.ToString() );
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,45 +1,4 @@
|
||||
= Asset Usage Detector =
|
||||
= Asset Usage Detector (v2.5.0) =
|
||||
|
||||
Online documentation available at: https://github.com/yasirkula/UnityAssetUsageDetector
|
||||
E-mail: yasirkula@gmail.com
|
||||
|
||||
|
||||
### ABOUT
|
||||
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.
|
||||
|
||||
|
||||
### 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"
|
||||
|
||||
- Asset Usage Detector window can be locked via the "Lock" button in its context menu (or via the lock icon at the top-right corner). If all the
|
||||
open windows are locked, "Search For References" opens a new window
|
||||
|
||||
- Seach results are split into different groups (scenes, assets, Project Settings) and each group displays its search results in its own tree view.
|
||||
Tree views support multi-selection and keyboard navigation. It's possible to hide groups or rows via their context menu (right click)
|
||||
|
||||
- Each root row in a group's tree view represents a different searched object and is drawn with an outline. Usage(s) of a searched object are listed under it as
|
||||
child rows (with indentation). If a child row's label contains bold text inside square brackets (e.g. "[Variable: m_Shader]"), then that text describes how
|
||||
its parent row is connected to that row (i.e. the value assigned to the m_Shader variable of that row is its parent row). Child rows can have their own children
|
||||
as some references involve multiple steps (e.g. when a Texture reference is found in a material which is used in a prefab which is referenced by a scene object)
|
||||
|
||||
- Rows with green tint to their left are the main references. For example, main references in a scene are the GameObjects that belong to that scene
|
||||
|
||||
- Rows with yellow tint are the parent rows of the selected row(s). To see a row's connection to the searched object, the yellow tinted rows can be traversed
|
||||
from bottom to top (or, you can hover the cursor over a row and see its connection to the searched object in a tooltip)
|
||||
|
||||
- Rows with gradient blue tint are the other occurrences of the selected row(s) (a row can appear multiple times in the tree view, right clicking the row and
|
||||
selecting "Expand All Occurrences" will reveal them all)
|
||||
|
||||
- When "Hide duplicate rows" option is enabled and a row's label starts with "[D]", then it means that the row has appeared in the tree view before and its children
|
||||
were omitted to simplify the search results (because otherwise the same child rows would be displayed for each occurrence of that row). Only the first occurrence
|
||||
of a row will display its children when "Hide duplicate rows" is enabled. To find a row's first occurrence, you can right click it and select "Select First Occurrence"
|
||||
|
||||
- Inside "Unused Objects" group, if a row's label starts with "[!]", then it means that some of its children are used in the project and it isn't safe to delete
|
||||
that object. Right clicking the row and selecting "Show Used Children" will reveal the used children
|
||||
|
||||
- When a prefab's row is double clicked, that prefab is automatically opened in Prefab Mode
|
||||
|
||||
- Selections in tree views are completely independent from each other, it isn't possible to multi-select objects in different tree views. Likewise, selected rows in
|
||||
a tree view won't be highlighted in other tree views. "Hide duplicate rows" also works independently for each tree view
|
||||
|
||||
- You can tweak most settings/colors via "Project Settings/yasirkula/Asset Usage Detector" page (on older versions, this menu is located at "Preferences" window)
|
||||
Documentation: https://github.com/yasirkula/UnityAssetUsageDetector
|
||||
E-mail: yasirkula@gmail.com
|
||||
+1
-1
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"name": "com.yasirkula.assetusagedetector",
|
||||
"displayName": "Asset Usage Detector",
|
||||
"version": "2.2.2",
|
||||
"version": "2.5.0",
|
||||
"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