Exemple #1
0
 public TurnAction(GameObject active_Ship, GameObject target_Ship, _Equipment a_equip)
 {
     c_Ship   = active_Ship;
     t_Ship   = target_Ship;
     c_Equ    = a_equip;
     c_Action = action_Type.Equipment;
 }
 void SetEquipmentBlendShapes(_Equipment item, int weight)
 {
     foreach (_EquipmentMeshRegion blendShape in item.equipmentMeshRegion)
     {
         targetMesh.SetBlendShapeWeight((int)blendShape, weight);
     }
 }
    public void Equip(_Equipment newItem)
    {
        int        index   = (int)newItem.equipmentSlot;
        _Equipment oldItem = Unequip(index);

        if (currentEquipments[index] != null)
        {
            oldItem = currentEquipments [index];
            inventory.Add(oldItem);
        }

        if (onEquipmentChanged != null)
        {
            onEquipmentChanged.Invoke(newItem, oldItem);
        }

        SetEquipmentBlendShapes(newItem, 100);
        currentEquipments [index] = newItem;
        SkinnedMeshRenderer newMesh = Instantiate <SkinnedMeshRenderer> (newItem.mesh);

        newMesh.transform.parent = targetMesh.transform;
        newMesh.bones            = targetMesh.bones;
        newMesh.rootBone         = targetMesh.rootBone;
        currentMeshs [index]     = newMesh;
    }
Exemple #4
0
    void OnEquipmentChanged(_Equipment newItem, _Equipment oldItem)
    {
        if (newItem != null && newItem.equipmentSlot == _EquipmentSlot.Weapon)
        {
            animator.SetLayerWeight(1, 1);
            if (weaponAnimationsDict.ContainsKey(newItem))
            {
                currentAnimSet = weaponAnimationsDict [newItem];
            }
        }
        else if (newItem == null && oldItem.equipmentSlot == _EquipmentSlot.Weapon)
        {
            animator.SetLayerWeight(1, 0);
            currentAnimSet = defaultAttackAnimSet;
        }

        if (newItem != null && newItem.equipmentSlot == _EquipmentSlot.Shield)
        {
            animator.SetLayerWeight(2, 1);
            currentAnimSet = defaultAttackAnimSet;
        }
        else if (newItem == null && oldItem.equipmentSlot == _EquipmentSlot.Shield)
        {
            animator.SetLayerWeight(2, 0);
        }
    }
    //更新角色属性显示
    private void UpdatePropertyText()
    {
        int strength = 0, intellect = 0, agility = 0, stamina = 0, damage = 0;

        foreach (_EquipmentSlot slot in slotArray) //遍历角色面板中的装备物品槽
        {
            if (slot.transform.childCount > 0)     //找到有物品的物品槽,获取里面装备的属性值
            {
                _Item item = slot.transform.GetChild(0).GetComponent <_ItemUI>().Item;
                if (item is _Equipment)//如果物品是装备,那就加角色对应的属性
                {
                    _Equipment e = (_Equipment)item;
                    strength  += e.Strength;
                    intellect += e.Intellect;
                    agility   += e.Agility;
                    stamina   += e.Stamina;
                }
                else if (item is _Weapon)///如果物品是武器,那就加角色的伤害(damage)属性
                {
                    _Weapon w = (_Weapon)item;
                    damage += w.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}\n", strength, intellect, agility, stamina, damage);

        characterPropertyText.text = text;
    }
    /// <summary>
    /// 解析Json文件
    /// </summary>
    public void ParseItemJson()
    {
        itemList = new List <_Item>();
        //文本在unity里面是TextAsset类型
        TextAsset itemText = Resources.Load <TextAsset>("_ItemJS"); //加载json文本

        string itemJson = itemText.text;                            //得到json文本里面的内容
        //Debug.Log(itemJson);
        JsonData data = JsonMapper.ToObject(itemJson);

        for (int i = 0; i < data.Count; i++)
        {
            int               id          = (int)data[i]["id"];
            string            name        = (string)data[i]["name"];
            _Item.ItemType    type        = (_Item.ItemType)System.Enum.Parse(typeof(_Item.ItemType), (string)data[i]["type"]);
            _Item.ItemQuality quality     = (_Item.ItemQuality)System.Enum.Parse(typeof(_Item.ItemQuality), (string)data[i]["quality"]);
            string            description = (string)data[i]["description"];
            int               capacity    = (int)data[i]["capacity"];
            int               buyPrice    = (int)data[i]["buyPrice"];
            int               sellPrice   = (int)data[i]["sellPrice"];
            string            sprite      = (string)data[i]["sprite"];
            _Item             item        = null;
            switch (type)
            {
            case _Item.ItemType.Consumable:
                int hp = (int)data[i]["hp"];
                int mp = (int)data[i]["mp"];
                item = new _Consumable(id, name, type, quality, description, capacity, buyPrice, sellPrice, sprite, hp, mp);
                break;

            case _Item.ItemType.Equipment:
                int strength  = (int)data[i]["strength"];
                int intellect = (int)data[i]["intellect"];
                int agility   = (int)data[i]["agility"];
                int stamina   = (int)data[i]["stamina"];
                _Equipment.EquipmentType equipType = (_Equipment.EquipmentType)System.Enum.Parse(typeof(_Equipment.EquipmentType), (string)data[i]["equipType"]);
                item = new _Equipment(id, name, type, quality, description, capacity, buyPrice, sellPrice, sprite, strength, intellect, agility, stamina, equipType);
                break;

            case _Item.ItemType.Weapon:
                int damage = (int)data[i]["damage"];
                _Weapon.WeaponType weaponType = (_Weapon.WeaponType)System.Enum.Parse(typeof(_Weapon.WeaponType), (string)data[i]["weaponType"]);
                item = new _Weapon(id, name, type, quality, description, capacity, buyPrice, sellPrice, sprite, damage, weaponType);
                break;

            case _Item.ItemType.Material:
                item = new _Material(id, name, type, quality, description, capacity, buyPrice, sellPrice, sprite);
                break;
            }

            itemList.Add(item);
        }
        //Debug.Log(item);
    }
Exemple #7
0
    void OnEquipmentChanged(_Equipment newItem, _Equipment oldItem)
    {
        if (newItem != null)
        {
            damage.AddModifier(newItem.damageModifier);
            armor.AddModifier(newItem.armorModifier);
        }

        if (oldItem != null)
        {
            damage.RemoveModifier(oldItem.damageModifier);
            armor.RemoveModifier(oldItem.armorModifier);
        }
    }
    public _Equipment Unequip(int index)
    {
        if (currentEquipments [index] != null)
        {
            if (currentMeshs [index] != null)
            {
                Destroy(currentMeshs [index].gameObject);
            }
            _Equipment oldItem = currentEquipments [index];
            Destroy(currentMeshs [index].gameObject);
            currentEquipments [index] = null;
            SetEquipmentBlendShapes(oldItem, 0);
            inventory.Add(oldItem);

            if (onEquipmentChanged != null)
            {
                onEquipmentChanged.Invoke(null, oldItem);
            }
            return(oldItem);
        }
        return(null);
    }