E_ElecCompetition/Electrical_inspectionCompet.../Assets/Adam/Scripts/ToolsItemManager.cs

147 lines
3.9 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Events;
using UnityEngine.UI;
//============================================================
//支持中文文件使用UTF-8编码
//@author YangHua
//@create 20230914
//@company QianHuo
//
//@description:工具包按钮管理
//============================================================
public class ToolsItemManager : MonoSingleton<ToolsItemManager>
{
public GameObject toolPanel;
public List<ToolItem> toolItems = new List<ToolItem>();
public ToolItem toolItemPrefab;
public Transform toolsContent;
public Button closeBtn;
public UnityEvent<GameObject> ItemClick;
public Button recoverBtn;
public UnityEvent recoverEvent = new UnityEvent();
public Toggle bottomToolToggle;
public GameObject currentTool;
public GameObject ServerRecorderPanel;
private void Start()
{
closeBtn.onClick.AddListener(() => { SwictchToolPanel(false); });
recoverBtn.onClick.AddListener(() =>
{
recoverEvent?.Invoke();
RecoverCurrentInstantiateTool(currentTool);
});
recoverBtn.gameObject.SetActive(false);
ServerRecorderPanel.gameObject.SetActive(false);
}
public void SwictchToolPanel(bool isActive)
{
toolPanel.SetActive(isActive);
}
/// <summary>
/// 在工具间生成图标
/// </summary>
/// <param name="toolName"></param>
public void CreatToolItem(GameObject currentModel)
{
ToolItem tTemp = Instantiate(toolItemPrefab, toolsContent);
tTemp.SetValue(currentModel.name, currentModel.transform);
tTemp.SetState(true);
if (tTemp.toolName == "工作卡")
{
tTemp.selfButton.interactable = true;
tTemp.selfButton.onClick.AddListener(() =>
{
UIManager.Instance.jobCardController.jobCardPanel.SetActive(true);
SetToggleState();
});
}
else if (tTemp.toolName == "服务器记录仪")
{
tTemp.selfButton.onClick.AddListener(() =>
{
StopCoroutine(WaitShowServerRecorderPanel());
StartCoroutine(WaitShowServerRecorderPanel());
SetToggleState();
});
}
else
{
tTemp.selfButton.onClick.AddListener(() =>
{
ItemClick?.Invoke(tTemp.prefab);
recoverBtn.gameObject.SetActive(true);
bottomToolToggle.interactable = false;
SetToggleState();
});
}
toolItems.Add(tTemp);
}
public void RemoveNull()
{
for (int i = 0; i < toolItems.Count; i++)
{
if (toolItems[i] == null)
toolItems.RemoveAt(i);
}
}
public void SetToggleState()
{
bottomToolToggle.isOn = false;
SwictchToolPanel(false);
}
/// <summary>
///
/// </summary>
/// <param name="tool"></param>
public void RecoverCurrentInstantiateTool(GameObject tool)
{
if (tool != null)
Destroy(tool);
bottomToolToggle.interactable = true;
recoverBtn.gameObject.SetActive(false);
}
/// <summary>
/// 需要3D去调用
/// </summary>
public void SwitchAllToolItems()
{
for (int i = 0; i < toolItems.Count; i++)
{
if (toolItems[i] != null)
toolItems[i].SwitchSelfIsClick();
else
toolItems.RemoveAt(i);
}
}
public void ResetState()
{
for (int i = 0; i < toolItems.Count; i++)
{
toolItems[i].SetState(true);
}
}
public IEnumerator WaitShowServerRecorderPanel()
{
ServerRecorderPanel.gameObject.SetActive(true);
yield return new WaitForSeconds(2f);
ServerRecorderPanel.gameObject.SetActive(false);
}
}