Example #1
0
	private void SetMaxSlots(int value)
	{
		if (value <= 0) {
			maxSlots = 1;
		} else {
			maxSlots = value;
		}

		if (maxSlots < ItemSlots.Count)
		{
			for (int i = maxSlots; i < ItemSlots.Count; i++)
			{
				Destroy(ItemSlots[i].transform.parent.gameObject);
			}
			int diff = ItemSlots.Count - maxSlots;
			ItemSlots.RemoveRange(maxSlots, diff);
		}
		else if (maxSlots > ItemSlots.Count)
		{
			int diff = maxSlots - ItemSlots.Count;

			for (int i = 0; i < diff; i++)
			{
				GameObject gameObject = Instantiate(itemSlotPrefab);
				gameObject.transform.SetParent(itemsParent, worldPositionStays: false);
				ItemSlots.Add(gameObject.GetComponentInChildren<ItemSlot>());
			}
		}
	}
Example #2
0
    private void SetMaxSlots(int value)
    {
        base.Awake();
        if (value <= 0)
        {
            maxSlots = 1;
        }
        else
        {
            maxSlots = value;
        }

        if (maxSlots < ItemSlots.Count)
        {
            for (int i = maxSlots; i < ItemSlots.Count; i++)
            {
                Destroy(ItemSlots[i]);
            }
            int diff = ItemSlots.Count - maxSlots;
            ItemSlots.RemoveRange(maxSlots, diff);
        }
        else if (maxSlots > ItemSlots.Count)
        {
            int diff = maxSlots - ItemSlots.Count;

            for (int i = 0; i < diff; i++)
            {
                ItemSlot slot = Instantiate(itemSlotPrefab).GetComponent <ItemSlot>();
                slot.transform.SetParent(itemsParent, worldPositionStays: false);
                slot.transform.SetAsLastSibling();
                LayoutRebuilder.ForceRebuildLayoutImmediate(itemsParent.GetComponent <RectTransform>());
                ItemSlots.Add(slot);
            }
        }
    }