Example #1
0
    //ici on ajoute en UI
    private void Inventory_ItemAdded(object sender, InvEventArgs e)
    {
        InvPrefab item           = e.Item;
        Transform inventoryPanel = transform.Find("Inventory pannel");

        foreach (Transform slot in inventoryPanel)
        {
            Transform       comp            = slot.GetChild(0).GetChild(0);
            Image           image           = comp.GetComponent <Image>();
            ItemDragHandler itemDragHandler = comp.GetComponent <ItemDragHandler>();
            Text            label           = comp.GetChild(0).GetComponent <Text>();


            if (!image.enabled)
            {
                image.enabled = true;
                image.sprite  = item.Image;

                int txt = inventaire.nombreItem(e.Item);
                label.text = txt.ToString();

                itemDragHandler.Item = item;

                break;
            }
        }
    }
Example #2
0
    private void Inventory_ItemRemoved(object sender, InvEventArgs e)
    {
        Transform inventoryPanel = transform.Find("Inventory pannel");


        foreach (Transform slot in inventoryPanel)
        {
            // if(slot)
            Transform       comp            = slot.GetChild(0).GetChild(0);
            Image           image           = comp.GetComponent <Image>();
            ItemDragHandler itemDragHandler = comp.GetComponent <ItemDragHandler>();
            Text            label           = comp.GetChild(0).GetComponent <Text>();

            // print(itemDragHandler);
            if (itemDragHandler.Item.Name.Equals(e.Item.Name))
            {
                image.enabled        = false;
                image.sprite         = null;
                itemDragHandler.Item = null;

                int txt = inventaire.nombreItem(e.Item);
                print(txt);
                if (txt == 0)
                {
                    label.text = "";
                }
                else
                {
                    label.text = txt.ToString();
                }

                break;
            }
        }
    }
Example #3
0
    private void Inventory_ItemRemplace(object sender, InvEventArgs e)
    {
        Transform inventoryPanel = transform.Find("Inventory pannel");


        foreach (Transform slot in inventoryPanel)
        {
            // if(slot)
            Transform       comp            = slot.GetChild(0).GetChild(0);
            Image           image           = comp.GetComponent <Image>();
            ItemDragHandler itemDragHandler = comp.GetComponent <ItemDragHandler>();
            Text            label           = comp.GetChild(0).GetComponent <Text>();

            // print(itemDragHandler);
            if (itemDragHandler.Item.Name.Equals(e.Item.Name))
            {
                image.sprite         = e.Item.Image;;
                itemDragHandler.Item = e.Item;

                int txt = inventaire.nombreItem(e.Item);
                label.text = txt.ToString();
                break;
            }
        }
    }