1
This commit is contained in:
53
unity/Assets/Script/UI/Bag/CanUseItem.cs
Normal file
53
unity/Assets/Script/UI/Bag/CanUseItem.cs
Normal file
@@ -0,0 +1,53 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
public class CanUseItem : MonoBehaviour
|
||||
{
|
||||
public Transform rectTransfrom;
|
||||
|
||||
public Text UpItemNum;
|
||||
private void OnEnable()
|
||||
{
|
||||
PlayerInfo.Instance.OnUpdateMainUI += UpdateUI;
|
||||
UpdateUI();
|
||||
}
|
||||
private void OnDisable()
|
||||
{
|
||||
PlayerInfo.Instance.OnUpdateMainUI -= UpdateUI;
|
||||
}
|
||||
public void UpdateUI()
|
||||
{
|
||||
foreach (Transform item in rectTransfrom)
|
||||
{
|
||||
Destroy(item.gameObject);
|
||||
}
|
||||
if(PlayerInfo.Instance.info.BagInfo.Count==0|| !PlayerInfo.Instance.info.BagInfo.ContainsKey(0))//背包中没有道具
|
||||
{
|
||||
UpItemNum.text = "0";
|
||||
}
|
||||
foreach (var item in PlayerInfo.Instance.info.BagInfo)
|
||||
{
|
||||
if(item.Key==Date.Instance.ItemDate[0].Id)//背包中道具Id等于道具表中的升级道具
|
||||
{
|
||||
UpItemNum.text = item.Value.ToString();
|
||||
}
|
||||
|
||||
if(Date.Instance.ItemDate[item.Key].type==ItemClass.User)//能够使用的道具
|
||||
{
|
||||
string path = "UI/Perfab/Item";
|
||||
UnityEngine.Object go = Resloader.Load<GameObject>(path);
|
||||
if (go != null)//预制体不为空
|
||||
{
|
||||
GameObject m = (GameObject)Instantiate(go, rectTransfrom);
|
||||
UIItemInfo ui = m.GetComponent<UIItemInfo>();
|
||||
ui.gameObject.SetActive(true);
|
||||
|
||||
ui.SetInfo(item.Key, item.Value);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user