mirror of
https://github.com/yasirkula/UnityAssetUsageDetector.git
synced 2026-11-19 22:42:37 +08:00
Compare commits
4 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| b0bf247aa4 | |||
| 4e4321bdae | |||
| 69f7ee5a27 | |||
| afda67474b |
@@ -184,18 +184,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<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
|
||||
private readonly PropertyInfo assetReferenceSubObjectTypeGetter =
|
||||
typeof( AssetReference ).GetProperty( "SubObjectType", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance )
|
||||
?? typeof( AssetReference ).GetProperty( "SubOjbectType", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance );
|
||||
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)?.GetMethod
|
||||
?? typeof(AssetReference).GetProperty("SubOjbectType", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance).GetMethod);
|
||||
#endif
|
||||
|
||||
#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 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
|
||||
|
||||
private void InitializeSearchFunctionsData( Parameters searchParameters )
|
||||
@@ -1810,41 +1809,39 @@ namespace AssetUsageDetectorNamespace
|
||||
}
|
||||
|
||||
#if ASSET_USAGE_ADDRESSABLES
|
||||
private Object GetAddressablesAssetReferenceValue( AssetReference assetReference )
|
||||
{
|
||||
Object result = assetReference.editorAsset;
|
||||
if( !result )
|
||||
return null;
|
||||
private Object GetAddressablesAssetReferenceValue(AssetReference assetReference)
|
||||
{
|
||||
Object result = assetReference.editorAsset;
|
||||
if (result == null)
|
||||
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];
|
||||
}
|
||||
}
|
||||
}
|
||||
string subObjectName = assetReference.SubObjectName;
|
||||
if (string.IsNullOrEmpty(subObjectName))
|
||||
return result;
|
||||
|
||||
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
|
||||
|
||||
private bool ShouldExcludeRedundantPrefabReferences( Object obj )
|
||||
@@ -1889,4 +1886,4 @@ namespace AssetUsageDetectorNamespace
|
||||
return ( component != null && !component.Equals( null ) ) ? component.gameObject : obj;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -99,15 +99,11 @@ namespace AssetUsageDetectorNamespace
|
||||
// Add Sprites of SpriteAtlases to the sub-assets list
|
||||
if( target is SpriteAtlas spriteAtlas )
|
||||
{
|
||||
Sprite[] packedSprites = AssetUsageDetector.spriteAtlasPackedSpritesGetter( spriteAtlas );
|
||||
if( packedSprites != null )
|
||||
{
|
||||
for( int i = 0; i < packedSprites.Length; i++ )
|
||||
{
|
||||
if( packedSprites[i] != null && currentSubAssets.Add( packedSprites[i] ) )
|
||||
subAssets.Add( new SubAsset( packedSprites[i], shouldSearchChildren ?? true ) );
|
||||
}
|
||||
}
|
||||
foreach (Sprite sprite in spriteAtlas.GetPackedSprites())
|
||||
{
|
||||
if (sprite != null && currentSubAssets.Add(sprite))
|
||||
subAssets.Add(new SubAsset(sprite, shouldSearchChildren ?? true));
|
||||
}
|
||||
}
|
||||
|
||||
// Find sub-asset(s) of the asset (if any)
|
||||
|
||||
@@ -1368,7 +1368,7 @@ namespace AssetUsageDetectorNamespace
|
||||
{
|
||||
label = Label,
|
||||
isMainReference = IsMainReference,
|
||||
instanceId = instanceId ?? 0,
|
||||
instanceId = instanceId ?? default,
|
||||
isUnityObject = instanceId.HasValue,
|
||||
usedState = usedState
|
||||
};
|
||||
@@ -1418,4 +1418,4 @@ namespace AssetUsageDetectorNamespace
|
||||
return uid;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,8 +6,10 @@ using System.Threading.Tasks;
|
||||
using Unity.Collections;
|
||||
using UnityEditor;
|
||||
using UnityEditor.SceneManagement;
|
||||
using UnityEditor.U2D;
|
||||
using UnityEngine;
|
||||
using UnityEngine.SceneManagement;
|
||||
using UnityEngine.U2D;
|
||||
using Object = UnityEngine.Object;
|
||||
|
||||
namespace AssetUsageDetectorNamespace
|
||||
@@ -564,5 +566,42 @@ namespace AssetUsageDetectorNamespace
|
||||
|
||||
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
|
||||
E-mail: yasirkula@gmail.com
|
||||
+1
-1
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"name": "com.yasirkula.assetusagedetector",
|
||||
"displayName": "Asset Usage Detector",
|
||||
"version": "2.6.1",
|
||||
"version": "2.6.3",
|
||||
"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