Exemplo n.º 1
0
    // Update is called once per frame
    void Update()
    {
        for (int i = 0; i < slotCount; i++)
        {
            if (Input.GetKeyDown(KeyCode.Alpha1 + i))
            {
                eventSubscriber.selectedUIItem = itemPanel.GetChild(i).gameObject;
                eventSubscriber.selectedUIItem.GetComponent <InventoryItemClickable>().OnItemSwitched();
            }
        }

        if (Input.GetButton("Fire1"))
        {
            if (eventSubscriber.selectedUIItem != null)
            {
                clickable = eventSubscriber.selectedUIItem.GetComponent <InventoryItemClickable>();
                clickable.OnItemClicked();
            }
        }
    }
    private void InventoryItemAdded(object sender, InventoryEventArgs e)
    {
        Transform panel = transform.Find("InventoryHud");

        foreach (Transform slot in panel)
        {
            Image image = slot.GetComponent <Image> ();
            // new
            InventoryItemClickable button = slot.GetComponent <InventoryItemClickable> ();

            if (!image.enabled)
            {
                image.enabled = true;
                image.sprite  = e.item.itemImage;
                button.item   = e.item;               // new

                break;
            }
        }
    }
Exemplo n.º 3
0
    void ItemUsed(object sender, InventoryEventArgs e)
    {
        foreach (Transform slot in panel)
        {
            InventoryItemClickable button = slot.GetComponent <InventoryItemClickable>();

            if (button.item == e.item)
            {
                Image image = slot.GetComponent <Image>();

                if (image.enabled)
                {
                    image.enabled = false;
                    image.sprite  = null;
                    slot.GetComponent <Outline>().enabled = false;
                    button.item    = null;
                    selectedUIItem = null;
                    break;
                }
            }
        }
    }
Exemplo n.º 4
0
    public void ItemAdded(object sender, InventoryEventArgs e)
    {
        IInventoryItem item = e.item;

        // Enable the correct slot for the item

        foreach (Transform slot in panel)
        {
            Image image = slot.GetComponent <Image>();
            InventoryItemClickable button = slot.GetComponent <InventoryItemClickable>();

            slot.GetComponent <Outline>().enabled = false;

            if (!image.enabled)
            {
                image.enabled = true;
                image.sprite  = item.itemImage;
                slot.GetComponent <Outline>().enabled = true;
                button.item    = e.item;
                selectedUIItem = slot.gameObject;
                break;
            }
        }
    }