-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathInventoryUI.cs
106 lines (96 loc) · 2.83 KB
/
InventoryUI.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.Events;
using System;
public class InventoryUI : UIBase
{
// Start is called before the first frame update
GameObject playerOBJ;
ItemInventory playerInven;
public GameObject SlotPrefab;
List<GameObject> slotList = new List<GameObject>();
public List<ItemSlot> slotScripts = new List<ItemSlot>();
protected override void Start()
{
setKey = KeyCode.I;
Debug.Log(setKey);
base.Start();
}
private void Awake()
{
InstantSlot();
}
// Update is called once per frame
void Update()
{
}
private void OnEnable()
{
OpenInventory(0);
}
private void OnDisable()
{
CloseInventory();
}
void InstantSlot()
{
if (playerInven == null)
{
playerInven = GameManager.instance.playerState.myInventory;
}
for (int i = slotList.Count; i < 40; i++)
{
GameObject go = Instantiate(SlotPrefab);
slotList.Add(go);
go.transform.SetParent(this.transform);
ItemSlot slotScrip = go.transform.GetComponent<ItemSlot>();
slotScrip.slotNumber = i;
slotScripts.Add(slotScrip);
}
}
void SetPlayerOBJ()
{
playerOBJ = GameManager.instance.playerObj;
playerInven = playerOBJ.transform.GetComponent<ItemInventory>();
}
public void OpenInventory(int start)
{
for (int i = start; i < playerInven.Inventory.Count; i++)
{
slotScripts[i].slotItem = playerInven.Inventory[i];
if (playerInven.Inventory[i] == null)
{
slotScripts[i].slotItem = null;
slotScripts[i].itemImage.sprite = null;
slotScripts[i].tmp.text = null;
}
//slotScripts[i].inventoryButton.onClick.RemoveAllListeners();
slotScripts[i].SetSlot(i);
slotScripts[i].invenUI = this;
}
}
public void CloseInventory()
{
for (int i = 0; i < playerInven.Inventory.Count; i++)
{
Button button = slotScripts[i].gameObject.transform.GetComponent<Button>();
Image image = slotScripts[i].gameObject.transform.GetComponent<Image>();
slotScripts[i].itemImage = null;
if (button.onClick != null)
{
button.onClick.RemoveAllListeners();
}
image.sprite = null;
}
}
public void RemoveLastIndex()
{
int index = playerInven.Inventory.Count;
slotScripts[index].itemImage.sprite = null;
slotScripts[index].slotItem = null;
slotScripts[index].tmp.text = null;
slotScripts[index].slotImage.color = Color.white;
}
}