|
|
|
|
@ -0,0 +1,57 @@
|
|
|
|
|
using System.Collections;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using UnityEngine;
|
|
|
|
|
using UnityEngine.UI;
|
|
|
|
|
|
|
|
|
|
public class InventoryManager : MonoBehaviour
|
|
|
|
|
{
|
|
|
|
|
static InventoryManager instance;
|
|
|
|
|
|
|
|
|
|
public Inventory myBag;
|
|
|
|
|
public GameObject slotGrid;
|
|
|
|
|
// public Slot slotPrefab;
|
|
|
|
|
public GameObject emptySlot;
|
|
|
|
|
public Text itemInfomation;
|
|
|
|
|
|
|
|
|
|
public List<GameObject> slots = new List<GameObject>();
|
|
|
|
|
|
|
|
|
|
void Awake()
|
|
|
|
|
{
|
|
|
|
|
if (instance != null)
|
|
|
|
|
Destroy(this);
|
|
|
|
|
instance = this;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void OnEnable()
|
|
|
|
|
{
|
|
|
|
|
RefreshItem();
|
|
|
|
|
instance.itemInfomation.text = "这里是物品描述。";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static void UpdateItemInfo(string itemDescription)
|
|
|
|
|
{
|
|
|
|
|
instance.itemInfomation.text = itemDescription;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static void RefreshItem()
|
|
|
|
|
{
|
|
|
|
|
// 循环删除slotGrid下的子集物品
|
|
|
|
|
for (int i = 0; i < instance.slotGrid.transform.childCount; i++)
|
|
|
|
|
{
|
|
|
|
|
if(instance.slotGrid.transform.childCount == 0)
|
|
|
|
|
break;
|
|
|
|
|
Destroy(instance.slotGrid.transform.GetChild(i).gameObject);
|
|
|
|
|
instance.slots.Clear(); // 清空slots列表
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 重新生成对应背包中物品的slot
|
|
|
|
|
for (int i = 0; i < instance.myBag.itemList.Count; i++)
|
|
|
|
|
{
|
|
|
|
|
instance.slots.Add(Instantiate(instance.emptySlot));
|
|
|
|
|
instance.slots[i].transform.SetParent(instance.slotGrid.transform);
|
|
|
|
|
instance.slots[i].GetComponent<Slot>().slotIndex = i;
|
|
|
|
|
instance.slots[i].GetComponent<Slot>().SetupSlot(instance.myBag.itemList[i]);
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|