128 lines
5.8 KiB
C#
128 lines
5.8 KiB
C#
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using Sirenix.OdinInspector;
|
|
using TMPro;
|
|
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
|
|
public class UI_ToolOrMaterialsOrDeviceItem : BaseItem
|
|
{
|
|
private HashSet<string> validToolNames = new HashSet<string> { "国网安全帽", "编织手套", "绝缘靴", "工作服","护目镜" };
|
|
public List<ItemInfo> itemInfoList;
|
|
public Button itemCloseBtn;
|
|
private ItemInfo currentItem;
|
|
public void Init(List<ItemInfo> _itemInfo)
|
|
{
|
|
itemInfoList = _itemInfo;
|
|
currentItem = itemInfoList[0];
|
|
if (GameManager.RunModelMgr.SceneType != E_SceneType.Site)
|
|
{
|
|
GetControl<Image>("iconBtn").GetComponent<Button>().interactable = false;
|
|
}
|
|
else
|
|
{
|
|
if (validToolNames.Contains(currentItem.toolName))
|
|
GetControl<Image>("iconBtn").GetComponent<Button>().interactable = false;
|
|
itemCloseBtn.gameObject.SetActive(false);
|
|
}
|
|
GetControl<TextMeshProUGUI>("countText").text = _itemInfo.Count.ToString();
|
|
GetControl<Image>("iconBtn").sprite = Resources.Load<Sprite>(Const.LoadToolAndMaterialPath + currentItem.toolName);
|
|
if (GameManager.RunModelMgr.ModeType == E_ModeType.Study)
|
|
{
|
|
itemCloseBtn.gameObject.SetActive(false);
|
|
GameManager.EventMgr.AddEventListener<string>(Enum_EventType.SwitchSubProcessStepTriggerID, SwitchSubProcessStepTriggerID);
|
|
}
|
|
}
|
|
private void SwitchSubProcessStepTriggerID(string arg0)
|
|
{
|
|
if (currentItem.toolName == arg0)
|
|
{
|
|
GameManager.UIMgr.imageTips.ShowTips(GetComponent<RectTransform>());
|
|
}
|
|
}
|
|
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.transform.eulerAngles = itemInfoList[counts].selfAngleInToolRoom;
|
|
obj.name = itemInfoList[counts].toolName;
|
|
Tool_SelectComponent objTool = obj.GetComponent<Tool_SelectComponent>();
|
|
objTool.itemInfo = itemInfoList[counts];
|
|
objTool.GetInfo();
|
|
if (objTool.itemInfo.toolOrDeviceOrMaterial == E_ToolOrDeviceOrMaterials.Device)
|
|
{
|
|
SingleBubbleCtrl[] sbcInScene = FindObjectsOfType<SingleBubbleCtrl>();
|
|
foreach (var item in sbcInScene)
|
|
{
|
|
if (item.targetDevice == null && item.positionKey == obj.transform.localPosition)
|
|
{
|
|
item.targetDevice = obj;
|
|
break;
|
|
}
|
|
|
|
}
|
|
}
|
|
|
|
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":
|
|
//bool isWorkCard = currentItem.toolName.Equals("工作证") ? false : true;
|
|
//if (currentItem.toolName.Equals("工作证") && !LiveSceneManager.Instance.npcCustomController.isClose)
|
|
//{
|
|
|
|
// if (GameManager.UIMgr.GetPanel<UI_MiddleTipPanel>() != null)
|
|
// GameManager.UIMgr.GetPanel<UI_MiddleTipPanel>().Init("提示:请移动到交互对象附近");
|
|
// if (GameManager.UIMgr.GetPanel<UI_MiddleTipPanel>() == null)
|
|
// {
|
|
// GameManager.UIMgr.ShowPanel<UI_MiddleTipPanel>(E_UI_Layer.System, (p) =>
|
|
// {
|
|
// p.Init($"提示:请移动到交互对象附近");
|
|
// });
|
|
// }
|
|
// //GameManager.UIMgr.ShowPanel<UI_MiddleTipPanel>(E_UI_Layer.System, (p) =>
|
|
// //{
|
|
// // p.Init($"提示:请移动到交互对象附近");
|
|
// //});
|
|
// GameManager.EventMgr?.EventTrigger<bool>(Enum_EventType.PlayerCanMove, true);
|
|
// return;
|
|
//}
|
|
//if (GameManager.ProcessMgr.IsRightSubProcessStepsTriggerID(currentItem.toolName, isWorkCard) == 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;
|
|
GameManager.EventMgr.EventTrigger<GameObject>(Enum_EventType.TakeOutAndRetrievingTheTools, currentTool);
|
|
if (currentTool.name != "电能表校验仪器")
|
|
GameManager.UIMgr.imageTips.HideTips();
|
|
//}
|
|
break;
|
|
}
|
|
}
|
|
private void OnDestroy()
|
|
{
|
|
if (GameManager.RunModelMgr.ModeType == E_ModeType.Study)
|
|
GameManager.EventMgr.RemoveEventListener<string>(Enum_EventType.SwitchSubProcessStepTriggerID, SwitchSubProcessStepTriggerID);
|
|
}
|
|
|
|
private void OnDisable()
|
|
{
|
|
if (GameManager.RunModelMgr.ModeType == E_ModeType.Study)
|
|
GameManager.EventMgr.RemoveEventListener<string>(Enum_EventType.SwitchSubProcessStepTriggerID, SwitchSubProcessStepTriggerID);
|
|
}
|
|
}
|