using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.EventSystems; using UnityEngine.UI; namespace Assets.Scripts { public class InventorySlot : MonoBehaviour { TooltipHandler tooltip; Item[] items = new Item[3]; public bool[] itemRemoved = {false, false, false}; int currentBag = 0; public ItemPlace place; Item equip; private void Start() { tooltip = GameObject.Find("TooltipHandler").GetComponent(); } public void updateCurrentBag(int currentBag) { this.currentBag = currentBag; } public void setItem(Item item) { items[currentBag] = item; itemRemoved[currentBag] = false; } public Item getItem() { return items[currentBag]; } public void removeItem() { items[currentBag] = null; itemRemoved[currentBag] = true; } public void showTooltip() { if (place == ItemPlace.BAG) { if (items[currentBag] != null) { string text = items[currentBag].getDisplayText(); Item equip = GameObject.Find("Inventory").GetComponent().getEquip(items[currentBag].getPlace()); if (equip != null) { text = "(Current)\r\n" + equip.getDisplayText() + "----------\r\n" + text; } tooltip.showTooltip(text); } } else { if (equip != null) { tooltip.showTooltip(equip.getDisplayText()); } } } public void hideTooltip() { tooltip.hideToolTip(); } public void onClick() { removeItem(); tooltip.hideToolTip(); } public void OnMouseDrag() { GameObject.Find("Inventory").GetComponent().setDrag(gameObject); } public void OnMouseUp() { GameObject startDrag = GameObject.Find("Inventory").GetComponent().getDrag(); Item item; bool isSwap = false; if (startDrag.GetComponent().place == ItemPlace.BAG) { item = startDrag.GetComponent().getItem(); } else { item = startDrag.GetComponent().getEquip(); } if (item != null) { if (place != item.getPlace() && place != ItemPlace.BAG) { return; } if (place == ItemPlace.BAG) { if (items[currentBag] != null) { startDrag.GetComponent().setItem(items[currentBag]); isSwap = true; } setItem(item); } else { if (equip != null) { if (startDrag.GetComponent().place == ItemPlace.BAG) { startDrag.GetComponent().setItem(equip); isSwap = true; } else { return; } } setEquip(item); } if (!isSwap) { if (startDrag.GetComponent().place != ItemPlace.BAG) { startDrag.GetComponent().removeEquip(); } else { startDrag.GetComponent().removeItem(); } } } } public Item getEquip() { return equip; } public void setEquip(Item item) { equip = item; } public void removeEquip() { equip = null; } } }