public void ShowAll() { for (int i = 0; i < transform.childCount; i++) { InventoryItemButton thisItem = transform.GetChild(i).GetComponent <InventoryItemButton>(); thisItem.gameObject.SetActive(true); } }
private void AddButton(InventoryItem item) { InventoryItemButton newButton = GameObject.Instantiate(m_InventoryItemButtonPrefab, m_RectTransform); newButton.Initialize(m_WorldObjectBuilder, item); m_Buttons.Add(newButton); }
// Start is called before the first frame update public void ShowOnly(int itemType) { for (int i = 0; i < transform.childCount; i++) { InventoryItemButton thisItem = transform.GetChild(i).GetComponent <InventoryItemButton>(); thisItem.gameObject.SetActive(thisItem.typeIndex == itemType); } }
public override void OnInspectorGUI() { _target = (InventoryItemButton)target; serializedObject.Update(); EditorGUILayout.Space(); _target.iconImage = (Image)EditorGUILayout.ObjectField("Icon Image", _target.iconImage, typeof(Image), true); _target.bgImage = (Image)EditorGUILayout.ObjectField("Bg Image", _target.bgImage, typeof(Image), true); EditorGUILayout.Space(); serializedObject.ApplyModifiedProperties(); base.OnInspectorGUI(); }
void RemoveItemUI(InventoryItem item) { foreach (Transform child in InventoryContent) { InventoryItemButton inventoryItemButton = child.GetComponent <InventoryItemButton>(); if (item == inventoryItemButton.Item) { Destroy(child.gameObject); } } ItemCountText.text = _inventory.GetItems().Count - 1 + "/" + _inventory.InventoryCapacity; }
void useItem(InventoryItemButton slot) { if (slot.Item.Item == null) { return; } SelectedConsumable = (ConsumableItemData)slot.Item.Item; //make the player select a character _eventSystem.SetSelectedGameObject(Player1); }
void UpdateItemUI(InventoryItem inventoryItem, int amount) { foreach (Transform child in InventoryContent.transform) { //get child with the item InventoryItemButton inventoryItemButton = child.GetComponent <InventoryItemButton>(); if (inventoryItemButton.Item == inventoryItem) { //get item panel child.transform.GetChild(0).GetChild(0).GetComponent <Text>().text = "x" + (inventoryItemButton.Item.Amount + amount); } } }
// Update is called once per frame public void ShowAll() { for (int i = 0; i < transform.childCount; i++) { InventoryItemButton thisItem = transform.GetChild(i).GetComponent <InventoryItemButton>(); if (thisItem != null) { thisItem.gameObject.SetActive(true); } else { print("Couldn't find an InventoryItemButton."); } } }
// Use this for initialization void Start() { int length = Inventory.myInv.itemArray.Length; for (int x = 0; x < length; ++x) { GameObject newButton = (GameObject)Instantiate(buttonPrefab, Vector3.zero, Quaternion.identity); InventoryItemButton buttonScript = newButton.GetComponent <InventoryItemButton>(); newButton.transform.SetParent(gameObject.transform); newButton.transform.localScale = new Vector3(1.0f, 1.0f, 1.0f); newButton.transform.localPosition = new Vector3(0.0f, 0.0f, 0.0f); newButton.transform.rotation = new Quaternion(0.0f, 0.0f, 0.0f, 0.0f); buttonScript.SetIndex(x); } }
private void AddInventoryItems() { foreach (int key in inventoryItems.Keys) { //if quantity > 0 if (inventoryItems[key] > 0) { WearableItem item = wearableDB.wearableItemDatabase.First(x => x.id == key); GameObject newButton = buttonObjectPool.GetObject(); newButton.transform.SetParent(contentPanel); InventoryItemButton itemButton = newButton.GetComponent <InventoryItemButton>(); itemButton.Setup(item, this); } } }
void OnEnable() { goldCount.text = PlayerStatus.GoldCount.ToString(); resourcesCount.text = PlayerStatus.ResourcesCount.ToString(); foreach (GameItem thisItem in PlayerStatus.Inventory.inventoryList) { if (thisItem.quantity != 0) { GameObject button = (GameObject)GameObject.Instantiate(invItemButton); //Make a copy of the base dialogue button button.SetActive(true); //As the base button is not active, new button must be set active button.transform.SetParent(invLayoutPanel.transform); //Set its parent to the dialogue panel button.tag = "ToDestroy"; InventoryItemButton inventoryItemButton = button.GetComponent <InventoryItemButton>(); //Get a reference to its script inventoryItemButton.SetVars(thisItem); } } }
public void Inspect(InventoryItemButton inventoryItemButton) { if (inventoryItemButton == null) { SelectedItem = null; ItemName.text = ""; ItemImage.enabled = false; ItemDescription.text = ""; UseButton.interactable = false; DropButton.interactable = false; return; } SelectedItem = inventoryItemButton; var item = inventoryItemButton.Item; ItemName.text = item.ColoredInspectorName; ItemImage.enabled = true; ItemImage.sprite = item.Base.itemIcon; ItemDescription.text = item.InspectorDescription; if (item is Equippable equippable) { EquipStatsText.gameObject.SetActive(true); Separator.SetActive(true); EquipStatsText.text = equippable.StatsDescription; } else { EquipStatsText.gameObject.SetActive(false); Separator.SetActive(false); } UseButton.interactable = item is Consumable consumable && consumable.ConsumableBase.ConsumableUses.Any() /*|| item is Equippable*/; DropButton.interactable = item.Base.droppable; }
void removeSlot(InventoryItemButton slot) { slot.Item = null; slot.Inventory = null; slot.GetComponent <Image>().sprite = BaseSlotSprite; }
public void ScrollButtons(Vector2 moveValue, Vector2 incrementValue, int VisibleButton, int MovedInvsButton, int ItemIndexModifier, Vector2 InvsDestination) { List <GameObject> _Buttons = new List <GameObject>(); List <Item> _Items = new List <Item>(); switch (currentMenu) { case ListType.Items: _Buttons = ButtonsHor; _Items = Items; break; case ListType.Combat: break; case ListType.KeyItems: _Buttons = ButtonsHor; _Items = KeyItems; break; } InventoryItemButton newItemButton = _Buttons[VisibleButton].GetComponent <InventoryItemButton>(); if (VisibleButton == 8) { // right or up if (newItemButton.itemIndex < _Items.Count) { newItemButton.item = _Items[newItemButton.itemIndex]; } else { //already hit minimum newItemButton.item = _Items[0]; newItemButton.itemIndex = 0; } } else { //left or down if (newItemButton.itemIndex >= 0) { newItemButton.item = _Items[newItemButton.itemIndex]; } else { //already passed minimum newItemButton.item = _Items[_Items.Count - 1]; newItemButton.itemIndex = _Items.Count - 1; } } newItemButton.SetGraphic(); // StartCoroutine(LockInputTimer(Speed * 2)); //StartCoroutine(LockButtons(_Buttons)); for (int i = 0; i < _Buttons.Count; i++) { if (i == MovedInvsButton) { continue; } //if (i == VisibleButton) ButtonOpacity(_Buttons[i], 1f); LeanTween.moveLocal(_Buttons[i], new Vector2(moveValue.x, moveValue.y), Speed); moveValue.x += incrementValue.x; moveValue.y += incrementValue.y; } LeanTween.moveLocal(_Buttons[MovedInvsButton], InvsDestination, 0.0f); GameObject button = _Buttons[MovedInvsButton]; _Buttons.RemoveAt(MovedInvsButton); if (VisibleButton == 8) { //Right _Buttons.Add(button); } else {//left _Buttons.Insert(0, button); } InventoryItemButton movedButton = _Buttons[VisibleButton].GetComponent <InventoryItemButton>(); movedButton.item = null; movedButton.SetGraphic(); movedButton.itemIndex = newItemButton.itemIndex + ItemIndexModifier; StartCoroutine(DelayedFunction(RedoButtonIndex, Speed + 0.001f)); //ButtonOpacity(_Buttons[MovedInvsButton], 0f); }
public void CreateButtons(ListType listType, bool Horizontal = true) { EventSystem.current.SetSelectedGameObject(null); List <GameObject> Buttons = new List <GameObject>(); List <Item> _Items = new List <Item>(); Buttons = ButtonsHor; switch (listType) { case ListType.Items: Buttons = ButtonsHor; currentMenu = ListType.Items; MenuName.text = "Items"; _Items = Items; break; case ListType.Combat: MenuName.text = "Weapons"; _Items = CombatItems; currentMenu = ListType.Combat; break; case ListType.KeyItems: MenuName.text = "Key Items"; Buttons = ButtonsHor; _Items = KeyItems; currentMenu = ListType.KeyItems; break; } //LeanTween.value(FG.gameObject, (Color x) => FG.color = x, FG.color, FGtarget, duration); LeanTween.value(MenuName.gameObject, (float x) => MenuName.maxVisibleCharacters = (int)x, 0, MenuName.text.Length, 0.3f); int q = -150; int t = 0; int index = 0; bool StopContinueOnce = true; for (int i = 0; i <= 8; i++) { Buttons[i].SetActive(true); InventoryItemButton Button = Buttons[i].GetComponent <InventoryItemButton>(); Button.buttonIndex = i; if (i == 0 || i == 8 || i >= _Items.Count) { Button.item = null; Button.SetGraphic(); if (_Items.Count < 8) { Buttons[i].SetActive(false); } if (i >= _Items.Count && _Items.Count < 8 && StopContinueOnce) { StopContinueOnce = false; Buttons[i].SetActive(true); } else { //ButtonOpacity(Buttons[i], 0f); /* * Color BGtarget = Button.GetComponent<Image>().color; * BGtarget.a = 0; * Image BG = Button.GetComponent<Image>(); * BG.color = BGtarget; * * Image FG = Button.transform.GetChild(0).GetComponent<Image>(); * Color FGtarget = FG.color; * FGtarget.a = 0; * FG.color = FGtarget; */ continue; } } Button.transform.position = CenterPoint.transform.position; //ButtonOpacity(Buttons[i], 1f); if (Horizontal) { LeanTween.moveLocalX(Button.gameObject, q, 0.3f).setEase(LeanTweenType.easeOutQuad).setDelay(0.3f); } else { LeanTween.moveLocalY(Button.gameObject, q, 0.3f).setEase(LeanTweenType.easeOutQuad).setDelay(0.3f); } if (Horizontal) { q += 50; } else { q += 50; } Button.item = _Items[t]; Button.itemIndex = t; t++; Button.SetGraphic(); if (i < 5) { index++; } } if (currentMenu == ListType.Combat) { SelectedItem = index; } else { SelectedWeapon = index; } StartCoroutine(DelayedFunction(Buttons[index].GetComponent <Button>().Select, 0.4f)); //StartCoroutine( DelayedFunction(Buttons[index].GetComponent<InventoryItemButton>().OnSelect(null), 0.3f)); //Buttons[index].GetComponent<Button>().Select(); //Buttons[index].GetComponent<InventoryItemButton>().OnSelect(null); }
/// <summary>Function called externally from UI buttons to only display items of the given type in the inventory</summary> /// <param name="typeID_">Integer for the type of item to show. 0 - All, 1 - Weapon, 2 - Armor, 3 - Consumable, 4 - Quest, 5 - Misc</param> public void ShowFilteredItems(int typeID_) { //Deleting all buttons except for our default button Transform parentT = this.itemButton.gameObject.transform.parent; List <GameObject> childToDestroy = new List <GameObject>(); for (int child = 0; child < parentT.childCount; child++) { if (parentT.GetChild(child).GetComponent <Button>() && parentT.GetChild(child) != this.itemButton.transform) { childToDestroy.Add(parentT.GetChild(child).gameObject); } } for (int d = 0; d < childToDestroy.Count; d++) { Destroy(childToDestroy[d]); childToDestroy[d] = null; } //Creating a new button for each item in the inventory int itemCount = 0; for (int i = 0; i < PartyGroup.globalReference.inventory.itemSlots.Count; i++) { if (PartyGroup.globalReference.inventory.itemSlots[i] != null) { bool validItem = false; //Checking to see if the item matches the designated type we're searching for switch (typeID_) { case 0: itemCount++; validItem = true; break; case 1: if (PartyGroup.globalReference.inventory.itemSlots[i].GetComponent <Weapon>()) { itemCount++; validItem = true; } break; case 2: if (PartyGroup.globalReference.inventory.itemSlots[i].GetComponent <Armor>()) { itemCount++; validItem = true; } break; case 4: if (PartyGroup.globalReference.inventory.itemSlots[i].GetComponent <QuestItem>()) { itemCount++; validItem = true; } break; default: if (PartyGroup.globalReference.inventory.itemSlots[i].GetComponent <Weapon>()) { break; } else if (PartyGroup.globalReference.inventory.itemSlots[i].GetComponent <Armor>()) { break; } else if (PartyGroup.globalReference.inventory.itemSlots[i].GetComponent <QuestItem>()) { break; } else { itemCount++; validItem = true; } break; } //If the current item matches the type we're looking for, we create a new button for it if (validItem) { //If this is the first valid item found, we enable the default item button if (itemCount == 1) { this.itemButton.gameObject.SetActive(true); this.itemButton.itemIndex = i; this.itemButton.itemNameText.text = PartyGroup.globalReference.inventory.itemSlots[i].itemNameID; this.itemButton.itemQuantityText.text = PartyGroup.globalReference.inventory.itemSlots[i].currentStackSize + ""; this.itemButton.inventoryScreenRef = this; } //Otherwise we have to create a new button for the item else { GameObject newButtonObj = GameObject.Instantiate(this.itemButton.gameObject, this.itemButton.gameObject.transform.parent); InventoryItemButton newButton = newButtonObj.GetComponent <InventoryItemButton>(); newButton.itemIndex = i; newButton.itemNameText.text = PartyGroup.globalReference.inventory.itemSlots[i].itemNameID; newButton.itemQuantityText.text = PartyGroup.globalReference.inventory.itemSlots[i].currentStackSize + ""; newButton.inventoryScreenRef = this; } } } } //If there are no valid items found, the default item button is hidden if (itemCount == 0) { this.itemButton.gameObject.SetActive(false); } }
public void Inspect(InventoryItemButton item) { InventoryItemInspector.Inspect(item); }