YanCheng_Metrology/Assets/Scripts/Project/UI/UI_Item/UI_ToolOrMaterialsOrDeviceI...

65 lines
2.5 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":
if (GameManager.ProcessMgr.IsRightSubProcessStepsTriggerID(currentItem.triggerID, true) == 0)
{
GameManager.UIMgr.HidePanel<UI_ToolAndMaterialPanel>();
GameObject currentTool = Instantiate(currentItem.objPrefab);
currentTool.GetComponent<BaseToolOrDevice>().enabled = false;
currentTool.GetComponent<Collider>().enabled = false;
currentTool.name = currentItem.toolName;
LiveSceneManager.Instance.SetSpawnToolInfo(currentTool);
}
break;
}
}
}