private void UpdateShuxingText()
    {
        int strength = 0, intellect = 0, agility = 0, stamina = 0, damage = 0;

        foreach (JiaoseWupin wupin in wupinList)
        {
            if (wupin.transform.childCount > 0)
            {
                Item item = wupin.transform.GetChild(0).GetComponent <ItemUI>().Item;
                if (item is Zhuangbei)
                {
                    Zhuangbei e = (Zhuangbei)item;
                    strength  += e.Strength;
                    intellect += e.Intellect;
                    agility   += e.Agility;
                    stamina   += e.Stamina;
                }
                else if (item is Wuqi)
                {
                    damage += ((Wuqi)item).Damage;
                }
            }
        }
        strength  += player.BasicStrength;
        intellect += player.BasicIntellect;
        agility   += player.BasicAgility;
        stamina   += player.BasicStamina;
        damage    += player.BasicDamage;
        string text = string.Format("力量:{0}\n智力:{1}\n敏捷:{2}\n体力:{3}\n攻击力:{4}", strength, intellect, agility, stamina, damage);

        shuxingText.text = text;
    }
Beispiel #2
0
 public bool zhuangbei(Zhuangbei zhuangbei)
 {
     AuM.playAudio("daoju");
     HA._gongji   += zhuangbei.gongji;
     HA._fangyu   += zhuangbei.fangyu;
     UM.tipContent = zhuangbei.tip;
     UM.tipTime    = 3f;
     AnimateGameobject(zhuangbei.gameObject);
     return(true);
 }
    //解析物品信息
    void ParseItemJson()
    {
        itemList = new List <Item>();
        //文本在Unity里面是TextAsset类型
        TextAsset  itemText  = Resources.Load <TextAsset>("Items");
        string     itemsJson = itemText.text;//物品信息的Json格式
        JSONObject j         = new JSONObject(itemsJson);

        foreach (JSONObject temp in j.list)
        {
            string        typeStr = temp["type"].str;
            Item.ItemType type    = (Item.ItemType)System.Enum.Parse(typeof(Item.ItemType), typeStr);

            //下面的是解析这个对象里面的公有属性
            int              id        = (int)(temp["id"].n);
            string           name      = temp["name"].str;
            Item.ItemQuality quality   = (Item.ItemQuality)System.Enum.Parse(typeof(Item.ItemQuality), temp["quality"].str);
            string           des       = temp["des"].str;
            int              capacity  = (int)(temp["capacity"].n);
            int              buyPrice  = (int)(temp["buyPrice"].n);
            int              sellPrice = (int)(temp["sellPrice"].n);
            string           sprite    = temp["sprite"].str;

            Item item = null;
            switch (type)
            {
            case Item.ItemType.Xiaohaopin:
                int hp = (int)(temp["hp"].n);
                int mp = (int)(temp["mp"].n);
                item = new Xiaohaopin(id, name, type, quality, des, capacity, buyPrice, sellPrice, sprite, hp, mp);
                break;

            case Item.ItemType.Zhuangbei:
                int strength  = (int)temp["strength"].n;
                int intellect = (int)temp["intellect"].n;
                int agility   = (int)temp["agility"].n;
                int stamina   = (int)temp["stamina"].n;
                Zhuangbei.ZhuangbeiType zbType = (Zhuangbei.ZhuangbeiType)System.Enum.Parse(typeof(Zhuangbei.ZhuangbeiType), temp["zbType"].str);
                item = new Zhuangbei(id, name, type, quality, des, capacity, buyPrice, sellPrice, sprite, strength, intellect, agility, stamina, zbType);
                break;

            case Item.ItemType.Wuqi:
                int           damage = (int)temp["damage"].n;
                Wuqi.WuqiType wqType = (Wuqi.WuqiType)System.Enum.Parse(typeof(Wuqi.WuqiType), temp["wqType"].str);
                item = new Wuqi(id, name, type, quality, des, capacity, buyPrice, sellPrice, sprite, damage, wqType);
                break;

            case Item.ItemType.Cailiao:
                item = new Cailiao(id, name, type, quality, des, capacity, buyPrice, sellPrice, sprite);
                break;
            }
            itemList.Add(item);
            Debug.Log(item);
        }
    }