Пример #1
0
        /// <summary>
        ///     Spawns the inventory icon into a given slot.
        /// </summary>
        /// <param name="slotIndex">The index of the slot that will parent the icon.</param>
        /// <param name="slotsHandler">Used to pass into the icon's <see cref="SwappablePositionManager"/></param>
        /// <returns>The items icon <see cref="GameObject"/> instance</returns>
        public GameObject SpawnInventoryIcon(int slotIndex, InventorySlotsHandler slotsHandler)
        {
            SlotIndex = slotIndex;
            GameObject itemObj = UnityEngine.Object.Instantiate(itemType.IconPrefab);

            // Second child of the icon gameObject must be the text amt
            GameObject textAmt = itemObj.transform.GetChild(TEXT_CHILD_IDX).gameObject;

            if (itemObj.TryGetComponent(out IItemRefsGUID guid))
            {
                // assign the reference guid to be this items guid
                guid.ItemGuid = this.guid;
            }

            // assign the slot index to the position manager for movement of items
            var positionManager = itemObj.GetComponent <SwappablePositionManager>();

            positionManager.SetSwappable(this);
            SlotsHandler = slotsHandler;

            Icon = itemObj.GetComponent <Image>();

            TextAmt = textAmt.GetComponent <TextMeshProUGUI>();

            SetTextAmt();

            return(itemObj);
        }
Пример #2
0
 private void Awake()
 {
     swapManager    = FindObjectOfType <SwapManager>();
     inventorySlots = GetComponent <InventorySlotsHandler>();
     if (inventorySlots != null)
     {
         inventorySlots.OnInventoryClosed = RemoveSwappableIfInventoryItem;
     }
 }