public void SetAnimal(int id) { Icon = UITool.FindChild <Image>(gameObject, "Icon"); Name = UITool.FindChild <Text>(gameObject, "Name"); mPlayerStatus = GameObject.FindGameObjectWithTag("Player").GetComponent <PlayerStatus>(); ID = id; ItemPet = InventoryManager.Instance.GetItemById(ID) as ItemPet; Icon.sprite = Resources.Load <Sprite>(ItemPet.Sprite); Name.text = ItemPet.Name; }
void ParseItemJson() { itemList = new List <Item>(); TextAsset itemText = Resources.Load <TextAsset>("Json/ItemsInfo"); string itemsJson = itemText.text; JSONObject j = new JSONObject(itemsJson); foreach (JSONObject temp in j.list) { Item item = null; int id = (int)temp["id"].n; string name = temp["name"].str; string des = temp["des"].str; string sprite = temp["sprite"].str; int buyprice = (int)temp["buyPrice"].n; int sellprice = (int)temp["sellPrice"].n; int capacity = (int)temp["capacity"].n; string strtype = temp["type"].str; Item.ItemType type = (Item.ItemType)System.Enum.Parse(typeof(Item.ItemType), strtype); switch (type) { case Item.ItemType.Consumable: JSONObject j3 = temp["applyAttr"]; List <ApplyAttrEffect> applyAttrEffects2 = new List <ApplyAttrEffect>(); if (j3.type == JSONObject.Type.ARRAY) { foreach (JSONObject temp2 in j3.list) { ApplyAttrEffect applyAttrEffect = null; AttrType attrType = (AttrType)System.Enum.Parse(typeof(AttrType), temp2["attrTpye"].str); bool positive = temp2[1].b; int value = (int)temp2[2].n; applyAttrEffect = new ApplyAttrEffect(attrType, positive, value); applyAttrEffects2.Add(applyAttrEffect); } } else if (j3.type == JSONObject.Type.OBJECT) { ApplyAttrEffect applyAttrEffect = null; AttrType attrType = (AttrType)System.Enum.Parse(typeof(AttrType), j3["attrTpye"].str); bool positive = j3[1].b; int value = (int)j3[2].n; applyAttrEffect = new ApplyAttrEffect(attrType, positive, value); applyAttrEffects2.Add(applyAttrEffect); } item = new Consumable(id, name, des, sprite, buyprice, sellprice, capacity, type, applyAttrEffects2); break; case Item.ItemType.Equipment: string stret = temp["equipType"].str; Equipment.EquipType equipType = (Equipment.EquipType)System.Enum.Parse(typeof(Equipment.EquipType), stret); JSONObject j2 = temp["applyAttr"]; List <ApplyAttrEffect> applyAttrEffects = new List <ApplyAttrEffect>(); if (j2.type == JSONObject.Type.ARRAY) { foreach (JSONObject temp2 in j2.list) { ApplyAttrEffect applyAttrEffect = null; AttrType attrType = (AttrType)System.Enum.Parse(typeof(AttrType), temp2["attrTpye"].str); bool positive = temp2[1].b; int value = (int)temp2[2].n; applyAttrEffect = new ApplyAttrEffect(attrType, positive, value); applyAttrEffects.Add(applyAttrEffect); } } else if (j2.type == JSONObject.Type.OBJECT) { ApplyAttrEffect applyAttrEffect = null; AttrType attrType = (AttrType)System.Enum.Parse(typeof(AttrType), j2["attrTpye"].str); bool positive = j2[1].b; int value = (int)j2[2].n; applyAttrEffect = new ApplyAttrEffect(attrType, positive, value); applyAttrEffects.Add(applyAttrEffect); } item = new Equipment(id, name, des, sprite, buyprice, sellprice, capacity, type, equipType, applyAttrEffects); break; case Item.ItemType.Materials: item = new Materials(id, name, des, sprite, buyprice, sellprice, capacity, type); break; case Item.ItemType.OtherItem: OtherItem.OtherItemType otherItemType = (OtherItem.OtherItemType)System.Enum.Parse(typeof(OtherItem.OtherItemType), temp["othertype"].str); switch (otherItemType) { case OtherItem.OtherItemType.Seed: int maxgrow = (int)temp["maxgrow"].n; int daygrow = (int)temp["daygrow"].n; int productid = (int)temp["productid"].n; JSONObject j4 = temp["diffsprites"]; List <string> diffsprites = new List <string>(); for (int i = 0; i < j4.list.Count; i++) { string diffsprite = j4[i].str; diffsprites.Add(diffsprite); } item = new ItemSeed(id, name, des, sprite, buyprice, sellprice, capacity, type, otherItemType, maxgrow, daygrow, productid, diffsprites); break; case OtherItem.OtherItemType.Pet: int petid = (int)temp["petid"].n; item = new ItemPet(id, name, des, sprite, buyprice, sellprice, capacity, type, otherItemType, petid); break; } break; } itemList.Add(item); } }