124 lines
3.5 KiB
C#
124 lines
3.5 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
|
|
[CreateAssetMenu(fileName = "NewEquipmentTierNameConfig", menuName = "Equipment/Equipment Tier Name Config")]
|
|
public class equipmentTierNameConfigSO : ScriptableObject
|
|
{
|
|
[Serializable]
|
|
public class StagePresentation
|
|
{
|
|
public string tierName;
|
|
public Sprite equipmentSprite;
|
|
[TextArea(2, 6)] public string tierDescription;
|
|
}
|
|
|
|
[Serializable]
|
|
public class SkillTypePresentationSet
|
|
{
|
|
public equipmentSO.EquipmentSkillType skillType;
|
|
public StagePresentation[] stagePresentations = new StagePresentation[5];
|
|
|
|
public void EnsureFiveStages()
|
|
{
|
|
if (stagePresentations == null)
|
|
{
|
|
stagePresentations = new StagePresentation[5];
|
|
}
|
|
else if (stagePresentations.Length != 5)
|
|
{
|
|
Array.Resize(ref stagePresentations, 5);
|
|
}
|
|
|
|
for (int i = 0; i < stagePresentations.Length; i++)
|
|
{
|
|
if (stagePresentations[i] == null)
|
|
{
|
|
stagePresentations[i] = new StagePresentation();
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
[Header("按技能类型配置五阶段展示")]
|
|
public List<SkillTypePresentationSet> namingSets = new List<SkillTypePresentationSet>();
|
|
|
|
private void OnValidate()
|
|
{
|
|
EnsureAllSkillTypes();
|
|
}
|
|
|
|
public bool TryGetStagePresentation(equipmentSO.EquipmentSkillType skillType, int stageIndex, out StagePresentation presentation)
|
|
{
|
|
EnsureAllSkillTypes();
|
|
SkillTypePresentationSet set = FindSet(skillType);
|
|
if (set != null)
|
|
{
|
|
int clampedIndex = Mathf.Clamp(stageIndex, 0, 4);
|
|
presentation = set.stagePresentations[clampedIndex];
|
|
return presentation != null;
|
|
}
|
|
|
|
presentation = null;
|
|
return false;
|
|
}
|
|
|
|
public bool TryGetAllStagePresentations(equipmentSO.EquipmentSkillType skillType, out StagePresentation[] presentations)
|
|
{
|
|
EnsureAllSkillTypes();
|
|
SkillTypePresentationSet set = FindSet(skillType);
|
|
if (set != null)
|
|
{
|
|
presentations = set.stagePresentations;
|
|
return true;
|
|
}
|
|
|
|
presentations = null;
|
|
return false;
|
|
}
|
|
|
|
private void EnsureAllSkillTypes()
|
|
{
|
|
if (namingSets == null)
|
|
{
|
|
namingSets = new List<SkillTypePresentationSet>();
|
|
}
|
|
|
|
var normalized = new List<SkillTypePresentationSet>();
|
|
Array skillTypes = Enum.GetValues(typeof(equipmentSO.EquipmentSkillType));
|
|
|
|
for (int i = 0; i < skillTypes.Length; i++)
|
|
{
|
|
equipmentSO.EquipmentSkillType skillType = (equipmentSO.EquipmentSkillType)skillTypes.GetValue(i);
|
|
SkillTypePresentationSet set = FindSet(skillType);
|
|
if (set == null)
|
|
{
|
|
set = new SkillTypePresentationSet
|
|
{
|
|
skillType = skillType
|
|
};
|
|
}
|
|
|
|
set.skillType = skillType;
|
|
set.EnsureFiveStages();
|
|
normalized.Add(set);
|
|
}
|
|
|
|
namingSets = normalized;
|
|
}
|
|
|
|
private SkillTypePresentationSet FindSet(equipmentSO.EquipmentSkillType skillType)
|
|
{
|
|
for (int i = 0; i < namingSets.Count; i++)
|
|
{
|
|
SkillTypePresentationSet set = namingSets[i];
|
|
if (set != null && set.skillType == skillType)
|
|
{
|
|
return set;
|
|
}
|
|
}
|
|
|
|
return null;
|
|
}
|
|
}
|