2025-12-09 17:22:44 +08:00

155 lines
4.4 KiB
C#
Raw 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;
using System.Collections.Generic;
using UnityEngine;
using RuntimeData;
using Logic.Multilingual;
using TH1_Core.Managers;
using UnityEngine.UI;
public enum SkillViewType
{
Normal,
Special,
Unique,
Negative,
Positive,
Max
}
[Serializable]
public struct SkillViewTypeColor
{
public SkillViewType SkillViewType;
public Color Color;
}
[Serializable]
[CreateAssetMenu(fileName = "SkillDataAssets", menuName = "TH1 Game Data/Skill Data Asset")]
public class SkillDataAssets : ScriptableObject
{
public List<SkillInfo> SkillInfoList = new List<SkillInfo>();
public List<SkillViewTypeColor> SkillViewTypeColorList = new List<SkillViewTypeColor>();
private Dictionary<SkillType,SkillInfo> _skillDict = new Dictionary<SkillType, SkillInfo>();
[NonSerialized]
private bool _initialized = false;
private void Init()
{
if (_initialized)
return;
foreach(var t in SkillInfoList)
_skillDict[t.SkillType] = t;
_initialized = true;
}
public bool GetSkillInfo(SkillType skill, out SkillInfo skillInfo)
{
Init();
return _skillDict.TryGetValue(skill,out skillInfo);
}
//根据unitTypeKey决定skill显示为什么
public bool GetSkillNameAndDesc(SkillType skill,UnitFullType key,out String skillName, out String skillDesc)
{
Init();
skillDesc = "";
skillName = "";
bool ret = _skillDict.TryGetValue(skill,out var skillInfo);
if (!ret) return false;
//如果没有SkillShowList
if (!skillInfo.HasShowList)
{
//Debug.Log($"has show list for {skill}");
skillDesc = skillInfo.SkillDesc;
skillName = skillInfo.SkillName;
return true;
}
//如果有ShowList根据key来判断选谁都选不到则采用基础SkillDesc
foreach (var t in skillInfo.SkillShowList)
{
if (key.UnitType == t.UnitType
&& (t.IgnoreUnitGiantType || key.GiantType == t.GiantType)
&& (t.IgnoreUnitLevel || key.UnitLevel == t.UnitLevel))
{
skillDesc = t.SkillDesc;
skillName = t.SkillName;
return true;
}
}
skillDesc = skillInfo.SkillDesc;
skillName = skillInfo.SkillName;
return true;
}
public bool GetSkillIcon(SkillType skill,UnitFullType key,out Sprite skillIcon)
{
Init();
skillIcon = null;
bool ret = _skillDict.TryGetValue(skill,out var skillInfo);
if (!ret) return false;
skillIcon = skillInfo.SkillIcon;
//如果没有SkillShowList
if (!skillInfo.HasShowList) return true;
//如果有ShowList根据key来判断选谁都选不到则采用基础SkillDesc
foreach (var t in skillInfo.SkillShowList)
{
if (key.UnitType == t.UnitType
&& (t.IgnoreUnitGiantType || key.GiantType == t.GiantType)
&& (t.IgnoreUnitLevel || key.UnitLevel == t.UnitLevel))
{
if(t.Icon != null)
skillIcon = t.Icon;
return true;
}
}
return true;
}
public Color GetBGColor(SkillViewType skillViewType,bool HasTimeLimit)
{
if (HasTimeLimit && skillViewType != SkillViewType.Negative)
skillViewType = SkillViewType.Positive;
foreach (var t in SkillViewTypeColorList)
if (t.SkillViewType == skillViewType)
return t.Color;
return Color.black;
}
}
[Serializable]
public class SkillInfo
{
public SkillType SkillType;
public SkillViewType SkillViewType;
[MultilingualField]
public string SkillName;
[MultilingualField]
public string SkillDesc;
public bool NotShow;
public Sprite SkillIcon;
//根据不同的unittype对象呈现不同的图标&说明
public bool HasShowList;
public List<SkillInfoShowPack> SkillShowList;
}
[Serializable]
public class SkillInfoShowPack
{
public UnitFullType UnitFullType;
public UnitType UnitType;
public GiantType GiantType;
public uint UnitLevel;
public bool IgnoreUnitGiantType;
public bool IgnoreUnitLevel;
public Sprite Icon;
[MultilingualField]
public string SkillDesc;
[MultilingualField]
public string SkillName;
}