61 lines
2.4 KiB
C#
61 lines
2.4 KiB
C#
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using Sirenix.OdinInspector;
|
|
using TMPro;
|
|
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
|
|
public class UI_ToolOrMaterialsOrDeviceItem : BaseItem
|
|
{
|
|
public List<ItemInfo> itemInfoList;
|
|
public Button itemCloseBtn;
|
|
private ItemInfo currentItem;
|
|
public void Init(List<ItemInfo> _itemInfo)
|
|
{
|
|
itemInfoList = _itemInfo;
|
|
currentItem = itemInfoList[0];
|
|
if (GameManager.RunModelMgr.ModeType == E_ModeType.Study)
|
|
{
|
|
itemCloseBtn.gameObject.SetActive(false);
|
|
}
|
|
if (GameManager.RunModelMgr.SceneType != E_SceneType.Site)
|
|
{
|
|
GetControl<Image>("iconBtn").GetComponent<Button>().interactable = false;
|
|
}
|
|
GetControl<TextMeshProUGUI>("countText").text = _itemInfo.Count.ToString();
|
|
GetControl<Image>("iconBtn").sprite = Resources.Load<Sprite>(Const.LoadToolAndMaterialPath + currentItem.toolName);
|
|
|
|
}
|
|
|
|
protected override void OnClick(string btnName)
|
|
{
|
|
base.OnClick(btnName);
|
|
switch (btnName)
|
|
{
|
|
case "itemCloseBtn":
|
|
int counts = 0; ;
|
|
if (itemInfoList.Count > 1)
|
|
{
|
|
counts = itemInfoList.Count - 1;
|
|
}
|
|
GameObject obj = Instantiate(itemInfoList[counts].objPrefab);
|
|
obj.transform.position = itemInfoList[counts].selfPosInToolRoom;
|
|
obj.name = itemInfoList[counts].toolName;
|
|
obj.GetComponent<Tool_SelectComponent>().itemInfo = itemInfoList[counts];
|
|
GameManager.PacksackBagMgr.RemoveOneToolOrMater(itemInfoList[counts]);
|
|
itemInfoList.Remove(itemInfoList[counts]);
|
|
GetControl<TextMeshProUGUI>("CountText").text = itemInfoList.Count.ToString();
|
|
if (itemInfoList.Count == 0)
|
|
Destroy(gameObject);
|
|
break;
|
|
case "iconBtn":
|
|
GameManager.UIMgr.HidePanel<UI_ToolAndMaterialPanel>();
|
|
GameObject currentTool = Instantiate(currentItem.objPrefab);
|
|
currentTool.name = currentItem.toolName;
|
|
Vector3 pos = Camera.main.transform.position + Camera.main.transform.forward * 0.3f;
|
|
currentTool.transform.position = new Vector3(pos.x+0.2f, pos.y-0.14f, pos.z+0.1f);
|
|
break;
|
|
}
|
|
}
|
|
}
|