using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.EventSystems; using UnityEngine.UI; namespace Assets.Scripts { public class Inventory : MonoBehaviour { public GameObject head; public GameObject chest; public GameObject shoulders; public GameObject feet; public GameObject ring; public GameObject amulet; public GameObject leftHand; public GameObject rightHand; public GameObject[] bags; public GameObject[] slots; public int currentBag = -1; GameObject startDrag; // Start is called before the first frame update void Start() { changeCurrentBag(0); } // Update is called once per frame void Update() { checkInventoryColors(); checkEquipColors(); } public void addItem(Item item) { if (item != null) { GameObject.Find("UIHandler").GetComponent().showMessage("SUCCESS;You got an item!"); bool itemAdded = false; for (int i = 0; i < bags.Length; i++) { for (int j = 0; j < slots.Length; j++) { if (slots[j].GetComponent().getItem() == null) { slots[j].GetComponent().setItem(item); itemAdded = true; slots[j].GetComponent().color = Color.red; break; } } if (itemAdded) { break; } } } } public void changeCurrentBag(int index) { if (currentBag != -1) { bags[currentBag].GetComponent().color = Color.white; } currentBag = index; bags[currentBag].GetComponent().color = Color.cyan; checkInventoryColors(); foreach(GameObject slot in slots) { slot.GetComponent().updateCurrentBag(currentBag); } } private void checkInventoryColors() { for (int i = 0; i < slots.Length; i++) { if (slots[i].GetComponent().getItem() != null) { slots[i].GetComponent().color = Color.red; } else { slots[i].GetComponent().color = Color.white; } } } private void checkEquipColors() { GameObject slot = head; for (int i = 0; i < 8; i++) { switch (i) { case 0: slot = head; break; case 1: slot = rightHand; break; case 2: slot = leftHand; break; case 3: slot = amulet; break; case 4: slot = feet; break; case 5: slot = shoulders; break; case 6: slot = chest; break; case 7: slot = ring; break; } if (slot.GetComponent().getEquip() != null) { slot.GetComponent().color = Color.red; } else { slot.GetComponent().color = Color.white; } } } public void setDrag(GameObject slot) { startDrag = slot; } public GameObject getDrag() { return startDrag; } public Item getEquip(ItemPlace place) { switch (place) { case ItemPlace.SHIELD: return leftHand.GetComponent().getEquip(); case ItemPlace.WEAPON: return rightHand.GetComponent().getEquip(); case ItemPlace.HELMET: return head.GetComponent().getEquip(); case ItemPlace.BOOTS: return feet.GetComponent().getEquip(); case ItemPlace.SHOULDER: return shoulders.GetComponent().getEquip(); case ItemPlace.AMULET: return amulet.GetComponent().getEquip(); case ItemPlace.RING: return ring.GetComponent().getEquip(); case ItemPlace.ARMOR: return chest.GetComponent().getEquip(); default: return null; } } } }