Files

111 lines
3.2 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;
using System.Collections.Generic;
using UnityEngine;
namespace TcgEngine
{
[CreateAssetMenu(fileName = "NewRankingData", menuName = "TcgEngine/Rank/RankingData", order = 5)]
public class RankingData :ScriptableObject
{
public string rankName = "青铜";
public PlayerRank rank;
public Sprite rankIcon;
public string rank_img_path;
public static List<RankingData> rank_lisk = new List<RankingData>();
public static void Load(string folder="")
{
if (rank_lisk.Count == 0)
{
rank_lisk.AddRange(Resources.LoadAll<RankingData>(folder));
}
rank_lisk.Sort((a, b) => a.rank.CompareTo(b.rank));
}
/// <summary>
/// 获取Rank图片优先使用动态路径
/// </summary>
public Sprite GetRankImage()
{
Sprite sprite = null;
if (!string.IsNullOrEmpty(rank_img_path))
{
sprite = SpriteLoader.Get()?.LoadSprite(rank_img_path);
if (sprite != null)
{
return sprite;
}
if (rankIcon != null)
{
Debug.LogWarning($"Rank {rankName} -- 动态加载失败使用静态Icon -- {rank_img_path}");
return rankIcon;
}
Debug.LogError($"Rank {rankName} -- 动态路径无效且没有静态Icon -- {rank_img_path}");
return null;
}
else
{
Debug.LogWarning($"Rank {rankName} 段位路径为空使用静态Icon");
return rankIcon;
}
}
public static RankingData Get(PlayerRank pRank)
{
foreach (RankingData item in GetAll())
{
if (item.rank == pRank)
{
return item;
}
}
return null;
}
public static List<RankingData> GetAllAvailable()
{
List<RankingData> validList = new List<RankingData>();
foreach (RankingData item in GetAll())
{
if (!string.IsNullOrEmpty(item.rank_img_path) || item.rankIcon != null)
{
validList.Add(item);
}
}
return validList;
}
public static List<RankingData> GetAll()
{
return rank_lisk;
}
// 当 Inspector 值发生改变时自动调用
private void OnValidate()
{
Dictionary<PlayerRank, string> rankNames = new Dictionary<PlayerRank, string>()
{
{ PlayerRank.Bronze, "青铜" },
{ PlayerRank.Silver, "白银" },
{ PlayerRank.Gold, "黄金" },
{ PlayerRank.Platinum, "铂金" },
{ PlayerRank.Diamond, "钻石" },
{ PlayerRank.King, "王者" }
};
if(rankNames.ContainsKey(rank))
rankName = rankNames[rank];
}
}
}