上期工程设计好了技能的信息,根数技能文本,需要4个枚举来规范技能的筛选,其中包括 SkillEffectType、SkillPropertyType、SkillUser及SkillTargetType。思路类似于将物品信息读取至内存中一样,脚本如下:
public enum SkillEffectType{SingleTarget,MultiTarget,Buff,Passive}
public enum SkillPropertyType{Attack,Def,AttackSpeed,HP,MP}
public enum SkillUser{Swordman,Magician}
public enum SkillTargetType{Self,Enemy,Position}
public Class SkillInfo
{
public int id;
public string name;
public string icon_name;
public string des;
public SkillEffectType effectType;
public SkillPropertyType propertyType;
public int skilleffect;
public int lastTime;
public int MPSpend;
public int coldTime;
public SkillUser skillUser;
public int needLevel;
public SkillTargetType skillTargetType;
public float distance;
}
public Class SkillsInfo
{
public static SkillsInfo _instance;
private Dictionary dictionary;
public TextAsset skillText;
void Awake( )
{
_instance = this;
ReadSkill( );
}
public SkillInfo GetSkillInfoById(int id)
{
SkillInfo info = null;
dictionary.TryGetValue(id, out info);
return info;
}
void ReadSkill( )
{
string text_pre = skillText.text;
string[ ] text_pre1 = text_pre.Split('\n');
foreach( string pa in text_pre1)
{
SkillInfo info = new SkillInfo( );
info.id = int.Parse(pa[0]);
info.name = pa[1];
info.icon_name = pa[2];
info.des = pa[3];
string str_effect = pa[4];
switch(str_effect)
{
case "SingleTarget"
info.skillEffectType = SkillEffectType.SingleTarget;
break;
case "MultiTarget"
info.skillEffectType = SkillEffectType.MultiTarget;
break;
case "Buff"
info.skillEffectType = SkillEffectType.Buff;
break;
case "Passive"
info.skillEffectType = SkillEffectType.Passive;
break;
}
string str_property = pa[5];
swtich(str_property)
{
case "Attack":
info.skillPropertyType = SkillPropertyType.Attack;
break;
case "Def":
info.skillPropertyType = SkillPropertyType.Def;
break;
case "AttackSpeed":
info.skillPropertyType = SkillPropertyType.AttackSpeed;
break;
case "HP":
info.skillPropertyType = SkillPropertyType.HP;
break;
case "MP":
info.skillPropertyType = SkillPropertyType.MP;
break;
}
info.skilleffect = int.Parse(pa[6]);
info.lastTime = int.Parse(pa[7]);
info.MPSpend = int.Parse(pa[8]);
info.coldTime = int.Parse(pa[9]);
}
string str_user = pa[10];
switch(str_user)
{
case "Swordman":
info.skillUser = SkillType.Swordman;
break;
case "Magician":
info.skillUser = SkillType.Magician;
break;
}
info.needLevel = int.Parse(pa[11]);
string str_target = pa[12];
switch(str_target)
{
case "Enemy":
info.skillTargetType = SkillTargetType.Enemy;
break;
case "Self":
info.skillTargetType = SkillTargetType.Self;
break;
case "Position":
info.skillTargetType = SkillTargetType.Position;
break;
}
info.position = float.Parse(pa[13]);
dictionary.Add(info.id,info);
}
}
这样就实现了技能信息读取至内存了。