Example #1
0
    private void UpdateText()
    {
        if (!GameManager.Instance)
        {
            return;
        }

        // Update all texts for now
        for (int i = 0; i < NumInventorySlots; ++i)
        {
            ItemCount ic = GameManager.Instance.MainPlayer.Inventory.GetSlotInformation(i);

            InventorySlotUI isu = m_inventorySlot[i];

            if (ic.Count == 0)
            {
                isu.m_count.text = "";
            }
            else
            {
                isu.m_count.text = ic.Count.ToString();
            }

            isu.m_title.color = (i == m_selectSlotIndex)
            ? new Color(48 / 255f, 255 / 255f, 42 / 255f)
            : new Color(1f, 1f, 1f);

            // set what is owned by this inventory slot
            if (ic.Item == EItem.None)
            {
                isu.m_icon.sprite = null;
                isu.m_icon.color  = new Color(1f, 1f, 1f, 0f);
            }
            else
            {
                if (isu.m_icon.sprite == null)
                {
                    TileResourceDef tileResourceDef = TileMapping.GetTileResourceDef((ETile)ic.Item);
                    Texture2D       tex             = tileResourceDef != null
                        ? Resources.Load(tileResourceDef.Filename) as Texture2D
                        : null;

                    if (tex)
                    {
                        Sprite sprite = Sprite.Create(tex, tileResourceDef.Rect, Vector2.zero);
                        isu.m_icon.sprite = sprite;
                        isu.m_icon.color  = ItemInstance.GetColorForItem(ic.Item);
                        isu.m_icon.rectTransform.SetWidth(Mathf.Min(tileResourceDef.Rect.width, 32));
                        isu.m_icon.rectTransform.SetHeight(Mathf.Min(tileResourceDef.Rect.height, 32));
                    }
                }
            }
        }
    }