132 lines
5.2 KiB
C#
132 lines
5.2 KiB
C#
using System.Collections;
|
||
using System.Collections.Generic;
|
||
using System.Linq;
|
||
using UnityEngine;
|
||
|
||
public class LiveSceneManager : SingletonMono<LiveSceneManager>
|
||
{
|
||
[HideInInspector]
|
||
public FirstPersonController firstPersonController;
|
||
//[HideInInspector]
|
||
public GameObject currentTool;
|
||
public Transform spawnToolPos;
|
||
public Transform tMDTips;
|
||
public string triggerName;
|
||
|
||
//场景中设备控制脚本
|
||
public Device_Control device_Control;
|
||
|
||
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);
|
||
//基类全部初始化
|
||
device_Control.transform.GetComponentsInChildren<PermanentTriggerBase>(true).ToList().ForEach(a => a.Awake());
|
||
}
|
||
public void SwitchFirstPersonControllerMove(bool isMove)
|
||
{
|
||
firstPersonController.playerCanMove = isMove;
|
||
}
|
||
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);
|
||
currentTool.GetComponent<Device_Base>().AddStartAction(() =>
|
||
{
|
||
});
|
||
currentTool.GetComponent<Device_Base>().AddEndAction(() =>
|
||
{
|
||
});
|
||
}
|
||
tMDTips.gameObject.SetActive(true);
|
||
if (currentTool.name.Equals("工作证"))
|
||
{
|
||
GameManager.UIMgr.ShowPanel<UI_PlayerSessionPanel>(E_UI_Layer.Mid, (p) =>
|
||
{
|
||
p.Init(currentTool.name, "您好,我是xx供电公司员工,这是我的工作证。现在我们要对贵户更换电能计量表", (intTemp) =>
|
||
{
|
||
GameManager.ProcessMgr.IsRightSubProcessStepsTriggerID(intTemp, true);
|
||
ScoreManager.instance.Check(currentTool.name, null);
|
||
OnCheckSubProcess();
|
||
});
|
||
});
|
||
tMDTips.gameObject.SetActive(false);
|
||
currentTool.transform.localEulerAngles = new Vector3(90, 0, 0);
|
||
|
||
}
|
||
if (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);
|
||
}
|
||
}
|
||
|
||
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);
|
||
}
|
||
}
|
||
|
||
private void OnDestroy()
|
||
{
|
||
firstPersonController.zoomAction -= OnZoom;
|
||
GameManager.EventMgr?.RemoveEventListener<GameObject>(Enum_EventType.TakeOutAndRetrievingTheTools, SetSpawnToolInfo);
|
||
GameManager.EventMgr?.RemoveEventListener<bool>(Enum_EventType.PlayerCanMove, SwitchFirstPersonControllerMove);
|
||
}
|
||
private void OnDisable()
|
||
{
|
||
firstPersonController.zoomAction -= OnZoom;
|
||
GameManager.EventMgr?.RemoveEventListener<GameObject>(Enum_EventType.TakeOutAndRetrievingTheTools, SetSpawnToolInfo);
|
||
GameManager.EventMgr?.RemoveEventListener<bool>(Enum_EventType.PlayerCanMove, SwitchFirstPersonControllerMove);
|
||
}
|
||
}
|