コード例 #1
0
 public void RemoveItem()
 {
     if (currentSelectedSlot)
     {
         var _item = currentSelectedSlot.item;
         if (ValidSlots[indexOfEquipedItem].item == _item)
         {
             lastEquipedItem = _item;
         }
         currentSelectedSlot.RemoveItem();
         onUnequipItem.Invoke(this, _item);
     }
 }
コード例 #2
0
 public void RemoveItem(EquipSlot slot)
 {
     if (slot)
     {
         Item item = slot.item;
         if (ValidSlots[indexOfEquipedItem].item == item)
         {
             lastEquipedItem = item;
         }
         slot.RemoveItem();
         onUnequipItem.Invoke(this, item);
     }
 }
コード例 #3
0
ファイル: Equipment.cs プロジェクト: barbafh3/RPGProto
    public override void UseItem(GameObject callingSlotObj)
    {
        var drop = callingSlotObj.GetComponent <DropItemHandler>();

        if (drop.slotType != type)
        {
            InventorySlot slot       = callingSlotObj.GetComponent <InventorySlot>();
            GameObject    weaponSlot = null;
            switch (type.typeName)
            {
            case "Weapon":
            {
                weaponSlot = GameObject.FindGameObjectWithTag("Weapon Slot");
                break;
            }

            case "Armor":
            {
                weaponSlot = GameObject.FindGameObjectWithTag("Armor Slot");
                break;
            }

            case "Helmet":
            {
                weaponSlot = GameObject.FindGameObjectWithTag("Helmet Slot");
                break;
            }
            }
            var weaponSlotScript = weaponSlot.GetComponent <EquipSlot>();

            weaponSlotScript.SwapItems(slot);
        }
        else
        {
            EquipSlot  slot           = callingSlotObj.GetComponent <EquipSlot>();
            List <int> availableSlots = CheckAvailableSlots(slot.itemList);
            var        targetSlot     = FindInventorySlotWithIndex(availableSlots[0]);

            var targetStack = targetSlot.itemStack;
            var localStack  = slot.itemStack;

            slot.itemList.AddAt(availableSlots[0], slot.itemStack);
            if (targetSlot != null)
            {
                targetSlot.RemoveItem();
                targetSlot.AddItem(localStack);
                slot.itemList.AddAt(targetSlot.itemIndex, localStack);
            }

            slot.RemoveItem();

            slot.itemList.itemEvent.Raise();

            if (targetStack != null)
            {
                slot.AddItem(targetStack);
                slot.equipment.AddAt(slot.itemIndex, targetStack);
            }

            if (slot.stackEvent != null)
            {
                slot.stackEvent.Raise();
            }

            slot.itemList.itemEvent.Raise();
            slot.equipment.itemEvent.Raise();
        }
    }