/// <summary> /// 使用成功的回调 /// </summary> /// <param name="composite">合成物的信息</param> public abstract void OnUsedSomething(RookiesGoods_Consumable consumable);
/// <summary> /// 初始化数据,读取xml和json,解析所有数据。 /// </summary> public void InitData() { IsSavingAfterQuit = false; PrototypeGoodsMenu = new Dictionary <int, RookiesGoods_GoodsBase>(); DurabilityID = new List <int>(); SpriteDic = new Dictionary <int, Sprite>(); PlayersData = new Dictionary <int, RookiesGoods_PlayerData>(); CompositeID = new List <int>(); XmlDocument xml = new XmlDocument(); xml.Load(Application.dataPath + "/RookiesGoods/Config/RookiesGoods_Config.xml"); XmlNodeList xmlNodeList = xml.SelectSingleNode("RookiesGoods_Config/JsonPath").ChildNodes; string path = xmlNodeList[0].InnerText; if (File.Exists(Application.dataPath + "/Resources/" + path + ".json")) { string classType, itemType, name, intro, effect, sprite; int id, maxNum, durability, length; int[] arrayValue; List <int> intListValue = new List <int>(); List <double> dbListValue = new List <double>(); List <string> strListValue = new List <string>(); TextAsset textAsset = Resources.Load(path) as TextAsset; JsonData jsonData = JsonMapper.ToObject(textAsset.text); foreach (JsonData data in jsonData) { JsonData stringValue = data["classType"]; JsonData intValue; JsonData arrayValues; JsonData propertyValue; classType = stringValue.ToString(); intValue = data["id"]; id = int.Parse(intValue.ToString()); intValue = data["maxNum"]; maxNum = int.Parse(intValue.ToString()); stringValue = data["itemType"]; itemType = stringValue.ToString(); stringValue = data["name"]; name = stringValue.ToString(); stringValue = data["intro"]; intro = stringValue.ToString(); stringValue = data["effect"]; effect = stringValue.ToString(); stringValue = data["spritePath"]; sprite = stringValue.ToString(); intValue = data["durability"]; durability = int.Parse(intValue.ToString()); arrayValues = data["compositeArray"]; if (sprite != "") { SpriteDic.Add(id, Resources.Load <Sprite>(sprite)); } switch (classType) { case "RookiesGoods_SuitBase": RookiesGoods_SuitBase suit; suit = new RookiesGoods_SuitBase(id, name, itemType, intro, effect, maxNum); suit.SetType(classType); length = arrayValues.Count; arrayValue = new int[length]; for (int i = 0; i < length; i++) { arrayValue[i] = int.Parse(arrayValues[i].ToString()); } if (length > 0) { CompositeID.Add(id); suit.UpdateComposite(arrayValue); } suit.Durability = durability; propertyValue = data["specialProperty"]; foreach (string key in propertyValue.Keys) { JsonData temp = propertyValue[key]; switch (temp.GetJsonType()) { case JsonType.None: break; case JsonType.Object: suit.AddProperty(key, temp); break; case JsonType.Array: length = temp.Count; intListValue.Clear(); strListValue.Clear(); dbListValue.Clear(); if (length > 0) { switch (temp[0].GetJsonType()) { case JsonType.Int: for (int i = 0; i < length; i++) { intListValue.Add(int.Parse(temp[i].ToString())); } suit.AddProperty(key, intListValue); break; case JsonType.String: for (int i = 0; i < length; i++) { strListValue.Add(temp[i].ToString()); } suit.AddProperty(key, strListValue); break; case JsonType.Double: for (int i = 0; i < length; i++) { dbListValue.Add(double.Parse(temp[i].ToString())); } suit.AddProperty(key, dbListValue); break; default: break; } } break; case JsonType.String: suit.AddProperty(key, temp.ToString()); break; case JsonType.Int: suit.AddProperty(key, int.Parse(temp.ToString())); break; case JsonType.Long: suit.AddProperty(key, long.Parse(temp.ToString())); break; case JsonType.Double: suit.AddProperty(key, double.Parse(temp.ToString())); break; case JsonType.Boolean: suit.AddProperty(key, bool.Parse(temp.ToString())); break; default: break; } } PrototypeGoodsMenu.Add(id, suit); break; case "RookiesGoods_Composite": RookiesGoods_Composite goods; goods = new RookiesGoods_Composite(id, name, itemType, intro, effect, maxNum); goods.SetType(classType); length = arrayValues.Count; arrayValue = new int[length]; for (int i = 0; i < length; i++) { arrayValue[i] = int.Parse(arrayValues[i].ToString()); } if (length > 0) { CompositeID.Add(id); goods.UpdateComposite(arrayValue); } propertyValue = data["specialProperty"]; foreach (string key in propertyValue.Keys) { JsonData temp = propertyValue[key]; switch (temp.GetJsonType()) { case JsonType.None: break; case JsonType.Object: goods.AddProperty(key, temp); break; case JsonType.Array: length = temp.Count; intListValue.Clear(); strListValue.Clear(); dbListValue.Clear(); if (length > 0) { switch (temp[0].GetJsonType()) { case JsonType.Int: for (int i = 0; i < length; i++) { intListValue.Add(int.Parse(temp[i].ToString())); } goods.AddProperty(key, intListValue); break; case JsonType.String: for (int i = 0; i < length; i++) { strListValue.Add(temp[i].ToString()); } goods.AddProperty(key, strListValue); break; case JsonType.Double: for (int i = 0; i < length; i++) { dbListValue.Add(double.Parse(temp[i].ToString())); } goods.AddProperty(key, dbListValue); break; default: break; } } break; case JsonType.String: goods.AddProperty(key, temp.ToString()); break; case JsonType.Int: goods.AddProperty(key, int.Parse(temp.ToString())); break; case JsonType.Long: goods.AddProperty(key, long.Parse(temp.ToString())); break; case JsonType.Double: goods.AddProperty(key, double.Parse(temp.ToString())); break; case JsonType.Boolean: goods.AddProperty(key, bool.Parse(temp.ToString())); break; default: break; } } PrototypeGoodsMenu.Add(id, goods); break; case "RookiesGoods_Consumable": RookiesGoods_Consumable consumable; consumable = new RookiesGoods_Consumable(id, name, itemType, intro, effect, maxNum); consumable.SetType(classType); length = arrayValues.Count; arrayValue = new int[length]; for (int i = 0; i < length; i++) { arrayValue[i] = int.Parse(arrayValues[i].ToString()); } if (length > 0) { CompositeID.Add(id); consumable.UpdateComposite(arrayValue); } propertyValue = data["specialProperty"]; foreach (string key in propertyValue.Keys) { JsonData temp = propertyValue[key]; switch (temp.GetJsonType()) { case JsonType.None: break; case JsonType.Object: consumable.AddProperty(key, temp); break; case JsonType.Array: length = temp.Count; intListValue.Clear(); strListValue.Clear(); dbListValue.Clear(); if (length > 0) { switch (temp[0].GetJsonType()) { case JsonType.Int: for (int i = 0; i < length; i++) { intListValue.Add(int.Parse(temp[i].ToString())); } consumable.AddProperty(key, intListValue); break; case JsonType.String: //if(IsInt(temp[0].ToString())) //{ // for (int i = 0; i < length; i++) // intListValue.Add(int.Parse(temp[i].ToString())); // consumable.AddProperty(key, intListValue); //} //else //{ for (int i = 0; i < length; i++) { strListValue.Add(temp[i].ToString()); } consumable.AddProperty(key, strListValue); // } break; case JsonType.Double: for (int i = 0; i < length; i++) { dbListValue.Add(double.Parse(temp[i].ToString())); } consumable.AddProperty(key, dbListValue); break; default: break; } } break; case JsonType.String: consumable.AddProperty(key, temp.ToString()); break; case JsonType.Int: consumable.AddProperty(key, int.Parse(temp.ToString())); break; case JsonType.Long: consumable.AddProperty(key, long.Parse(temp.ToString())); break; case JsonType.Double: consumable.AddProperty(key, double.Parse(temp.ToString())); break; case JsonType.Boolean: consumable.AddProperty(key, bool.Parse(temp.ToString())); break; default: break; } } PrototypeGoodsMenu.Add(id, consumable); break; default: throw new ArgumentException(string.Format("id {0}的框架类型错误", id)); } } } else { Debug.LogError("物品配置文件为空,插件将在你第一次存储物品信息时,自动生成配置文件。或者不使用插件直接编写。"); // throw new ArgumentException("丢失物品配置文件"); } }