yyl
2025-12-04 b0ee04e90107c110444e352b21002fa1bbc9ed34
125 战斗 新增预加载资源编辑器查看状态功能
1个文件已修改
113 ■■■■■ 已修改文件
Main/System/Battle/BattleResources/BattleCacheManager.cs 113 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
Main/System/Battle/BattleResources/BattleCacheManager.cs
@@ -259,4 +259,117 @@
        
        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
}