diff --git a/Plugins/AssetUsageDetector/Editor/AssetUsageDetectorSearchFunctions.cs b/Plugins/AssetUsageDetector/Editor/AssetUsageDetectorSearchFunctions.cs index d69e526..5c97055 100644 --- a/Plugins/AssetUsageDetector/Editor/AssetUsageDetectorSearchFunctions.cs +++ b/Plugins/AssetUsageDetector/Editor/AssetUsageDetectorSearchFunctions.cs @@ -211,8 +211,8 @@ namespace AssetUsageDetectorNamespace private readonly Func defaultReflectionProbeGetter = (Func) Delegate.CreateDelegate( typeof( Func ), typeof( RenderSettings ).GetProperty( "defaultReflection", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static ).GetGetMethod( true ) ); #endif + internal static readonly Func spriteAtlasPackedSpritesGetter = (Func) Delegate.CreateDelegate( typeof( Func ), typeof( SpriteAtlasExtensions ).GetMethod( "GetPackedSprites", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static ) ); #if ASSET_USAGE_ADDRESSABLES - private readonly Func spriteAtlasPackedSpritesGetter = (Func) Delegate.CreateDelegate( typeof( Func ), 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 diff --git a/Plugins/AssetUsageDetector/Editor/ObjectToSearch.cs b/Plugins/AssetUsageDetector/Editor/ObjectToSearch.cs index 24ad8ac..855c984 100644 --- a/Plugins/AssetUsageDetector/Editor/ObjectToSearch.cs +++ b/Plugins/AssetUsageDetector/Editor/ObjectToSearch.cs @@ -2,6 +2,7 @@ using System.Collections.Generic; using UnityEditor; using UnityEngine; +using UnityEngine.U2D; using Object = UnityEngine.Object; namespace AssetUsageDetectorNamespace @@ -95,6 +96,20 @@ namespace AssetUsageDetectorNamespace } } + // If is an Atlas we get sprites directly as GetSubAssets return the final texture + 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 ) ); + } + } + } + // Find sub-asset(s) of the asset (if any) Object[] assets = AssetDatabase.LoadAllAssetsAtPath( AssetDatabase.GetAssetPath( target ) ); for( int i = 0; i < assets.Length; i++ ) @@ -117,4 +132,4 @@ namespace AssetUsageDetectorNamespace } } } -} \ No newline at end of file +}