yyl
2025-12-03 93cab33f292e99c81e738b2b6c58c7fa21a7f371
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
using UnityEngine;
using Spine.Unity;
using System.Collections.Generic;
 
/// <summary>
/// 战斗资源缓存信息
/// </summary>
public class BattleResCache
{
    /// <summary>
    /// 资源标识符
    /// </summary>
    public class ResourceIdentifier
    {
        public string Directory;      // 资源目录
        public string AssetName;      // 资源名称
        public ResourceType Type;     // 资源类型
        public bool IsPersistent;     // 是否常驻(红队资源)
        public string OwnerId;        // 资源所有者ID (格式: HeroID_SkinID)
        
        /// <summary>
        /// 获取资源唯一Key(目录+名称)
        /// </summary>
        public string GetKey()
        {
            return $"{Directory}/{AssetName}";
        }
        
        public override int GetHashCode()
        {
            return GetKey().GetHashCode();
        }
        
        public override bool Equals(object obj)
        {
            if (obj is ResourceIdentifier other)
            {
                return GetKey() == other.GetKey();
            }
            return false;
        }
    }
    
    /// <summary>
    /// 资源类型
    /// </summary>
    public enum ResourceType
    {
        Spine,      // Spine动画资源
        Audio       // 音频资源
    }
    
    /// <summary>
    /// 缓存的资源项
    /// </summary>
    public class CachedResource
    {
        public ResourceIdentifier Identifier;
        public Object Asset;              // UnityEngine.Object
        public bool IsPersistent;         // 是否常驻
        
        public CachedResource(ResourceIdentifier identifier, Object asset, bool isPersistent)
        {
            Identifier = identifier;
            Asset = asset;
            IsPersistent = isPersistent;
        }
        
        /// <summary>
        /// 是否可以卸载(非常驻资源才能卸载)
        /// </summary>
        public bool CanUnload()
        {
            return !IsPersistent;
        }
        
        /// <summary>
        /// 获取Spine资源
        /// </summary>
        public SkeletonDataAsset GetSkeletonDataAsset()
        {
            return Asset as SkeletonDataAsset;
        }
        
        /// <summary>
        /// 获取音频资源
        /// </summary>
        public AudioClip GetAudioClip()
        {
            return Asset as AudioClip;
        }
    }
}