Files

81 lines
2.3 KiB
C#
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
using System.Collections.Generic;
using UnityEngine;
namespace TcgEngine
{
[CreateAssetMenu(fileName = "NewRankMedalData", menuName = "TcgEngine/Rank/RankMedalData", order = 5)]
public class RankMedalData : ScriptableObject
{
public string medalName;
public Sprite sprite;
public string icon_url;
private static List<RankMedalData> medalList = new List<RankMedalData>();
/// <summary>
/// 从 Resources 目录加载所有 RankIconData
/// </summary>
public static void Load(string folder = "")
{
if (medalList.Count == 0)
{
medalList.AddRange(Resources.LoadAll<RankMedalData>(folder));
}
}
/// <summary>
/// 获取所有奖牌配置
/// </summary>
public static List<RankMedalData> GetAll()
{
return medalList;
}
/// <summary>
/// 根据奖牌名称查找
/// </summary>
public static RankMedalData Get(string name)
{
foreach (RankMedalData item in medalList)
{
if (item.medalName == name)
return item;
}
return null;
}
/// <summary>
/// 获取奖牌 Sprite优先走网络路径需要配合 SpriteLoader
/// </summary>
public Sprite GetIcon()
{
Sprite result = null;
if (!string.IsNullOrEmpty(icon_url))
{
result = SpriteLoader.Get()?.LoadSprite(icon_url);
if (result != null)
{
return result;
}
if (sprite != null)
{
Debug.LogWarning($"奖牌 {medalName} -- 动态加载失败使用静态Sprite -- {icon_url}");
return sprite;
}
Debug.LogError($"奖牌 {medalName} -- 动态路径无效且没有静态Sprite -- {icon_url}");
return null;
}
else
{
Debug.LogWarning($"奖牌 {medalName} 未配置网络路径使用静态Sprite");
return sprite;
}
}
}
}