private void Awake() { if (instance == null) { instance = this; } else if (instance != this) { Destroy(gameObject); } //DontDestroyOnLoad(gameObject); slots = new List <GameObject>(); for (int i = 0, max = transform.childCount; i < max; i++) { slots.Add(transform.GetChild(i).gameObject); slots[i].GetComponent <Item_string>().code = null; } }
public void ItemAdded(string currentitem) //might tweak so that it pulls from the list of items instead. { if (removeditems.Count > 0) //this is checking if there's any refill spots left by removed items first { UIimageSet(currentitem); Slots[removeditems[0]] = new Itemslot(currentitem, removeditems[0]); //makes the removed item area the item removeditems.RemoveAt(0); //got to remove that place now since its filled and to move onto the next place } else { if (slotnumber < 9)//fully putting item into registry unless full { UIimageSet(currentitem); Slots.Add(new Itemslot(currentitem, slotnumber)); slotnumber += 1; } else { Debug.Log("Your inventory is full"); } } }
public void OnPointerClick(BaseEventData Data) { Debug.Log("클릭"); Item_string item = this.GetComponent <Item_string>(); PointerEventData eventData = Data as PointerEventData; if (eventData.button == PointerEventData.InputButton.Left) { Debug.Log("왼쪽클릭"); if (Inventory.instance.isSHOP == false) { if (item.code != null) { if (item.code.Substring(0, 1) == "2") { //퀵슬롯에 아이템이 있으면 감소 for (int i = 0; i < Itemslot.instance.slots.Count; i++) { if (Itemslot.instance.slots[i].GetComponent <Item_string>().code != null) { if (Itemslot.instance.slots[i].GetComponent <Item_string>().code.Equals(this.GetComponent <Item_string>().code)) { Itemslot.instance.slots[i].GetComponent <ItemquickSlot>().minus_item(Itemslot.instance.slots[i].GetComponent <Item_string>()); break; } } } //인벤토리의 아이템을 감소 & consume실행 Inventory.instance.player.Consume(false, item.code.Substring(0, 4), InventorySlot.GetType(item.code), ItemManager.instance.GetOpt1_1(int.Parse(item.code.Substring(0, 5))), ItemManager.instance.GetOpt2_1(int.Parse(item.code.Substring(0, 5)))); int count = int.Parse(item.code.Substring(5, 2)) - 1; string count_string = ((count < 10 ? "0" + count : "" + count)); item.code = Inventory.instance.copy(item.code.Substring(0, 5) + count_string); //해당 슬롯의 갯수출력변경 this.GetComponentInChildren <Text>().text = (int.Parse(item.code.Substring(5, 2)) > 0 ? " " + int.Parse(item.code.Substring(5, 2)) : " "); if (count <= 0) { Inventory.instance.pop_list(this.GetComponent <index>().Index); return; } } } } } if (eventData.button == PointerEventData.InputButton.Right) { //오른쪽클릭 Debug.Log("오른쪽 클릭"); if (Inventory.instance.isSHOP == false) {//아이템 장착 및 소비 if (item.code == null) { return; } if (int.Parse(item.code.Substring(0, 1)) < 3) { switch (item.code.Substring(0, 1)) { case "2": Itemslot.Add(this.gameObject); /*int count = int.Parse(item.code.Substring(5,2)) - 1; * this.GetComponentInChildren<Text>().text = (count > 0 ? " " + count : " "); * * if (count < 1) * { * Inventory.instance.pop_list(this.GetComponent<index>().Index); * } * else * item.code = item.code.Substring(0, 5) + (count < 10 ? "0" + count : "" + count); */ break; case "1": Debug.Log("이큅 실행"); equip(item); break; } } } else { GameObject slotnow = null; //돈버는 코드 필요 for (int i = 0; i < Itemslot.instance.slots.Count; i++) { slotnow = Itemslot.instance.slots[i]; if (slotnow.GetComponent <Item_string>().code.Equals(item.code)) { slotnow.GetComponent <Item_string>().code = null; slotnow.GetComponent <Image>().sprite = Inventory.instance.defaultImage; slotnow.GetComponentInChildren <Text>().text = " "; break; } } Inventory.instance.pop_list(this.GetComponent <index>().Index); } } }