Example #1
0
 public void addItemToInventory(int ignoreSlot, int itemID, int itemValue)
 {
     for (int i = 0; i < SlotContainer.transform.childCount; i++)
     {
         if (SlotContainer.transform.GetChild(i).childCount == 0 && i != ignoreSlot)
         {
             GameObject   item         = (GameObject)Instantiate(prefabItem);
             ItemOnObject itemOnObject = item.GetComponent <ItemOnObject>();
             itemOnObject.item = itemDatabase.getItemByID(itemID);
             if (itemOnObject.item.itemValue < itemOnObject.item.maxStack && itemValue <= itemOnObject.item.maxStack)
             {
                 itemOnObject.item.itemValue = itemValue;
             }
             else
             {
                 itemOnObject.item.itemValue = 1;
             }
             item.transform.SetParent(SlotContainer.transform.GetChild(i));
             item.GetComponent <RectTransform>().localPosition = Vector3.zero;
             itemOnObject.item.indexItemInList = 999;
             updateItemSize();
             stackableSettings();
             break;
         }
     }
     stackableSettings();
     updateItemList();
 }
Example #2
0
 public void addItemToInventoryStorage(int itemID, int value)
 {
     for (int i = 0; i < SlotContainer.transform.childCount; i++)
     {
         if (SlotContainer.transform.GetChild(i).childCount == 0)
         {
             GameObject   item         = (GameObject)Instantiate(prefabItem);
             ItemOnObject itemOnObject = item.GetComponent <ItemOnObject>();
             itemOnObject.item = itemDatabase.getItemByID(itemID);
             if (itemOnObject.item.itemValue < itemOnObject.item.maxStack && value <= itemOnObject.item.maxStack)
             {
                 itemOnObject.item.itemValue = value;
             }
             else
             {
                 itemOnObject.item.itemValue = 1;
             }
             item.transform.SetParent(SlotContainer.transform.GetChild(i));
             item.GetComponent <RectTransform>().localPosition = Vector3.zero;
             itemOnObject.item.indexItemInList = 999;
             if (inputManagerDatabase == null)
             {
                 inputManagerDatabase = (InputManager)Resources.Load("InputManager");
             }
             updateItemSize();
             stackableSettings();
             break;
         }
     }
     stackableSettings();
     updateItemList();
 }
Example #3
0
        public GameObject addItemToInventory(int id, int value)
        {
            for (int i = 0; i < SlotContainer.transform.childCount; i++)
            {
                if (SlotContainer.transform.GetChild(i).childCount == 0)
                {
                    GameObject   item         = (GameObject)Instantiate(prefabItem);
                    ItemOnObject itemOnObject = item.GetComponent <ItemOnObject>();
                    itemOnObject.item = itemDatabase.getItemByID(id);
                    if (itemOnObject.item.itemValue <= itemOnObject.item.maxStack && value <= itemOnObject.item.maxStack)
                    {
                        itemOnObject.item.itemValue = value;
                    }
                    else
                    {
                        itemOnObject.item.itemValue = 1;
                    }
                    item.transform.SetParent(SlotContainer.transform.GetChild(i));
                    item.GetComponent <RectTransform>().localPosition        = Vector3.zero;
                    item.transform.GetChild(0).GetComponent <Image>().sprite = itemOnObject.item.itemIcon;
                    itemOnObject.item.indexItemInList = ItemsInInventory.Count - 1;
                    if (inputManagerDatabase == null)
                    {
                        inputManagerDatabase = (InputManager)Resources.Load("InputManager");
                    }
                    return(item);
                }
            }

            stackableSettings();
            updateItemList();
            return(null);
        }
Example #4
0
        public void OnPointerDown(PointerEventData data)                    //splitting the item now
        {
            inv = transform.parent.parent.parent.GetComponent <Inventory>();
            if (transform.parent.parent.parent.GetComponent <Hotbar>() == null && data.button == PointerEventData.InputButton.Left && pressingButtonToSplit && inv.stackable && (inv.ItemsInInventory.Count < (inv.height * inv.width))) //if you press leftclick and and keycode
            {
                ItemOnObject itemOnObject = GetComponent <ItemOnObject>();                                                                                                                                                               //we take the ItemOnObject script of the item in the slot

                if (itemOnObject.item.itemValue > 1)                                                                                                                                                                                     //we split the item only when we have more than 1 in the stack
                {
                    int splitPart = itemOnObject.item.itemValue;                                                                                                                                                                         //we take the value and store it in there
                    itemOnObject.item.itemValue = (int)itemOnObject.item.itemValue / 2;                                                                                                                                                  //calculate the new value for the splitted item
                    splitPart = splitPart - itemOnObject.item.itemValue;                                                                                                                                                                 //take the different

                    inv.addItemToInventory(itemOnObject.item.itemID, splitPart);                                                                                                                                                         //and add a new item to the inventory
                    inv.stackableSettings();

                    if (GetComponent <ConsumeItem>().duplication != null)
                    {
                        GameObject dup = GetComponent <ConsumeItem>().duplication;
                        dup.GetComponent <ItemOnObject>().item.itemValue = itemOnObject.item.itemValue;
                        dup.GetComponent <SplitItem>().inv.stackableSettings();
                    }
                    inv.updateItemList();
                }
            }
        }
Example #5
0
 public void stackableSettings(bool stackable, Vector3 posi)
 {
     for (int i = 0; i < SlotContainer.transform.childCount; i++)
     {
         if (SlotContainer.transform.GetChild(i).childCount > 0)
         {
             ItemOnObject item = SlotContainer.transform.GetChild(i).GetChild(0).GetComponent <ItemOnObject>();
             if (item.item.maxStack > 1)
             {
                 RectTransform textRectTransform = SlotContainer.transform.GetChild(i).GetChild(0).GetChild(1).GetComponent <RectTransform>();
                 Text          text = SlotContainer.transform.GetChild(i).GetChild(0).GetChild(1).GetComponent <Text>();
                 text.text    = "" + item.item.itemValue;
                 text.enabled = stackable;
                 textRectTransform.localPosition = posi;
             }
         }
     }
 }
Example #6
0
        void ItemDataBase()
        {
            EditorGUILayout.BeginVertical("Box");

            GUILayout.BeginHorizontal();
            GUILayout.FlexibleSpace();
            toolbarInt = GUILayout.Toolbar(toolbarInt, toolbarStrings, GUILayout.Width(position.width - 18));                                                    //creating a toolbar(tabs) to navigate what you wanna do
            GUILayout.EndHorizontal();

            scrollPosition = EditorGUILayout.BeginScrollView(scrollPosition);

            GUILayout.Space(10);

            if (toolbarInt == 0)                                                                                                                              //if equal 0 than it is "Create Item"
            {
                GUI.color = Color.green;
                if (GUILayout.Button("Add Item", GUILayout.Width(position.width - 23)))
                {
                    addItem();
                    showItem = true;
                }

                if (showItem)
                {
                    GUI.color = Color.white;

                    GUILayout.BeginVertical("Box", GUILayout.Width(position.width - 23));
                    try
                    {
                        inventoryItemList.itemList[inventoryItemList.itemList.Count - 1].itemName = EditorGUILayout.TextField("Item Name", inventoryItemList.itemList[inventoryItemList.itemList.Count - 1].itemName, GUILayout.Width(position.width - 30)); //textfield for the itemname which you wanna create
                        inventoryItemList.itemList[inventoryItemList.itemList.Count - 1].itemID   = inventoryItemList.itemList.Count - 1;                                                                                                                    //itemID getting set automaticly ...its unique...better do not change it :D

                        GUILayout.BeginHorizontal();
                        GUILayout.Label("Item Description");                                                                                                                                                                                                                                             //label ItemDescription
                        GUILayout.Space(47);
                        inventoryItemList.itemList[inventoryItemList.itemList.Count - 1].itemDesc = EditorGUILayout.TextArea(inventoryItemList.itemList[inventoryItemList.itemList.Count - 1].itemDesc, GUILayout.Width(position.width - 180), GUILayout.Height(70));                                    //Text area for the itemDesc
                        GUILayout.EndHorizontal();
                        inventoryItemList.itemList[inventoryItemList.itemList.Count - 1].itemIcon  = (Sprite)EditorGUILayout.ObjectField("Item Icon", inventoryItemList.itemList[inventoryItemList.itemList.Count - 1].itemIcon, typeof(Sprite), false, GUILayout.Width(position.width - 33));           //objectfield for the itemicon for your new item
                        inventoryItemList.itemList[inventoryItemList.itemList.Count - 1].itemModel = (GameObject)EditorGUILayout.ObjectField("Item Model", inventoryItemList.itemList[inventoryItemList.itemList.Count - 1].itemModel, typeof(GameObject), false, GUILayout.Width(position.width - 33)); //objectfield for the itemmodel for your new item

                        inventoryItemList.itemList[inventoryItemList.itemList.Count - 1].itemType = (ItemType)EditorGUILayout.EnumPopup("Item Type", inventoryItemList.itemList[inventoryItemList.itemList.Count - 1].itemType, GUILayout.Width(position.width - 33));                                   //the itemtype which you want to have can be selected with the enumpopup
                        inventoryItemList.itemList[inventoryItemList.itemList.Count - 1].maxStack = EditorGUILayout.IntField("Max Stack", inventoryItemList.itemList[inventoryItemList.itemList.Count - 1].maxStack, GUILayout.Width(position.width - 33));
                        inventoryItemList.itemList[inventoryItemList.itemList.Count - 1].rarity   = EditorGUILayout.IntSlider("Rarity", inventoryItemList.itemList[inventoryItemList.itemList.Count - 1].rarity, 0, 100);

                        #region attributes
                        GUILayout.BeginVertical("Box", GUILayout.Width(position.width - 33));
                        showItemAttributes = EditorGUILayout.Foldout(showItemAttributes, "Item attributes");
                        if (showItemAttributes)
                        {
                            GUILayout.BeginHorizontal();
                            addAttributeName = EditorGUILayout.TextField("Name", addAttributeName);
                            GUI.color        = Color.green;
                            if (GUILayout.Button("Add"))
                            {
                                addAttribute();
                            }
                            GUILayout.EndHorizontal();
                            GUILayout.Space(10);
                            GUI.color = Color.white;
                            EditorGUI.BeginChangeCheck();
                            attributeAmount = EditorGUILayout.IntSlider("Amount", attributeAmount, 0, 50);
                            if (EditorGUI.EndChangeCheck())
                            {
                                attributeName  = new int[attributeAmount];
                                attributeValue = new int[attributeAmount];
                            }

                            string[] attributes = new string[itemAttributeList.itemAttributeList.Count];
                            for (int i = 0; i < attributes.Length; i++)
                            {
                                attributes[i] = itemAttributeList.itemAttributeList[i].attributeName;
                            }

                            for (int k = 0; k < attributeAmount; k++)
                            {
                                EditorGUILayout.BeginHorizontal();
                                attributeName[k]  = EditorGUILayout.Popup("Attribute " + (k + 1), attributeName[k], attributes, EditorStyles.popup);
                                attributeValue[k] = EditorGUILayout.IntField("Value", attributeValue[k]);
                                EditorGUILayout.EndHorizontal();
                            }



                            if (GUILayout.Button("Save"))
                            {
                                List <ItemAttribute> iA = new List <ItemAttribute>();
                                for (int i = 0; i < attributeAmount; i++)
                                {
                                    iA.Add(new ItemAttribute(attributes[attributeName[i]], attributeValue[i]));
                                }
                                inventoryItemList.itemList[inventoryItemList.itemList.Count - 1].itemAttributes = iA;
                                showItem = false;
                            }
                        }
                        GUILayout.EndVertical();
                        #endregion

                        //#region categories
                        //GUILayout.BeginVertical("Box", GUILayout.Width(position.width - 33));
                        //showItemCategories = EditorGUILayout.Foldout(showItemCategories, "Item categories");
                        //if (showItemCategories)
                        //{
                        //    GUILayout.BeginHorizontal();
                        //    addCategoryName = EditorGUILayout.TextField("Name", addCategoryName);
                        //    GUI.color = Color.green;
                        //    if (GUILayout.Button("Add"))
                        //        addCategory();
                        //    GUILayout.EndHorizontal();
                        //    GUILayout.Space(10);
                        //    GUI.color = Color.white;
                        //    EditorGUI.BeginChangeCheck();
                        //    categoryAmount = EditorGUILayout.IntSlider("Amount", categoryAmount, 0, 50);
                        //    if (EditorGUI.EndChangeCheck())
                        //    {
                        //        categoryName = new int[categoryAmount];
                        //        categoryValue = new int[categoryAmount];
                        //    }

                        //    string[] categories = new string[itemCategoryList.itemCategoryList.Count];
                        //    for (int i = 0; i < categories.Length; i++)
                        //    {
                        //        categories[i] = itemCategoryList.itemCategoryList[i].categoryName;
                        //    }

                        //    for (int k = 0; k < categoryAmount; k++)
                        //    {
                        //        EditorGUILayout.BeginHorizontal();
                        //        //categoryName[k] = EditorGUILayout.Popup("Category " + (k + 1), categoryName[k], categories, EditorStyles.popup);
                        //        //categoryValue[k] = EditorGUILayout.IntField("Value", categoryValue[k]);
                        //        EditorGUILayout.EndHorizontal();
                        //    }
                        //    if (GUILayout.Button("Save"))
                        //    {
                        //        List<ItemCategory> iA = new List<ItemCategory>();
                        //        for (int i = 0; i < categoryAmount; i++)
                        //        {
                        //            iA.Add(new ItemCategory(categories[categoryName[i]], categoryValue[i]));
                        //        }
                        //        inventoryItemList.itemList[inventoryItemList.itemList.Count - 1].itemCategories = iA;
                        //        showItem = false;

                        //    }

                        //}
                        //GUILayout.EndVertical();
                        //#endregion

                        inventoryItemList.itemList[inventoryItemList.itemList.Count - 1].indexItemInList = 999;
                    }
                    catch (System.Exception ex)
                    {
                        Debug.LogError(ex.ToString());
                    }
                    GUILayout.EndVertical();
                }
            }

            if (toolbarInt == 1)                                                            //if toolbar equals 1...manage items...alle items are editable here
            {
                if (inventoryItemList.itemList.Count == 1)                                  //if there is no item in the database you get this...yes it is right to have == 1
                {
                    GUILayout.Label("There is no Item in the Database!");                   //information that you do not have one
                }
                else
                {
                    GUILayout.BeginVertical();
                    for (int i = 1; i < inventoryItemList.itemList.Count; i++)                      //get through all items which are there in the itemdatabase
                    {
                        try
                        {
                            manageItem.Add(false);                                                                               //foldout is closed at default
                            GUILayout.BeginVertical("Box");
                            manageItem[i] = EditorGUILayout.Foldout(manageItem[i], "" + inventoryItemList.itemList[i].itemName); //create for every item which you have in the itemdatabase a foldout
                            if (manageItem[i])                                                                                   //if you press on it you get this
                            {
                                EditorUtility.SetDirty(inventoryItemList);                                                       //message the scriptableobject that you change something now
                                GUI.color = Color.red;                                                                           //all upcoming GUIelements get changed to red
                                if (GUILayout.Button("Delete Item"))                                                             //create button that deletes the item
                                {
                                    inventoryItemList.itemList.RemoveAt(i);                                                      //remove the item out of the itemdatabase
                                    EditorUtility.SetDirty(inventoryItemList);                                                   //and message the database again that you changed something
                                }

                                GUI.color = Color.white;                                                                                                                                       //next GUIElements will be white
                                inventoryItemList.itemList[i].itemName = EditorGUILayout.TextField("Item Name", inventoryItemList.itemList[i].itemName, GUILayout.Width(position.width - 45)); //textfield for the itemname which you wanna create
                                inventoryItemList.itemList[i].itemID   = i;                                                                                                                    //itemID getting set automaticly ...its unique...better do not change it :D
                                GUILayout.BeginHorizontal();
                                GUILayout.Label("Item ID");
                                GUILayout.Label("" + i);
                                GUILayout.EndHorizontal();
                                GUILayout.BeginHorizontal();
                                GUILayout.Label("Item Description");                                                                                                                                                                       //label ItemDescription
                                GUILayout.Space(47);
                                inventoryItemList.itemList[i].itemDesc = EditorGUILayout.TextArea(inventoryItemList.itemList[i].itemDesc, GUILayout.Width(position.width - 195), GUILayout.Height(70));                                    //Text area for the itemDesc
                                GUILayout.EndHorizontal();
                                inventoryItemList.itemList[i].itemIcon  = (Sprite)EditorGUILayout.ObjectField("Item Icon", inventoryItemList.itemList[i].itemIcon, typeof(Sprite), false, GUILayout.Width(position.width - 45));           //objectfield for the itemicon for your new item
                                inventoryItemList.itemList[i].itemModel = (GameObject)EditorGUILayout.ObjectField("Item Model", inventoryItemList.itemList[i].itemModel, typeof(GameObject), false, GUILayout.Width(position.width - 45)); //objectfield for the itemmodel for your new item
                                inventoryItemList.itemList[i].itemType  = (ItemType)EditorGUILayout.EnumPopup("Item Type", inventoryItemList.itemList[i].itemType, GUILayout.Width(position.width - 45));                                  //the itemtype which you want to have can be selected with the enumpopup
                                inventoryItemList.itemList[i].maxStack  = EditorGUILayout.IntField("Max Stack", inventoryItemList.itemList[i].maxStack, GUILayout.Width(position.width - 45));
                                inventoryItemList.itemList[i].rarity    = EditorGUILayout.IntSlider("Rarity", inventoryItemList.itemList[i].rarity, 0, 100);

                                GUILayout.BeginVertical("Box", GUILayout.Width(position.width - 45));
                                showItemAttributes = EditorGUILayout.Foldout(showItemAttributes, "Item attributes");
                                if (showItemAttributes)
                                {
                                    string[] attributes = new string[itemAttributeList.itemAttributeList.Count];
                                    for (int t = 1; t < attributes.Length; t++)
                                    {
                                        attributes[t] = itemAttributeList.itemAttributeList[t].attributeName;
                                    }


                                    if (inventoryItemList.itemList[i].itemAttributes.Count != 0)
                                    {
                                        for (int t = 0; t < inventoryItemList.itemList[i].itemAttributes.Count; t++)
                                        {
                                            for (int z = 1; z < attributes.Length; z++)
                                            {
                                                if (inventoryItemList.itemList[i].itemAttributes[t].attributeName == attributes[z])
                                                {
                                                    attributeNamesManage[t] = z;
                                                    attributeValueManage[t] = inventoryItemList.itemList[i].itemAttributes[t].attributeValue;
                                                    break;
                                                }
                                            }
                                        }
                                    }

                                    for (int z = 0; z < inventoryItemList.itemList[i].itemAttributes.Count; z++)
                                    {
                                        EditorGUILayout.BeginHorizontal();
                                        GUI.color = Color.red;
                                        if (GUILayout.Button("-"))
                                        {
                                            inventoryItemList.itemList[i].itemAttributes.RemoveAt(z);
                                        }
                                        GUI.color = Color.white;
                                        attributeNamesManage[z] = EditorGUILayout.Popup(attributeNamesManage[z], attributes, EditorStyles.popup);
                                        inventoryItemList.itemList[i].itemAttributes[z].attributeValue = EditorGUILayout.IntField("Value", inventoryItemList.itemList[i].itemAttributes[z].attributeValue);
                                        EditorGUILayout.EndHorizontal();
                                    }
                                    GUI.color = Color.green;
                                    if (GUILayout.Button("+"))
                                    {
                                        inventoryItemList.itemList[i].itemAttributes.Add(new ItemAttribute());
                                    }



                                    GUI.color = Color.white;
                                    //what happens if the button save is clicked
                                    if (GUILayout.Button("Save"))
                                    {
                                        List <ItemAttribute> iA = new List <ItemAttribute>();
                                        for (int k = 0; k < inventoryItemList.itemList[i].itemAttributes.Count; k++)
                                        {
                                            iA.Add(new ItemAttribute(attributes[attributeNamesManage[k]], attributeValueManage[k]));
                                        }
                                        inventoryItemList.itemList[i].itemAttributes = iA;

                                        GameObject[] items = GameObject.FindGameObjectsWithTag("Item");
                                        for (int z = 0; z < items.Length; z++)
                                        {
                                            ItemOnObject item = items[z].GetComponent <ItemOnObject>();
                                            if (item.item.itemID == inventoryItemList.itemList[i].itemID)
                                            {
                                                int value = item.item.itemValue;
                                                item.item           = inventoryItemList.itemList[i];
                                                item.item.itemValue = value;
                                            }
                                        }

                                        manageItem[i] = false;
                                    }
                                }
                                GUILayout.EndVertical();


                                //GUILayout.BeginVertical("Box", GUILayout.Width(position.width - 45));
                                //showItemCategories = EditorGUILayout.Foldout(showItemCategories, "Item categories");
                                //if (showItemCategories)
                                //{

                                //    string[] categories = new string[itemCategoryList.itemCategoryList.Count];
                                //    for (int t = 0; t < categories.Length; t++)
                                //    {
                                //        categories[t] = itemCategoryList.itemCategoryList[t].categoryName;
                                //    }


                                //    if (inventoryItemList.itemList[i].itemCategories.Count != 0)
                                //    {
                                //        for (int t = 0; t < inventoryItemList.itemList[i].itemCategories.Count; t++)
                                //        {
                                //            for (int z = 1; z < categories.Length; z++)
                                //            {
                                //                if (inventoryItemList.itemList[i].itemCategories[t].categoryName == categories[z])
                                //                {
                                //                    categoryNamesManage[t] = z;
                                //                    categoryValueManage[t] = inventoryItemList.itemList[i].itemCategories[t].categoryValue;
                                //                    break;
                                //                }
                                //            }
                                //        }
                                //    }

                                //    for (int z = 0; z < inventoryItemList.itemList[i].itemCategories.Count; z++)
                                //    {
                                //        EditorGUILayout.BeginHorizontal();
                                //        GUI.color = Color.red;
                                //        if (GUILayout.Button("-"))
                                //            inventoryItemList.itemList[i].itemCategories.RemoveAt(z);
                                //        GUI.color = Color.white;
                                //        categoryNamesManage[z] = EditorGUILayout.Popup(categoryNamesManage[z], categories, EditorStyles.popup);
                                //        inventoryItemList.itemList[i].itemCategories[z].categoryValue = EditorGUILayout.IntField("Value", inventoryItemList.itemList[i].itemCategories[z].categoryValue);
                                //        EditorGUILayout.EndHorizontal();
                                //    }
                                //    GUI.color = Color.green;
                                //    if (GUILayout.Button("+"))
                                //        inventoryItemList.itemList[i].itemCategories.Add(new ItemCategory());



                                //    GUI.color = Color.white;
                                //    //what happens if the button save is clicked
                                //    if (GUILayout.Button("Save"))
                                //    {
                                //        List<ItemCategory> iA = new List<ItemCategory>();
                                //        for (int k = 0; k < inventoryItemList.itemList[i].itemCategories.Count; k++)
                                //        {
                                //            iA.Add(new ItemCategory(categories[categoryNamesManage[k]], categoryValueManage[k]));
                                //        }
                                //        inventoryItemList.itemList[i].itemCategories = iA;

                                //        GameObject[] items = GameObject.FindGameObjectsWithTag("Item");
                                //        for (int z = 0; z < items.Length; z++)
                                //        {
                                //            ItemOnObject item = items[z].GetComponent<ItemOnObject>();
                                //            if (item.item.itemID == inventoryItemList.itemList[i].itemID)
                                //            {
                                //                int value = item.item.itemValue;
                                //                item.item = inventoryItemList.itemList[i];
                                //                item.item.itemValue = value;
                                //            }
                                //        }

                                //        manageItem[i] = false;
                                //    }



                                //}
                                //GUILayout.EndVertical();

                                EditorUtility.SetDirty(inventoryItemList);                                                                                              //message scriptable object that you have changed something
                            }
                            GUILayout.EndVertical();
                        }
                        catch (System.Exception ex)
                        {
                            Debug.LogError(ex.ToString());
                        }
                    }
                    GUILayout.EndVertical();
                }
            }

            EditorGUILayout.EndScrollView();

            EditorGUILayout.EndVertical();
        }
Example #7
0
        public void updateSlotAmount()
        {
            if (prefabSlot == null)
            {
                prefabSlot = Resources.Load("Prefabs/Slot - Inventory") as GameObject;
            }

            if (SlotContainer == null)
            {
                SlotContainer = (GameObject)Instantiate(prefabSlotContainer);
                SlotContainer.transform.SetParent(PanelRectTransform.transform);
                SlotContainerRectTransform = SlotContainer.GetComponent <RectTransform>();
                SlotGridRectTransform      = SlotContainer.GetComponent <RectTransform>();
                SlotGridLayout             = SlotContainer.GetComponent <GridLayoutGroup>();
            }

            if (SlotContainerRectTransform == null)
            {
                SlotContainerRectTransform = SlotContainer.GetComponent <RectTransform>();
            }
            SlotContainerRectTransform.localPosition = Vector3.zero;

            List <Item>       itemsToMove = new List <Item>();
            List <GameObject> slotList    = new List <GameObject>();

            foreach (Transform child in SlotContainer.transform)
            {
                if (child.tag == "Slot")
                {
                    slotList.Add(child.gameObject);
                }
            }

            while (slotList.Count > width * height)
            {
                GameObject   go         = slotList[slotList.Count - 1];
                ItemOnObject itemInSlot = go.GetComponentInChildren <ItemOnObject>();
                if (itemInSlot != null)
                {
                    itemsToMove.Add(itemInSlot.item);
                    ItemsInInventory.Remove(itemInSlot.item);
                }
                slotList.Remove(go);
                DestroyImmediate(go);
            }

            if (slotList.Count < width * height)
            {
                for (int i = slotList.Count; i < (width * height); i++)
                {
                    GameObject Slot = (GameObject)Instantiate(prefabSlot);
                    Slot.name = (slotList.Count + 1).ToString();
                    Slot.transform.SetParent(SlotContainer.transform);
                    slotList.Add(Slot);
                }
            }

            if (itemsToMove != null && ItemsInInventory.Count < width * height)
            {
                foreach (Item i in itemsToMove)
                {
                    addItemToInventory(i.itemID);
                }
            }

            setImportantVariables();
        }