Пример #1
0
        private void Init()
        {
            // add update listener
            inventory.AddOnInventoryUpdateListener(OnInventoryUpdate);

            // hide templates
            inventoryUISlotTemplate.gameObject.SetActive(false);
            inventoryUIObjectTemplate.gameObject.SetActive(false);

            // instantiate all slots according to inventory
            slotSpecial.Init(this);
            InstantiateNewSlots(inventory.GetSlotCount());

            // add all existing inventory objects
            foreach (InventoryObject inventoryObject in inventory.GetInventoryObjects())
            {
                AddInventoryObject(inventoryObject);
            }

            // cleanup existing scene inventory objects which are already stored in the inventory
            inventory.CleanupExistingSceneInventoryObjects();

            // add special inventory object if existing
            if (inventory.GetSpecialInventoryObject() != null)
            {
                AddInventoryObject(inventory.GetSpecialInventoryObject(), true);
            }
        }
Пример #2
0
        public void InstantiateNewSlots(int amount)
        {
            for (int i = 0; i < amount; i++)
            {
                GameObject templateClone = Instantiate(inventoryUISlotTemplate.gameObject, Vector3.zero, Quaternion.identity);
                templateClone.name = "Slot" + i;
                InventoryUISlot slot = templateClone.GetComponent <InventoryUISlot>();
                slot.SetInventoryUIObject(null);
                slot.GetTransform().SetParent(inventoryUISlotTemplate.GetTransform().parent);
                slot.GetTransform().localScale = inventoryUISlotTemplate.GetTransform().localScale;
                slot.gameObject.SetActive(true);
                slot.Init(this);

                slots.Add(slot);
            }
        }