Пример #1
0
        /// <summary>
        /// If there's an item in this slot, draws its icon inside.
        /// </summary>
        /// <param name="item">Item.</param>
        /// <param name="index">Index.</param>
        public virtual void DrawIcon(InventoryItem item, int index)
        {
            if (ParentInventoryDisplay != null)
            {
                if (!InventoryItem.IsNull(item))
                {
                    GameObject itemIcon = new GameObject("Icon", typeof(RectTransform));
                    itemIcon.transform.SetParent(this.transform);
                    UnityEngine.UI.Image itemIconImage = itemIcon.AddComponent <Image>();
                    itemIconImage.sprite = item.Icon;
                    RectTransform itemRectTransform = itemIcon.GetComponent <RectTransform>();
                    itemRectTransform.localPosition = Vector3.zero;
                    itemRectTransform.localScale    = Vector3.one;
                    MMGUI.SetSize(itemRectTransform, ParentInventoryDisplay.IconSize);

                    // if there's more than one of this item in this slot, we draw the associated quantity
                    if (item.Quantity > 1)
                    {
                        GameObject textObject = new GameObject("Slot " + index + " Quantity", typeof(RectTransform));
                        textObject.transform.SetParent(this.transform);
                        Text textComponent = textObject.AddComponent <Text>();
                        textComponent.text      = item.Quantity.ToString();
                        textComponent.font      = ParentInventoryDisplay.QtyFont;
                        textComponent.fontSize  = ParentInventoryDisplay.QtyFontSize;
                        textComponent.color     = ParentInventoryDisplay.QtyColor;
                        textComponent.alignment = ParentInventoryDisplay.QtyAlignment;
                        RectTransform textObjectRectTransform = textObject.GetComponent <RectTransform>();
                        textObjectRectTransform.localPosition = Vector3.zero;
                        textObjectRectTransform.localScale    = Vector3.one;
                        MMGUI.SetSize(textObjectRectTransform, (ParentInventoryDisplay.SlotSize - Vector2.one * ParentInventoryDisplay.QtyPadding));
                    }
                }
            }
        }