59 lines
1.6 KiB
C#
59 lines
1.6 KiB
C#
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
|
|
namespace TcgEngine
|
|
{
|
|
[CreateAssetMenu(fileName = "CardCover", menuName = "TcgEngine/CardCover", order = 10)]
|
|
public class CardCoverData : ScriptableObject
|
|
{
|
|
public int 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));
|
|
// 直接按照 int id 排序
|
|
_cardCoverList.Sort((a, b) => a.id.CompareTo(b.id));
|
|
}
|
|
|
|
|
|
public Sprite GetCardCover()
|
|
{
|
|
if (!string.IsNullOrEmpty(cardCoverPath))
|
|
{
|
|
Sprite dynamicSprite = SpriteLoader.Get()?.LoadSprite(cardCoverPath+".png");
|
|
// Debug.Log(cardCoverPath+".png");
|
|
if (dynamicSprite != null)
|
|
return dynamicSprite;
|
|
}
|
|
else
|
|
{
|
|
Debug.LogWarning("卡组封面地址为空!");
|
|
}
|
|
return null;
|
|
}
|
|
|
|
public static CardCoverData Get(string name)
|
|
{
|
|
foreach (CardCoverData cardCover in GetAll())
|
|
{
|
|
if (cardCover.name == name)
|
|
{
|
|
return cardCover;
|
|
}
|
|
}
|
|
return null;
|
|
}
|
|
|
|
public static List<CardCoverData> GetAll()
|
|
{
|
|
return _cardCoverList;
|
|
}
|
|
|
|
}
|
|
}
|