| | |
| | | |
| | | return $"Spine: {spineTotal}, Audio: {audioTotal}"; |
| | | } |
| | | |
| | | // ===== 编辑器调试接口 ===== |
| | | #if UNITY_EDITOR |
| | | // 编辑器模式下的资源引用调试类 |
| | | public class ResourceReferenceDebug |
| | | { |
| | | public BattleResCache.CachedResource CachedResource; |
| | | public Dictionary<string, HashSet<string>> BattlefieldOwners; |
| | | |
| | | public int RefCount |
| | | { |
| | | get |
| | | { |
| | | int count = 0; |
| | | foreach (var owners in BattlefieldOwners.Values) |
| | | { |
| | | count += owners.Count; |
| | | } |
| | | return count; |
| | | } |
| | | } |
| | | |
| | | // 私有构造函数,只能由 DebugAPI 调用 |
| | | internal ResourceReferenceDebug() |
| | | { |
| | | } |
| | | } |
| | | |
| | | public static class DebugAPI |
| | | { |
| | | public static Dictionary<string, ResourceReferenceDebug> GetSpineCache() |
| | | { |
| | | var result = new Dictionary<string, ResourceReferenceDebug>(); |
| | | foreach (var kvp in globalSpineCache) |
| | | { |
| | | // 直接在这里赋值,不通过构造函数传递私有类 |
| | | result[kvp.Key] = new ResourceReferenceDebug |
| | | { |
| | | CachedResource = kvp.Value.CachedResource, |
| | | BattlefieldOwners = kvp.Value.BattlefieldOwners |
| | | }; |
| | | } |
| | | return result; |
| | | } |
| | | |
| | | public static Dictionary<string, ResourceReferenceDebug> GetAudioCache() |
| | | { |
| | | var result = new Dictionary<string, ResourceReferenceDebug>(); |
| | | foreach (var kvp in globalAudioCache) |
| | | { |
| | | result[kvp.Key] = new ResourceReferenceDebug |
| | | { |
| | | CachedResource = kvp.Value.CachedResource, |
| | | BattlefieldOwners = kvp.Value.BattlefieldOwners |
| | | }; |
| | | } |
| | | return result; |
| | | } |
| | | |
| | | public static int GetTotalSpineCount() => globalSpineCache.Count; |
| | | public static int GetTotalAudioCount() => globalAudioCache.Count; |
| | | |
| | | public static HashSet<string> GetAllBattleGuids() |
| | | { |
| | | var guids = new HashSet<string>(); |
| | | foreach (var refInfo in globalSpineCache.Values) |
| | | { |
| | | foreach (var guid in refInfo.BattlefieldOwners.Keys) |
| | | { |
| | | guids.Add(guid); |
| | | } |
| | | } |
| | | foreach (var refInfo in globalAudioCache.Values) |
| | | { |
| | | foreach (var guid in refInfo.BattlefieldOwners.Keys) |
| | | { |
| | | guids.Add(guid); |
| | | } |
| | | } |
| | | return guids; |
| | | } |
| | | |
| | | public static void ClearAllCache() |
| | | { |
| | | globalSpineCache.Clear(); |
| | | globalAudioCache.Clear(); |
| | | Debug.Log("BattleCacheManager: All cache cleared (Editor only)"); |
| | | } |
| | | } |
| | | |
| | | // 资源引用视图类(供编辑器使用) |
| | | public class ResourceReferenceView |
| | | { |
| | | public string ResourceKey; |
| | | public string ResourcePath; |
| | | public bool IsLoaded; |
| | | public int TotalRefCount; |
| | | public Dictionary<string, int> BattlefieldRefCounts = new Dictionary<string, int>(); |
| | | |
| | | public ResourceReferenceView(string key, ResourceReferenceDebug refInfo) |
| | | { |
| | | ResourceKey = key; |
| | | ResourcePath = refInfo.CachedResource.Identifier.Directory + "/" + refInfo.CachedResource.Identifier.AssetName; |
| | | IsLoaded = refInfo.CachedResource.Asset != null; |
| | | TotalRefCount = refInfo.RefCount; |
| | | |
| | | foreach (var kvp in refInfo.BattlefieldOwners) |
| | | { |
| | | BattlefieldRefCounts[kvp.Key] = kvp.Value.Count; |
| | | } |
| | | } |
| | | } |
| | | #endif |
| | | } |