Exemplo n.º 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>());
			}
		}
	}
Exemplo n.º 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);
            }
        }
    }
Exemplo n.º 3
0
 public void Slots()
 {
     for (int i = 0; i < inventorySlots; i++)
     {
         Transform slot = Instantiate(slotPrefab);
         //slot.transform.SetParent(GameObject.FindObjectOfType<Inventory>().transform);
         slot.transform.SetParent(itemsParent, false);
         ItemSlots.Add(slot.gameObject.GetComponent <ItemSlot>());
     }
 }