using System; using GeometryTD.Definition; using GeometryTD.CustomUtility; using UnityGameFramework.Runtime; namespace GeometryTD.DataTable { /// /// 底座组件表 /// public class DRBaseComp : DataRowBase { private int m_Id = 0; /// /// 获取底座组件编号 /// public override int Id => m_Id; /// /// 获取底座组件名 /// public string Name { get; private set; } /// /// 获取底座组件攻击速度数组(秒/次) /// public float[] AttackSpeed { get; private set; } /// /// 获取底座组件每级提升攻击速度(值为负数) /// public float AttackSpeedPerLevel { get; private set; } /// /// 获取攻击属性 /// public AttackPropertyType AttackPropertyType { get; private set; } /// /// 获取属性约束 /// public string Constraint { get; private set; } /// /// 获取可能出现的 Tag /// public TagType[] PossibleTag { get; private set; } public override bool ParseDataRow(string dataRowString, object userData) { string[] columnStrings = dataRowString.Split(DataTableExtension.DataSplitSeparators); for (int i = 0; i < columnStrings.Length; i++) { columnStrings[i] = columnStrings[i].Trim(DataTableExtension.DataTrimSeparators); } int index = 0; index++; m_Id = int.Parse(columnStrings[index++]); index++; Name = columnStrings[index++]; AttackSpeed = GenerateAttackSpeed(columnStrings[index++]); AttackSpeedPerLevel = float.Parse(columnStrings[index++]); AttackPropertyType = EnumUtility.Get(columnStrings[index++]); Constraint = columnStrings[index++]; PossibleTag = GeneratePossibleTag(columnStrings[index++]); return true; } private float[] GenerateAttackSpeed(string raw) { if (!raw.StartsWith('[') || !raw.EndsWith(']')) { throw new ArgumentException("Input must be enclosed in square brackets."); } if (raw.Length == 2) return new float[] { }; string[] attackSpeedRaws = raw.Substring(1, raw.Length - 2).Split(","); int length = attackSpeedRaws.Length; var attackSpeed = new float[length]; for (int i = 0; i < length; i++) { attackSpeed[i] = float.Parse(attackSpeedRaws[i]); } return attackSpeed; } private TagType[] GeneratePossibleTag(string raw) { if (!raw.StartsWith('[') || !raw.EndsWith(']')) { throw new ArgumentException("Input must be enclosed in square brackets."); } if (raw.Length == 2) return new TagType[] { }; string[] tagTypes = raw.Substring(1, raw.Length - 2).Split(","); int length = tagTypes.Length; var tags = new TagType[length]; for (int i = 0; i < length; i++) { tags[i] = EnumUtility.Get(tagTypes[i]); } return tags; } } }