59 lines
1.5 KiB
C#
59 lines
1.5 KiB
C#
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
|
|
namespace TcgEngine
|
|
{
|
|
[CreateAssetMenu(fileName = "CardCover", menuName = "TcgEngine/CardCover", order = 10)]
|
|
public class CardCoverData : ScriptableObject
|
|
{
|
|
public string id;
|
|
public string name;
|
|
public string cardCoverPath;
|
|
|
|
private static List<CardCoverData> _cardCoverList = new List<CardCoverData>();
|
|
|
|
public static void Load(string folder = "")
|
|
{
|
|
if (_cardCoverList.Count==0)
|
|
_cardCoverList.AddRange(Resources.LoadAll<CardCoverData>(folder));
|
|
}
|
|
|
|
public Sprite GetCardCover()
|
|
{
|
|
if (_cardCoverList.Count == 0)
|
|
Load();
|
|
|
|
if (!string.IsNullOrEmpty(cardCoverPath))
|
|
{
|
|
Sprite dynamicSprite = SpriteLoader.Get()?.LoadSprite(cardCoverPath);
|
|
if (dynamicSprite != null)
|
|
return dynamicSprite;
|
|
}
|
|
else
|
|
{
|
|
Debug.LogWarning("卡组封面地址为空!");
|
|
}
|
|
return null;
|
|
}
|
|
|
|
public static CardCoverData Get(string id)
|
|
{
|
|
foreach (CardCoverData cardCover in GetAll())
|
|
{
|
|
if (cardCover.id == id)
|
|
{
|
|
return cardCover;
|
|
}
|
|
}
|
|
|
|
return null;
|
|
}
|
|
|
|
public static List<CardCoverData> GetAll()
|
|
{
|
|
return _cardCoverList;
|
|
}
|
|
|
|
}
|
|
}
|