Ejemplo n.º 1
0
        /// <summary>
        /// Draws the slot and its content (icon, quantity...).
        /// </summary>
        /// <param name="i">The index.</param>
        protected virtual void DrawSlot(int i)
        {
            if (!DrawEmptySlots)
            {
                if (InventoryItem.IsNull(TargetInventory.Content[i]))
                {
                    return;
                }
            }

            if (_slotPrefab == null)
            {
                InitializeSlotPrefab();
            }

            GameObject theSlot = (GameObject)Instantiate(_slotPrefab);

            theSlot.transform.SetParent(InventoryGrid.transform);
            theSlot.GetComponent <RectTransform>().localScale = Vector3.one;
            theSlot.transform.position = transform.position;
            theSlot.name = "Slot " + i;

            // we add the background image
            if (!InventoryItem.IsNull(TargetInventory.Content[i]))
            {
                theSlot.GetComponent <Image>().sprite = FilledSlotImage;
            }
            else
            {
                theSlot.GetComponent <Image>().sprite = EmptySlotImage;
            }
            theSlot.GetComponent <Image>().type = SlotImageType;
            theSlot.GetComponent <InventorySlot>().spriteState            = _spriteState;
            theSlot.GetComponent <InventorySlot>().MovedSprite            = MovedSlotImage;
            theSlot.GetComponent <InventorySlot>().ParentInventoryDisplay = this;
            theSlot.GetComponent <InventorySlot>().Index = i;

            SlotContainer.Add(theSlot);

            theSlot.SetActive(true);

            theSlot.GetComponent <InventorySlot>().DrawIcon(TargetInventory.Content[i], i);
        }