Esempio n. 1
0
        public void OnPointerUp(PointerEventData data)
        {
            // IF we Right Click so we can USE or EQUIP an item.
            if (item != null && data.button == PointerEventData.InputButton.Right && !data.dragging)
            {
                // Get the Player_Manager component.
                Player_Manager player = Character_Manager.GetPlayerManager().GetComponent <Player_Manager> ();
                // IF this item is a consumable,
                if (item.Type == "Consumable")
                {
                    // Add "usage" attributes associated with this item.  At this current time if you are looking at the demo we only add HP.
                    player.AddHealth((float)item.RestoreHP);
                    // Play the Pickup Sound.
                    Grid.soundManager.PlaySound(item.UsedSound);
                    if (amount - 1 == 0)
                    {
                        // Clear the old slot.
                        GetComponentInParent <Inventory>().items [slotNumber] = new Item();
                        // Destroy this gameobject as it holds no item.
                        Destroy(gameObject);
                        // Do not show the tooltip.
                        Grid.tooltip.Deactivate();
                        return;
                    }
                    --amount;
                    GetComponentInParent <Inventory>().slots [slotNumber].GetComponentInChildren <Text> ().text = amount.ToString();
                    return;
                }
                // IF this item is a piece of equipment, such as a Weapon, Armour, Ring or a Bracelet.
                if (item.Type == "Weapon" || item.Type == "Armour" || item.Type == "Ring" || item.Type == "Bracelet")
                {
                    // Get the Equipment component.
                    Equipment equipment = player.GetComponentInChildren <Equipment> ();
                    // Play the Pickup Sound.
                    Grid.soundManager.PlaySound(item.UsedSound);
                    Item swappedItem = null;
                    if (item.Type == "Weapon")
                    {
                        // Set the new weapon to the player while returning the old weapon (if the player wielded one).
                        swappedItem = equipment.EquipWeapon(item);
                    }
                    else if (item.Type == "Armour")
                    {
                        // Set the new Armour to the player while returning the old Armour (if the player wearing one).
                        swappedItem = equipment.EquipArmour(item);
                    }
                    else if (item.Type == "Ring")
                    {
                        // Set the new Ring to the player while returning the old Ring (if the player wearing one).
                        swappedItem = equipment.EquipRing(item);
                    }
                    else if (item.Type == "Bracelet")
                    {
                        // Set the new Bracelet to the player while returning the old Bracelet (if the player wearing one).
                        swappedItem = equipment.EquipBracelet(item);
                    }

                    // Remove this item from this List of Items.
                    GetComponentInParent <Inventory>().items [slotNumber] = new Item();
                    // IF we have an item being swapped out.
                    if (swappedItem != null)
                    {
                        // Add the swapped out equipped item to the inventory.
                        GetComponentInParent <Inventory>().AddItem(swappedItem.ID, 1);
                    }
                    // Do not show the tooltip.
                    Grid.tooltip.Deactivate();
                    // Destroy this item in the inventory list.
                    Destroy(gameObject);
                }
            }
        }