1118OPSSNew/Assets/Zion/Scripts//LiveSceneManager.cs

136 lines
4.3 KiB
C#

using DG.Tweening.Core.Easing;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.UIElements;
using static UnityEngine.Rendering.DebugUI;
public class LiveSceneManager : SingletonMono<LiveSceneManager>
{
[HideInInspector]
public FirstPersonController firstPersonController;
//[HideInInspector]
public GameObject currentTool;
public Transform spawnToolPos;
//public Transform tMDTips;
public string triggerName;
public string playSpeack;
private Vector3 lastPlayerPos = new Vector3();
private Vector3 lastPlayerAngle = new Vector3();
private float lastFOV;
private Vector3 lastPlayerCameraAngle = new Vector3();
protected override void Awake()
{
base.Awake();
firstPersonController = GameObject.FindGameObjectWithTag("Player").GetComponent<FirstPersonController>();
//tMDTips.gameObject.SetActive(false);
//firstPersonController.zoomAction += OnZoom;
//基类全部初始化
//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, float fov = 0, Vector3 _camareAngle = new Vector3(), bool isRecord = false)
{
if (isRecord)
{
lastPlayerPos = firstPersonController.transform.position;
lastPlayerAngle = firstPersonController.transform.eulerAngles;
lastFOV = firstPersonController.playerCamera.fieldOfView;
lastPlayerCameraAngle = firstPersonController.playerCamera.transform.localEulerAngles;
}
firstPersonController.transform.position = _pos;
firstPersonController.transform.eulerAngles = _angle;
if (isSetFOVAndUpDownView)
{
firstPersonController.playerCamera.fieldOfView = fov;
firstPersonController.playerCamera.transform.localEulerAngles = _camareAngle;
}
firstPersonController.yaw = 0;
firstPersonController.pitch = 0;
}
public void ResetFirstPersonTransform()
{
if (lastFOV != 0)
{
firstPersonController.transform.position = lastPlayerPos;
firstPersonController.transform.eulerAngles = lastPlayerAngle;
firstPersonController.playerCamera.fieldOfView = lastFOV;
firstPersonController.playerCamera.transform.localEulerAngles = lastPlayerCameraAngle;
firstPersonController.yaw = 0;
firstPersonController.pitch = 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<Device_Base>())
{
currentTool.GetComponent<Device_Base>().SetHeadPosAndEulerang(currentTool.transform.localPosition, currentTool.transform.localEulerAngles);
}
}
private void Update()
{
if (Input.GetKeyDown(KeyCode.Escape))
{
if (currentTool != null)
{
Debug.Log("Escape");
OnCheckSubProcess();
}
}
}
public void OnCheckSubProcess(bool ifdestroy = true)
{
if (currentTool != null)
{
if (ifdestroy)
DestroyImmediate(currentTool);
currentTool = null;
}
}
private void OnDestroy()
{
currentTool = null;
Debug.Log("LiveSceneManager OnDestroy");
}
private void OnDisable()
{
Debug.Log(" OnDisable()");
}
}