Пример #1
0
        /// <summary>
        /// Destroys and replaces inventory UI components
        /// </summary>
        private void InitializeInventory()
        {
            if (inventory == null)
            {
                return;
            }

            if (slots != null)
            {
                //Destroy existing inventory slots
                for (int i = 0; i < slots.Length; i++)
                {
                    Destroy(slots[i].gameObject);
                }
            }

            //Initialize new slots array
            slots = new UISlot[inventory.GetSize()];

            //Instantiate new inventory slots
            for (int i = 0; i < slots.Length; i++)
            {
                GameObject instance = Instantiate(uiSlotPrefab, transform);
                UISlot     slot     = instance.GetComponent <UISlot>();
                slot.ItemDropped += OnItemDropped;
                slot.ID           = i;
                slots[i]          = slot;
            }

            OnInventoryUpdate();
        }
Пример #2
0
        public void OnDrop(PointerEventData eventData)
        {
            Transform dragged = eventData.pointerDrag.transform;

            if (dragged != null)
            {
                UISlot    startSlot = dragged.parent.GetComponent <UISlot>();
                Inventory inventory = startSlot.GetComponentInParent <UIInventory>().GetInventory();

                ItemDropped?.Invoke(startSlot.ID, ID, inventory);
            }
        }