Inventory.sortItems C# (CSharp) Method

sortItems() public method

public sortItems ( ) : void
return void
    public void sortItems()
    {
        int empty = -1;
        for (int i = 0; i < SlotContainer.transform.childCount; i++)
        {
            if (SlotContainer.transform.GetChild(i).childCount == 0 && empty == -1)
                empty = i;
            else
            {
                if (empty > -1)
                {
                    if (SlotContainer.transform.GetChild(i).childCount != 0)
                    {
                        RectTransform rect = SlotContainer.transform.GetChild(i).GetChild(0).GetComponent<RectTransform>();
                        SlotContainer.transform.GetChild(i).GetChild(0).transform.SetParent(SlotContainer.transform.GetChild(empty).transform);
                        rect.localPosition = Vector3.zero;
                        i = empty + 1;
                        empty = i;
                    }
                }
            }
        }
    }

Usage Example

コード例 #1
0
 void OnBackpack(Item item)
 {
     if (item.itemType == ItemType.Backpack)
     {
         for (int i = 0; i < item.itemAttributes.Count; i++)
         {
             if (mainInventory == null)
             {
                 mainInventory = inventory.GetComponent <Inventory>();
             }
             mainInventory.sortItems();
             if (item.itemAttributes[i].attributeName == "Slots")
             {
                 changeInventorySize(item.itemAttributes[i].attributeValue);
             }
         }
     }
 }