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;
|
}
|
}
|
}
|