new_10009_YanCheng_Metrology/Assets/Template/Scripts/Project/Manager/LiveSceneManager.cs

333 lines
13 KiB
C#

using System.Collections;
using System.Collections.Generic;
using System.Linq;
using UnityEngine;
using UnityEngine.UI;
public class LiveSceneManager : SingletonMono<LiveSceneManager>
{
[HideInInspector]
public FirstPersonController firstPersonController;
//[HideInInspector]
public GameObject currentTool;
public Transform spawnToolPos;
public Transform tMDTips;
public string triggerName;
public NPCController npcCustomController;
public string playSpeack;
//场景中设备控制脚本
public Device_Control device_Control;
/// <summary>
/// 校验仪位置
/// </summary>
public Transform jiaoYanYiPos;
/// <summary>
/// 万用表位置
/// </summary>
public Transform wanYongBiaoPos;
public Tool_ElectricEnergyMeterCalibrationInstrument jiaoYanYi;
protected override void Awake()
{
base.Awake();
firstPersonController = GameObject.FindGameObjectWithTag("Player").GetComponent<FirstPersonController>();
tMDTips.gameObject.SetActive(false);
GameManager.EventMgr?.AddEventListener<GameObject>(Enum_EventType.TakeOutAndRetrievingTheTools, SetSpawnToolInfo);
firstPersonController.zoomAction += OnZoom;
GameManager.EventMgr?.AddEventListener<bool>(Enum_EventType.PlayerCanMove, SwitchFirstPersonControllerMove);
//基类全部初始化
if (device_Control != null)
device_Control.transform.GetComponentsInChildren<PermanentTriggerBase>(true).ToList().ForEach(a => a.Awake());
}
public void SwitchFirstPersonControllerMove(bool isMove)
{
firstPersonController.playerCanMove = isMove;
}
/// <summary>
///
/// </summary>
/// <param name="_pos"></param>
/// <param name="_angle"></param>
/// <param name="isSetFOVAndUpDownView">是否设置FOV 和 上下视角</param>
public void SetFirstPersonTransform(Vector3 _pos, Vector3 _angle, bool isSetFOVAndUpDownView = false)
{
firstPersonController.transform.position = _pos;
firstPersonController.transform.eulerAngles = _angle;
if (isSetFOVAndUpDownView)
{
firstPersonController.playerCamera.fieldOfView = 10;
firstPersonController.playerCamera.transform.localEulerAngles = new Vector3(26.308f, 0, 0);
}
}
private void OnZoom(float value)
{
tMDTips.localScale = new Vector3(value, value, value);
}
public void SetSpawnToolInfo(GameObject tool)
{
if (tool == null) return;
currentTool = tool;
currentTool.transform.parent = Camera.main.transform;
currentTool.transform.localPosition = spawnToolPos.localPosition;
currentTool.transform.localEulerAngles = spawnToolPos.localEulerAngles;
if (currentTool.GetComponent<Tool_Base>())
{
currentTool.GetComponent<Tool_Base>().SetHeadPosAndEulerang(currentTool.transform.localPosition, currentTool.transform.localEulerAngles);
currentTool.GetComponent<Tool_Base>().AddStartAction(() =>
{
tMDTips.gameObject.SetActive(false);
});
currentTool.GetComponent<Tool_Base>().AddEndAction(() =>
{
tMDTips.gameObject.SetActive(true);
});
}
if (currentTool.GetComponent<Device_Base>())
{
currentTool.GetComponent<Device_Base>().SetHeadPosAndEulerang(currentTool.transform.localPosition, currentTool.transform.localEulerAngles);
}
tMDTips.gameObject.SetActive(true);
if (currentTool.name.Equals("工作证"))
{
GameManager.UIMgr.ShowPanel<UI_PlayerSessionPanel>(E_UI_Layer.Mid, (p) =>
{
p.Init(currentTool.name, playSpeack, (intTemp) =>
{
GameManager.ProcessMgr.IsRightSubProcessStepsTriggerID(intTemp, true);
ScoreManager.instance.Check(currentTool.name, null);
OnCheckSubProcess();
}, 0);
});
tMDTips.gameObject.SetActive(false);
currentTool.transform.localEulerAngles = new Vector3(90, 0, 0);
}
else if (currentTool.name.Equals("三相四线智能电能表") || currentTool.name.Equals("三相四线费控智能电能表"))
{
tMDTips.gameObject.SetActive(false);
currentTool.transform.localPosition = new Vector3(currentTool.transform.localPosition.x, currentTool.transform.localPosition.y, currentTool.transform.localPosition.z + 0.1f);
currentTool.transform.localEulerAngles = new Vector3(-90, 180, -180);
//核对设备
if (GameManager.RunModelMgr.schemeID == 1002)
{
CheckDeviceButtonPanel.Show(currentTool.name);
tMDTips.gameObject.SetActive(true);
}
}
else if (currentTool.name.Equals("采集器"))//HQB 采集器
{
tMDTips.gameObject.SetActive(false);
//currentTool.transform.localPosition = new Vector3(currentTool.transform.localPosition.x, currentTool.transform.localPosition.y, currentTool.transform.localPosition.z + 0.1f);
currentTool.transform.localEulerAngles = new Vector3(0, 180, 0);
//核对设备
if (GameManager.RunModelMgr.schemeID == 4001)
{
//CheckDeviceButtonPanel.Show(currentTool.name);
tMDTips.gameObject.SetActive(true);
}
}
else if (currentTool.name.Equals("绝缘导线"))
{
tMDTips.gameObject.SetActive(true);
if (GameManager.RunModelMgr.ModeType == E_ModeType.Study && GameManager.RunModelMgr.schemeID == 1002 && ProcessManager.Instance.subProcessStepTriggerID.StartsWith("选择") && ProcessManager.Instance.subProcessStepTriggerID.EndsWith("线"))
{
currentTool.GetComponent<Tool_InsulatedConductor>().SetChoeseState(ProcessManager.Instance.subProcessStepTriggerID[2].ToString());
}
else
currentTool.GetComponent<Tool_InsulatedConductor>().SetChoeseState();
}
else if (currentTool.name.Equals("低压电流互感器"))
{
currentTool.transform.localPosition = new Vector3(0.148f, -0.023f, 0.399f);
//核对设备
if (GameManager.RunModelMgr.schemeID == 1002)
{
CheckDeviceButtonPanel.Show(currentTool.name);
}
}
else if (currentTool.name.Equals("电能表校验仪器"))
{
if (jiaoYanYi != null)
{
//jiaoYanYi.tPEMLineController.WhenToolNull(null);
RemoveCuurentJiaoYanYi();
}
if (jiaoYanYiPos != null)
{
tMDTips.gameObject.SetActive(false);
currentTool.transform.position = jiaoYanYiPos.position;
currentTool.transform.eulerAngles = jiaoYanYiPos.eulerAngles;
currentTool.transform.parent = jiaoYanYiPos;
jiaoYanYi = currentTool.GetComponent<Tool_ElectricEnergyMeterCalibrationInstrument>();
currentTool = null;
GameManager.UIMgr.GetPanel<UI_MenuBar>().TakeOutAndRetrievingTheTools(null);
//GameManager.EventMgr?.EventTrigger<GameObject>(Enum_EventType.TakeOutAndRetrievingTheTools, null);
}
else
{
Debug.Log("该科目不需要用到校验仪");
}
}
else if (currentTool.name.Equals("万用表"))
{
if (wanYongBiaoPos != null)
{
currentTool.transform.position = wanYongBiaoPos.position;
currentTool.transform.eulerAngles = wanYongBiaoPos.eulerAngles;
currentTool.transform.parent = wanYongBiaoPos;
}
else
{
Debug.Log("该科目不需要用到校验仪");
}
}
else if (currentTool.name.Equals("盒装计量箱电子标签"))
{
currentTool.transform.localPosition = new Vector3(0.1483f, 0.0661f, 0.3306f);
currentTool.transform.localEulerAngles = new Vector3(54.87f, -249.27f, -72.053f);
}
}
private void Update()
{
if (Input.GetKeyDown(KeyCode.Escape))
{
if (currentTool != null)
{
if (GameManager.ProcessMgr.IsRightSubProcessStepsTriggerID(triggerName, true) == 0)
{
Debug.Log("Escape");
OnCheckSubProcess();
}
}
}
}
public void OnCheckSubProcess(bool ifdestroy = true)
{
if (currentTool != null)
{
if (tMDTips != null)
tMDTips.gameObject.SetActive(false);
if (ifdestroy)
DestroyImmediate(currentTool);
currentTool = null;
GameManager.EventMgr?.EventTrigger<GameObject>(Enum_EventType.TakeOutAndRetrievingTheTools, null);
}
}
public void RemoveCuurentJiaoYanYi()
{
if (jiaoYanYi != null)
{
jiaoYanYi.tPEMLineController.DestroyAllLineTrigger();
DestroyImmediate(jiaoYanYi.gameObject);
jiaoYanYi = null;
}
}
/// <summary>
/// 设置校验仪盒子 线材状态
/// </summary>
public void SetJiaoYanYiState()
{
//StopCoroutine(WaitSetJiaoYanYiState());
//StartCoroutine(WaitSetJiaoYanYiState());
jiaoYanYi.GetComponent<Collider>().enabled = false;
jiaoYanYi.OpenGaiZi(1);
jiaoYanYi.tPEMLineController.CheckLine(1);
}
/// <summary>
/// 设置校验仪仪器
/// </summary>
public void SetJiaoYanYiYiQiState()
{
//StopCoroutine(WaitSetJiaoYanYiYiQiState());
//StartCoroutine(WaitSetJiaoYanYiYiQiState());
jiaoYanYi.threePhaseEnergyMeterCalibrator.SwitchPos(1);
}
public void SetJiaoYanYiScreenState()
{
//StopCoroutine(WaitSetJiaoYanYiScreenState());
//StartCoroutine(WaitSetJiaoYanYiScreenState());
jiaoYanYi.threePhaseEnergyMeterCalibrator.OpenPower();
jiaoYanYi.threePhaseEnergyMeterCalibrator.SetState(1);
}
private IEnumerator WaitSetJiaoYanYiScreenState()
{
yield return new WaitForSeconds(0.01f);
}
private IEnumerator WaitSetJiaoYanYiYiQiState()
{
yield return new WaitForSeconds(0.01f);
}
/// <summary>
/// 0=接入校验仪步骤,1-现场测定电能表误差
/// </summary>
/// <param name="state"></param>
/// <returns></returns>
private IEnumerator WaitSetJiaoYanYiState()
{
yield return new WaitForSeconds(0.01f);
}
private void OnDestroy()
{
firstPersonController.zoomAction -= OnZoom;
currentTool = null;
GameManager.EventMgr.EventTrigger<GameObject>(Enum_EventType.TakeOutAndRetrievingTheTools, null);
GameManager.EventMgr.RemoveEventListener<bool>(Enum_EventType.PlayerCanMove, SwitchFirstPersonControllerMove);
GameManager.EventMgr.RemoveEventListener<GameObject>(Enum_EventType.TakeOutAndRetrievingTheTools, SetSpawnToolInfo);
//清空设备铭牌核对选项
UI_CheckDevicePanel.isCheck互感器A相 = false;
UI_CheckDevicePanel.isCheck互感器B相 = false;
UI_CheckDevicePanel.isCheck互感器C相 = false;
UI_CheckDevicePanel.isCheck电能表 = false;
//删除核对按钮
if (CheckDeviceButtonPanel.instance != null)
{
CheckDeviceButtonPanel.instance.MyDesTroy();
}
//隐藏中间提示面板
if (GameManager.UIMgr.GetPanel<UI_MiddleTipPanel>())
{
GameManager.UIMgr.HidePanel<UI_MiddleTipPanel>();
}
Debug.Log("LiveSceneManager OnDestroy");
}
private void OnDisable()
{
//firstPersonController.zoomAction -= OnZoom;
//currentTool = null;
//GameManager.EventMgr.EventTrigger<GameObject>(Enum_EventType.TakeOutAndRetrievingTheTools, null);
//GameManager.EventMgr.RemoveEventListener<bool>(Enum_EventType.PlayerCanMove, SwitchFirstPersonControllerMove);
//GameManager.EventMgr.RemoveEventListener<GameObject>(Enum_EventType.TakeOutAndRetrievingTheTools, SetSpawnToolInfo);
////清空设备铭牌核对选项
//if (GameManager.UIMgr.GetPanel<UI_CheckDevicePanel>())
//{
// GameManager.UIMgr.GetPanel<UI_CheckDevicePanel>().isCheck互感器A相 = false;
// GameManager.UIMgr.GetPanel<UI_CheckDevicePanel>().isCheck互感器B相 = false;
// GameManager.UIMgr.GetPanel<UI_CheckDevicePanel>().isCheck互感器C相 = false;
// GameManager.UIMgr.GetPanel<UI_CheckDevicePanel>().isCheck电能表 = false;
//}
////删除核对按钮
//if (CheckDeviceButtonPanel.instance != null)
//{
// CheckDeviceButtonPanel.instance.MyDesTroy();
//}
Debug.Log(" OnDisable()");
}
}