Пример #1
0
    public void EnablePanel()
    {
        panelactive   = true;
        panel.enabled = true;

        foreach (Image img in slotImages)
        {
            img.enabled = true;
        }
        foreach (BoxCollider2D col in slotColliders)
        {
            col.enabled = true;
        }

        foreach (TextMeshProUGUI text in itemTexts)
        {
            text.enabled = true;
        }



        if (isdirty)
        {
            foreach (EquipmentType item in EquipmentType.GetValues(typeof(EquipmentType)))
            {
                if (inventory.GetItemSlot(item) != null)
                {
                    equipmentSlotDict[item].SetItem(inventory.GetItemSlot(item));
                }
            }

            isdirty = false;
        }
    }
Пример #2
0
    // start awake functions not called on a disabled objectes could alter the function to check if images is set but the event listener wouldnt be enabled.


    public void Initalize(CharacterInventory pinventory)
    {
        panel      = transform.Find("InventoryPanel").GetComponent <Image>();
        slotHolder = transform.Find("InventoryPanel").transform.Find("ItemUiHolder");
        textHolder = transform.Find("InventoryPanel").transform.Find("ItemTextHolder");

        slotImages    = slotHolder.GetComponentsInChildren <Image>();
        slotColliders = slotHolder.GetComponentsInChildren <BoxCollider2D>();
        itemTexts     = textHolder.GetComponentsInChildren <TextMeshProUGUI>();

        Transform slots = transform.Find("InventoryPanel").Find("ItemUiHolder");

        itemSlots = slots.GetComponentsInChildren <ItemSlot>();

        inventory = pinventory;

        //listener for item equips and unequips
        EventManager.Current.RegisterListener <ItemEquipped>(UpdateSlot);
        EventManager.Current.RegisterListener <ItemUnequipped>(ClearSlot);

        //creates a dictionary of equipment type to associated slots
        int counter = 0;

        foreach (EquipmentType item in EquipmentType.GetValues(typeof(EquipmentType)))
        {
            if (counter == itemSlots.Length)
            {
                Debug.Log("Inventory image slots is missing an equipment type!");
                break;
            }

            equipmentSlotDict.Add(item, itemSlots[counter]);

            counter++;
        }
    }