using UnityEngine;
using Spine.Unity;
using System.Collections.Generic;
///
/// 战斗资源缓存信息
///
public class BattleResCache
{
///
/// 资源标识符
///
public class ResourceIdentifier
{
public string Directory; // 资源目录
public string AssetName; // 资源名称
public ResourceType Type; // 资源类型
public bool IsPersistent; // 是否常驻(红队资源)
public string OwnerId; // 资源所有者ID (格式: HeroID_SkinID)
///
/// 获取资源唯一Key(目录+名称)
///
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;
}
}
///
/// 资源类型
///
public enum ResourceType
{
Spine, // Spine动画资源
Audio // 音频资源
}
///
/// 缓存的资源项
///
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;
}
///
/// 是否可以卸载(非常驻资源才能卸载)
///
public bool CanUnload()
{
return !IsPersistent;
}
///
/// 获取Spine资源
///
public SkeletonDataAsset GetSkeletonDataAsset()
{
return Asset as SkeletonDataAsset;
}
///
/// 获取音频资源
///
public AudioClip GetAudioClip()
{
return Asset as AudioClip;
}
}
}