private void ActivateSlots(int capacity, ItemPickable[] item, StorageViewable storage) { Clear(); for (int i = 0; i < capacity; i++) { InventorySlotManager Slot = transform.GetChild(i).gameObject.GetComponent <InventorySlotManager>(); Slot.Active = true; Slot.GetComponent <RawImage>().color = Active_Color; if (item[i] != null) { GameObject itemObject = new GameObject(); ItemSprite itemSprite = itemObject.AddComponent <ItemSprite>(); RawImage image = itemObject.AddComponent <RawImage>(); itemSprite.Reference = item[i].gameObject; itemSprite.Quantity = item[i].Quantity; image.texture = item[i].ItemIcon; image.SetNativeSize(); itemObject.name = item[i].name; itemObject.transform.SetParent(Slot.transform, false); try { item[i].gameObject.GetComponent <Collider>().enabled = false; item[i].gameObject.GetComponent <MeshRenderer>().enabled = false; } catch (Exception e) { item[i].gameObject.SetActive(false); } } } CheckDropForInActive(); }
/* private void Debug() { * print("Slot Index " + i); * print("Slot Active " + Slot.Active); * print("Slot Child Count " + Slot.transform.childCount); * print("Item Pickable " + itemPickable.Stackable); * print("Limit of Stack " + limitOfStack); * print("IgnoreCommonItems " + ignoreCommonItems); * print("Quantity " + quantity); * }*/ private void Single_AddToSlot(ItemPickable itemPickable, InventorySlotManager Slot) { GameObject item = new GameObject(); ItemSprite itemSprite = item.AddComponent <ItemSprite>(); RawImage image = item.AddComponent <RawImage>(); itemSprite.Reference = itemPickable.gameObject; itemSprite.Quantity = 1; image.texture = itemPickable.ItemIcon; image.SetNativeSize(); image.rectTransform.sizeDelta = new Vector2(80, 80); if (itemPickable.transform.gameObject.GetComponent <ItemBlock>() != null) { item.name = itemPickable.transform.gameObject.GetComponent <ItemBlock>().BlockName; } else { item.name = itemPickable.gameObject.name; } item.transform.SetParent(Slot.transform, false); try { itemPickable.gameObject.GetComponent <Collider>().enabled = false; itemPickable.gameObject.GetComponent <MeshRenderer>().enabled = false; } catch (Exception) { itemPickable.gameObject.SetActive(false); } Refresh(); }
public void ClearInventory() { for (int i = 0; i < 40; i++) { InventorySlotManager tempInventorySlots = transform.Find("ItemSlots").Find("ItemGrid").Find(string.Format("Slot{0}", i)).GetComponent <InventorySlotManager> (); tempInventorySlots.RemoveItem(); } }
private void Clear() { for (int i = 0; i < transform.childCount; i++) { InventorySlotManager Slot = transform.GetChild(i).gameObject.GetComponent <InventorySlotManager>(); Slot.Active = false; Slot.GetComponent <RawImage>().color = InActive_Color; } }
private void CheckDropForInActive() { for (int i = 0; i < transform.childCount; i++) { InventorySlotManager Slot = transform.GetChild(i).gameObject.GetComponent <InventorySlotManager>(); if (!Slot.Active && Slot.transform.childCount > 0) { Slot.DropItems(); } } }
public void Initialize() { Clear(); for (int i = 0; i < UI.root.playerInventory.ActiveInventorySlots; i++) { InventorySlotManager Slot = transform.GetChild(i).gameObject.GetComponent <InventorySlotManager>(); Slot.Active = true; Slot.GetComponent <RawImage>().color = Active_Color; } CheckDropForInActive(); }
private void ActivateSlots(int ActiveInventorySlots) { Clear(); for (int i = 0; i < ActiveInventorySlots; i++) { InventorySlotManager Slot = transform.GetChild(i).gameObject.GetComponent <InventorySlotManager>(); Slot.Active = true; Slot.GetComponent <RawImage>().color = Active_Color; } CheckDropForInActive(); }
public void MoveItemToInventory(ItemPickable itemPickable, int quantity, bool ignoreCommonItems) { //print(" Moving... " + held); if (held < ActiveInventorySlots) { FullInventory = false; for (int i = 0; i < UI.root.InventorySlotGrid.transform.childCount; i++) { InventorySlotManager Slot = UI.root.InventorySlotGrid.transform.GetChild(i).GetComponent <InventorySlotManager>(); //print("here " + i + " child count: " + Slot.transform.childCount); bool limitOfStack = false; try { limitOfStack = Slot.transform.GetChild(0).GetComponent <ItemSprite>().QuantityChange(quantity, itemPickable); // true --> can change + quantity } catch (Exception) { } if (Slot.Active && Slot.transform.childCount == 0 && quantity == 1) { // Checking if Single and not filled Single_AddToSlot(itemPickable, Slot); //print("Here"); break; } if (Slot.Active && (Slot.transform.childCount == 0) && itemPickable.Stackable && !ignoreCommonItems && quantity > 1) { MultipleInit_AddToSlot(itemPickable, Slot, quantity); break; } if (Slot.transform.childCount >= 1) { if (Slot.Active && (Slot.transform.GetChild(0).GetComponent <ItemSprite>().Reference.name == itemPickable.name) && itemPickable.Stackable && limitOfStack && !ignoreCommonItems) { // Checking if same item and stackable Multiple_AddToSlot(itemPickable, Slot, quantity); break; } } if (Slot.Active && (Slot.transform.childCount == 0) && itemPickable.Stackable && limitOfStack && ignoreCommonItems) { // Checking if same item and stackable Multiple_AddToSlot(itemPickable, Slot, quantity); break; } } } else { FullInventory = true; Show_InventoryFullDialogBox(); } }
void Update() { ClearInventory(); numOfItems = 0; inventoryDictionary = GameObject.FindGameObjectWithTag("Player").GetComponent <Player>().getInventory().GetInventory(); Dictionary <GameObject, int> .KeyCollection tempInventoryHolder = inventoryDictionary.Keys; if (tempInventoryHolder != null) { foreach (GameObject item in tempInventoryHolder) { InventorySlotManager slot = transform.Find("ItemSlots").Find("ItemGrid").Find(string.Format("Slot{0}", numOfItems)).GetComponent <InventorySlotManager> (); slot.InsertItem(item, inventoryDictionary [item]); numOfItems++; } } }
private void Multiple_AddToSlot(ItemPickable item, InventorySlotManager Slot, int quantity) { Slot.transform.GetChild(0).GetComponent <ItemSprite>().QuantityChangeImplicit(quantity); Destroy(item.gameObject); }