mirror of
https://github.com/yasirkula/UnityAssetUsageDetector.git
synced 2026-11-19 14:32:37 +08:00
Compare commits
5 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 7b291b2190 | |||
| b0bf247aa4 | |||
| 4e4321bdae | |||
| 69f7ee5a27 | |||
| afda67474b |
@@ -24,6 +24,11 @@
|
|||||||
"name": "com.unity.visualeffectgraph",
|
"name": "com.unity.visualeffectgraph",
|
||||||
"expression": "0.0.0",
|
"expression": "0.0.0",
|
||||||
"define": "ASSET_USAGE_VFX_GRAPH"
|
"define": "ASSET_USAGE_VFX_GRAPH"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "com.unity.ugui",
|
||||||
|
"expression": "0.0.0",
|
||||||
|
"define": "ASSET_USAGE_UGUI"
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"noEngineReferences": false
|
"noEngineReferences": false
|
||||||
|
|||||||
@@ -10,7 +10,9 @@ using UnityEditor.AddressableAssets.Settings;
|
|||||||
#endif
|
#endif
|
||||||
using UnityEditor.Animations;
|
using UnityEditor.Animations;
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
|
#if ASSET_USAGE_UGUI
|
||||||
using UnityEngine.UI;
|
using UnityEngine.UI;
|
||||||
|
#endif
|
||||||
using UnityEngine.U2D;
|
using UnityEngine.U2D;
|
||||||
using UnityEngine.Playables;
|
using UnityEngine.Playables;
|
||||||
using UnityEditor.U2D;
|
using UnityEditor.U2D;
|
||||||
@@ -184,18 +186,17 @@ namespace AssetUsageDetectorNamespace
|
|||||||
private readonly Func<Object> renderSettingsGetter = (Func<Object>) Delegate.CreateDelegate( typeof( Func<Object> ), typeof( RenderSettings ).GetMethod( "GetRenderSettings", 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 ) );
|
||||||
private readonly Func<Cubemap> defaultReflectionProbeGetter = (Func<Cubemap>) Delegate.CreateDelegate( typeof( Func<Cubemap> ), typeof( RenderSettings ).GetProperty( "defaultReflection", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static ).GetGetMethod( true ) );
|
private readonly Func<Cubemap> defaultReflectionProbeGetter = (Func<Cubemap>) Delegate.CreateDelegate( typeof( Func<Cubemap> ), typeof( RenderSettings ).GetProperty( "defaultReflection", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static ).GetGetMethod( true ) );
|
||||||
|
|
||||||
internal static readonly Func<SpriteAtlas, Sprite[]> spriteAtlasPackedSpritesGetter = (Func<SpriteAtlas, Sprite[]>) Delegate.CreateDelegate( typeof( Func<SpriteAtlas, Sprite[]> ), typeof( SpriteAtlasExtensions ).GetMethod( "GetPackedSprites", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static ) );
|
|
||||||
#if ASSET_USAGE_ADDRESSABLES
|
#if ASSET_USAGE_ADDRESSABLES
|
||||||
private readonly PropertyInfo assetReferenceSubObjectTypeGetter =
|
private readonly Func<AssetReference, Type> assetReferenceSubObjectTypeGetter = (Func<AssetReference, Type>)Delegate.CreateDelegate(typeof(Func<AssetReference, Type>),
|
||||||
typeof( AssetReference ).GetProperty( "SubObjectType", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance )
|
typeof(AssetReference).GetProperty("SubObjectType", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance)?.GetMethod
|
||||||
?? typeof( AssetReference ).GetProperty( "SubOjbectType", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance );
|
?? typeof(AssetReference).GetProperty("SubOjbectType", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance).GetMethod);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if ASSET_USAGE_VFX_GRAPH
|
#if ASSET_USAGE_VFX_GRAPH
|
||||||
private static Type vfxResourceType => typeof( Editor ).Assembly.GetType( "UnityEditor.VFX.VisualEffectResource" ) ?? Array.Find( AppDomain.CurrentDomain.GetAssemblies(), ( assembly ) => assembly.GetName().Name == "UnityEditor.VFXModule" ).GetType( "UnityEditor.VFX.VisualEffectResource" );
|
private static Type vfxResourceType => Type.GetType("UnityEditor.VFX.VisualEffectResource, UnityEditor.VFXModule") ?? typeof(Editor).Assembly.GetType("UnityEditor.VFX.VisualEffectResource");
|
||||||
private readonly Func<string, object> vfxResourceGetter = (Func<string, object>) Delegate.CreateDelegate( typeof( Func<string, object> ), vfxResourceType.GetMethod( "GetResourceAtPath", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static ) );
|
private readonly Func<string, object> vfxResourceGetter = (Func<string, object>) Delegate.CreateDelegate( typeof( Func<string, object> ), vfxResourceType.GetMethod( "GetResourceAtPath", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static ) );
|
||||||
private readonly MethodInfo vfxResourceContentsGetter = vfxResourceType.GetMethod( "GetContents", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance );
|
private readonly MethodInfo vfxResourceContentsGetter = vfxResourceType.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 );
|
private readonly MethodInfo vfxSerializableObjectValueGetter = Array.Find(Type.GetType("UnityEditor.VFX.VFXSerializableObject, Unity.VisualEffectGraph.Editor").GetMethods(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance), (methodInfo) => methodInfo.Name == "Get" && !methodInfo.IsGenericMethod);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
private void InitializeSearchFunctionsData( Parameters searchParameters )
|
private void InitializeSearchFunctionsData( Parameters searchParameters )
|
||||||
@@ -1643,11 +1644,13 @@ namespace AssetUsageDetectorNamespace
|
|||||||
continue;
|
continue;
|
||||||
|
|
||||||
// Additional filtering for fields:
|
// Additional filtering for fields:
|
||||||
|
#if ASSET_USAGE_UGUI
|
||||||
// 1- Ignore "m_RectTransform", "m_CanvasRenderer" and "m_Canvas" fields of Graphic components
|
// 1- Ignore "m_RectTransform", "m_CanvasRenderer" and "m_Canvas" fields of Graphic components
|
||||||
string fieldName = field.Name;
|
string fieldName = field.Name;
|
||||||
if( typeof( Graphic ).IsAssignableFrom( currType ) &&
|
if( typeof( Graphic ).IsAssignableFrom( currType ) &&
|
||||||
( fieldName == "m_RectTransform" || fieldName == "m_CanvasRenderer" || fieldName == "m_Canvas" ) )
|
( fieldName == "m_RectTransform" || fieldName == "m_CanvasRenderer" || fieldName == "m_Canvas" ) )
|
||||||
continue;
|
continue;
|
||||||
|
#endif
|
||||||
|
|
||||||
VariableGetVal getter = field.CreateGetter( type );
|
VariableGetVal getter = field.CreateGetter( type );
|
||||||
if (getter != null)
|
if (getter != null)
|
||||||
@@ -1683,10 +1686,12 @@ namespace AssetUsageDetectorNamespace
|
|||||||
if( typeof( Component ).IsAssignableFrom( currType ) && ( propertyName == "gameObject" ||
|
if( typeof( Component ).IsAssignableFrom( currType ) && ( propertyName == "gameObject" ||
|
||||||
propertyName == "transform" || propertyName == "attachedRigidbody" || propertyName == "rectTransform" ) )
|
propertyName == "transform" || propertyName == "attachedRigidbody" || propertyName == "rectTransform" ) )
|
||||||
continue;
|
continue;
|
||||||
|
#if ASSET_USAGE_UGUI
|
||||||
// Ignore "canvasRenderer" and "canvas" properties of Graphic components to get more useful results
|
// Ignore "canvasRenderer" and "canvas" properties of Graphic components to get more useful results
|
||||||
else if( typeof( Graphic ).IsAssignableFrom( currType ) &&
|
else if( typeof( Graphic ).IsAssignableFrom( currType ) &&
|
||||||
( propertyName == "canvasRenderer" || propertyName == "canvas" ) )
|
( propertyName == "canvasRenderer" || propertyName == "canvas" ) )
|
||||||
continue;
|
continue;
|
||||||
|
#endif
|
||||||
// Prevent accessing properties of Unity that instantiate an existing resource (causing memory leak)
|
// Prevent accessing properties of Unity that instantiate an existing resource (causing memory leak)
|
||||||
else if( typeof( MeshFilter ).IsAssignableFrom( currType ) && propertyName == "mesh" )
|
else if( typeof( MeshFilter ).IsAssignableFrom( currType ) && propertyName == "mesh" )
|
||||||
continue;
|
continue;
|
||||||
@@ -1810,41 +1815,39 @@ namespace AssetUsageDetectorNamespace
|
|||||||
}
|
}
|
||||||
|
|
||||||
#if ASSET_USAGE_ADDRESSABLES
|
#if ASSET_USAGE_ADDRESSABLES
|
||||||
private Object GetAddressablesAssetReferenceValue( AssetReference assetReference )
|
private Object GetAddressablesAssetReferenceValue(AssetReference assetReference)
|
||||||
{
|
{
|
||||||
Object result = assetReference.editorAsset;
|
Object result = assetReference.editorAsset;
|
||||||
if( !result )
|
if (result == null)
|
||||||
return null;
|
return null;
|
||||||
|
|
||||||
string subObjectName = assetReference.SubObjectName;
|
string subObjectName = assetReference.SubObjectName;
|
||||||
if( !string.IsNullOrEmpty( subObjectName ) )
|
if (string.IsNullOrEmpty(subObjectName))
|
||||||
{
|
return result;
|
||||||
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;
|
Type subObjectType = assetReferenceSubObjectTypeGetter(assetReference) ?? typeof(Object);
|
||||||
}
|
if (subObjectType.IsAssignableFrom(result.GetType()))
|
||||||
|
return result;
|
||||||
|
|
||||||
|
if (result is SpriteAtlas spriteAtlas)
|
||||||
|
{
|
||||||
|
foreach (Sprite sprite in spriteAtlas.GetPackedSprites())
|
||||||
|
{
|
||||||
|
if (sprite != null && sprite.name == subObjectName)
|
||||||
|
return sprite;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
foreach (Object subAsset in AssetDatabase.LoadAllAssetsAtPath(AssetDatabase.GetAssetPath(result)))
|
||||||
|
{
|
||||||
|
if (subAsset != null && subAsset.name == subObjectName && subObjectType.IsAssignableFrom(subAsset.GetType()))
|
||||||
|
return subAsset;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
private bool ShouldExcludeRedundantPrefabReferences( Object obj )
|
private bool ShouldExcludeRedundantPrefabReferences( Object obj )
|
||||||
@@ -1889,4 +1892,4 @@ namespace AssetUsageDetectorNamespace
|
|||||||
return ( component != null && !component.Equals( null ) ) ? component.gameObject : obj;
|
return ( component != null && !component.Equals( null ) ) ? component.gameObject : obj;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -99,15 +99,11 @@ namespace AssetUsageDetectorNamespace
|
|||||||
// Add Sprites of SpriteAtlases to the sub-assets list
|
// Add Sprites of SpriteAtlases to the sub-assets list
|
||||||
if( target is SpriteAtlas spriteAtlas )
|
if( target is SpriteAtlas spriteAtlas )
|
||||||
{
|
{
|
||||||
Sprite[] packedSprites = AssetUsageDetector.spriteAtlasPackedSpritesGetter( spriteAtlas );
|
foreach (Sprite sprite in spriteAtlas.GetPackedSprites())
|
||||||
if( packedSprites != null )
|
{
|
||||||
{
|
if (sprite != null && currentSubAssets.Add(sprite))
|
||||||
for( int i = 0; i < packedSprites.Length; i++ )
|
subAssets.Add(new SubAsset(sprite, shouldSearchChildren ?? true));
|
||||||
{
|
}
|
||||||
if( packedSprites[i] != null && currentSubAssets.Add( packedSprites[i] ) )
|
|
||||||
subAssets.Add( new SubAsset( packedSprites[i], shouldSearchChildren ?? true ) );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Find sub-asset(s) of the asset (if any)
|
// Find sub-asset(s) of the asset (if any)
|
||||||
|
|||||||
@@ -1368,7 +1368,7 @@ namespace AssetUsageDetectorNamespace
|
|||||||
{
|
{
|
||||||
label = Label,
|
label = Label,
|
||||||
isMainReference = IsMainReference,
|
isMainReference = IsMainReference,
|
||||||
instanceId = instanceId ?? 0,
|
instanceId = instanceId ?? default,
|
||||||
isUnityObject = instanceId.HasValue,
|
isUnityObject = instanceId.HasValue,
|
||||||
usedState = usedState
|
usedState = usedState
|
||||||
};
|
};
|
||||||
@@ -1418,4 +1418,4 @@ namespace AssetUsageDetectorNamespace
|
|||||||
return uid;
|
return uid;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,8 +6,10 @@ using System.Threading.Tasks;
|
|||||||
using Unity.Collections;
|
using Unity.Collections;
|
||||||
using UnityEditor;
|
using UnityEditor;
|
||||||
using UnityEditor.SceneManagement;
|
using UnityEditor.SceneManagement;
|
||||||
|
using UnityEditor.U2D;
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
using UnityEngine.SceneManagement;
|
using UnityEngine.SceneManagement;
|
||||||
|
using UnityEngine.U2D;
|
||||||
using Object = UnityEngine.Object;
|
using Object = UnityEngine.Object;
|
||||||
|
|
||||||
namespace AssetUsageDetectorNamespace
|
namespace AssetUsageDetectorNamespace
|
||||||
@@ -564,5 +566,42 @@ namespace AssetUsageDetectorNamespace
|
|||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static List<Sprite> GetPackedSprites(this SpriteAtlas spriteAtlas)
|
||||||
|
{
|
||||||
|
SpriteAtlas masterAtlas = spriteAtlas.isVariant ? spriteAtlas.GetMasterAtlas() : null;
|
||||||
|
Object[] packables = (masterAtlas != null) ? masterAtlas.GetPackables() : spriteAtlas.GetPackables();
|
||||||
|
List<Sprite> result = new(packables.Length);
|
||||||
|
|
||||||
|
foreach (Object packable in packables)
|
||||||
|
{
|
||||||
|
if (packable == null)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
if (packable.IsFolder())
|
||||||
|
{
|
||||||
|
foreach (string guid in AssetDatabase.FindAssets("t:Sprite", new[] { AssetDatabase.GetAssetPath(packable) }))
|
||||||
|
{
|
||||||
|
foreach (Object asset in AssetDatabase.LoadAllAssetsAtPath(AssetDatabase.GUIDToAssetPath(guid)))
|
||||||
|
{
|
||||||
|
if (asset is Sprite sprite)
|
||||||
|
result.Add(sprite);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (packable is Texture2D)
|
||||||
|
{
|
||||||
|
foreach (Object asset in AssetDatabase.LoadAllAssetsAtPath(AssetDatabase.GetAssetPath(packable)))
|
||||||
|
{
|
||||||
|
if (asset is Sprite sprite)
|
||||||
|
result.Add(sprite);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (packable is Sprite sprite)
|
||||||
|
result.Add(sprite);
|
||||||
|
}
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
= Asset Usage Detector (v2.6.1) =
|
= Asset Usage Detector (v2.6.3) =
|
||||||
|
|
||||||
Documentation: https://github.com/yasirkula/UnityAssetUsageDetector
|
Documentation: https://github.com/yasirkula/UnityAssetUsageDetector
|
||||||
E-mail: yasirkula@gmail.com
|
E-mail: yasirkula@gmail.com
|
||||||
+1
-1
@@ -1,7 +1,7 @@
|
|||||||
{
|
{
|
||||||
"name": "com.yasirkula.assetusagedetector",
|
"name": "com.yasirkula.assetusagedetector",
|
||||||
"displayName": "Asset Usage Detector",
|
"displayName": "Asset Usage Detector",
|
||||||
"version": "2.6.1",
|
"version": "2.6.3",
|
||||||
"documentationUrl": "https://github.com/yasirkula/UnityAssetUsageDetector",
|
"documentationUrl": "https://github.com/yasirkula/UnityAssetUsageDetector",
|
||||||
"changelogUrl": "https://github.com/yasirkula/UnityAssetUsageDetector/releases",
|
"changelogUrl": "https://github.com/yasirkula/UnityAssetUsageDetector/releases",
|
||||||
"licensesUrl": "https://github.com/yasirkula/UnityAssetUsageDetector/blob/master/LICENSE.txt",
|
"licensesUrl": "https://github.com/yasirkula/UnityAssetUsageDetector/blob/master/LICENSE.txt",
|
||||||
|
|||||||
Reference in New Issue
Block a user