数组越界,
1001,小瓶血药,icon1,Drug,50,0,80,100
1002,大瓶血药,icon2,Drug,100,0,180,200
1003,蓝药,icon3,Drug,0,100,150,180
string icon_name = proArray[2];//這里报数组越界
string text = objectInfoText.text;
string[] strArray = text.Split('\n');
foreach (string str in strArray)
{
string[] proArray = str.Split(',');
ObjectInfo info = new ObjectInfo();
int id = int.Parse(proArray[0]);
string name = proArray[1];
string icon_name = proArray[2];//這里报数组越界
string str_type = proArray[3];
ObjectType type = ObjectType.Drug;
switch (str_type)
{ case "Drug":
type = ObjectType.Drug;
break;
case "Equip":
type = ObjectType.Equip; break;
case "Mat":
type = ObjectType.Mat; break;
}
info.id = id; info.name = name; info.icon_name = icon_name; info.type = type;
if (type==ObjectType.Drug)
{ int hp = int.Parse(proArray[4]);
int mp = int.Parse(proArray[5]);
int price_sell = int.Parse(proArray[6]);
int price_buy = int.Parse(proArray[7]);
info.hp = hp; info.mp = mp; info.price_buy = price_buy; info.price_sell = price_sell; }
objectInfoDic.Add(id,info);
}
}
1001,小瓶血药,icon1,Drug,50,0,80,100
1002,大瓶血药,icon2,Drug,100,0,180,200
1003,蓝药,icon3,Drug,0,100,150,180
你的数据是有问题的,里面有的是英文逗号,有的是中文逗号, 保持逗号的统一,统一使用英文逗号