void CheckSlots(ItemData itemData, Transform[] _inventory) { ItemData itemDataScript = itemData.GetComponent <ItemData>(); ItemDataPack itemPack = itemDataScript._item; foreach (Transform slot in _inventory) { if (slot.childCount > 0) { ItemDataPack _item = slot.GetChild(0).GetComponent <ItemData>()._item; if (_item.Type == itemPack.Type) { if (_item.Id == itemPack.Id) { InventoryStackControl scrpt = slot.GetChild(0).GetComponent <InventoryStackControl>(); if (scrpt != null) { scrpt.IncreaseStack(itemPack.Amount); Debug.Log(scrpt.amount.ToString()); } //child.GetChild(0).GetComponent<Text> ().text = "" + tcount; //DataBox.text = "" + item.gameObject.name; Debug.Log("returned"); return; } } } } foreach (Transform slot in _inventory) { if (slot.childCount == 0) { GameObject itemToInstantiate = null; if (itemPack.Type == 1) { itemToInstantiate = itemIconDict[itemPack.Id]; } if (itemPack.Type == 2) { itemToInstantiate = attachmentIconDict[itemPack.Id]; } GameObject i = Instantiate(itemToInstantiate); i.transform.SetParent(slot); InventoryStackControl scrpt = i.GetComponent <InventoryStackControl>(); scrpt.IncreaseStack(itemPack.Amount); return; } } }
void CheckContents(ItemData object_) { //ItemData itemDataScript = object_.GetComponent<ItemData>(); ItemData itemDataScript = object_; ItemDataPack itemPack = itemDataScript._item; ///if the item is a weapon if (itemPack.Type == 1) { WeaponDataPack weaponPack = itemDataScript.weaponData; //if item is a primary weapon if (weaponPack.WeaponType == 1) { if (primarySlotOne.transform.childCount == 0) { GameObject itemToInstantiate = null; if (itemPack.Type == 1) { itemToInstantiate = itemIconDict[itemPack.Id]; } GameObject i = Instantiate(itemToInstantiate); i.transform.SetParent(primarySlotOne.transform); InventoryStackControl scrpt = i.GetComponent <InventoryStackControl>(); scrpt.IncreaseStack(itemPack.Amount); return; } if (primarySlotTwo.transform.childCount == 0) { GameObject itemToInstantiate = null; if (itemPack.Type == 1) { itemToInstantiate = itemIconDict[itemPack.Id]; } GameObject i = Instantiate(itemToInstantiate); i.transform.SetParent(primarySlotTwo.transform); InventoryStackControl scrpt = i.GetComponent <InventoryStackControl>(); scrpt.IncreaseStack(itemPack.Amount); return; } if (GameData.instance.currentSlot < 2) { GameObject itemToInstantiate = null; if (itemPack.Type == 1) { itemToInstantiate = itemIconDict[itemPack.Id]; } Destroy(primarySlotOne.transform.GetChild(0).gameObject); GameObject i = Instantiate(itemToInstantiate); i.transform.SetParent(primarySlotOne.transform); InventoryStackControl scrpt = i.GetComponent <InventoryStackControl>(); scrpt.IncreaseStack(itemPack.Amount); GameData.instance.weaponHolder.GetComponent <GunControlV2>().EquipWeapon(i); return; } if (GameData.instance.currentSlot == 2) { GameObject itemToInstantiate = null; if (itemPack.Type == 1) { itemToInstantiate = itemIconDict[itemPack.Id]; } Destroy(primarySlotTwo.transform.GetChild(0).gameObject); GameObject i = Instantiate(itemToInstantiate); i.transform.SetParent(primarySlotTwo.transform); InventoryStackControl scrpt = i.GetComponent <InventoryStackControl>(); scrpt.IncreaseStack(itemPack.Amount); GameData.instance.weaponHolder.GetComponent <GunControlV2>().EquipWeapon(i); return; } } if (weaponPack.WeaponType == 2) { if (secondarySlot.transform.childCount == 0) { return; } } if (weaponPack.WeaponType == 3) { CheckSlots(object_, explosiveInventory); return; } //// } else { CheckSlots(object_, Inventory); } }