187 lines
4.9 KiB
C#
187 lines
4.9 KiB
C#
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
using DG.Tweening;
|
|
|
|
public class CameraMgr : MonoSingleton<CameraMgr>
|
|
{
|
|
public CameraRT camera_Rt;
|
|
|
|
Vector3 originPos;
|
|
Vector3 originRot;
|
|
|
|
// [Header("业务视角点")]
|
|
public List<Transform> logicViewList = new List<Transform>();
|
|
|
|
/// <summary>
|
|
/// 是否定位至机柜
|
|
/// </summary>
|
|
public bool is_located;
|
|
|
|
private void Awake()
|
|
{
|
|
camera_Rt = GetComponent<CameraRT>();
|
|
}
|
|
|
|
public void SetOrigin()
|
|
{
|
|
originPos = Camera.main.transform.position;
|
|
originRot = Camera.main.transform.localEulerAngles;
|
|
}
|
|
|
|
public void GotoView(string viewName)
|
|
{
|
|
Transform viewTarget = logicViewList.Find(x => x.name == viewName);
|
|
camera_Rt.SetTarget(viewTarget);
|
|
}
|
|
|
|
|
|
public void GotoView(string viewName, float _distance)
|
|
{
|
|
Transform viewTarget = logicViewList.Find(x => x.name == viewName);
|
|
|
|
camera_Rt.SetTarget(viewTarget, _distance);
|
|
|
|
}
|
|
|
|
public void GotoView(Transform viewTarget, float _distance)
|
|
{
|
|
camera_Rt.SetTarget(viewTarget, _distance);
|
|
}
|
|
|
|
public void GotoView(Transform viewTarget, float _distance, Quaternion rotation, float TargetPos_dis = -1)
|
|
{
|
|
camera_Rt.SetTarget(viewTarget, _distance, rotation, TargetPos_dis);
|
|
}
|
|
|
|
[ContextMenu("test")]
|
|
public void test()
|
|
{
|
|
GotoView(new Vector3(9.67f, -2.43f, -13.5f), 5);
|
|
}
|
|
|
|
public void GotoView(Vector3 viewTarget, float _distance)
|
|
{
|
|
camera_Rt.SetTarget(viewTarget, _distance);
|
|
}
|
|
|
|
public void StoreTarget()
|
|
{
|
|
camera_Rt.StoreTarget();
|
|
}
|
|
|
|
public void ResumeView()
|
|
{
|
|
camera_Rt.ResumeTarget();
|
|
}
|
|
|
|
public void ReturnToMain()
|
|
{
|
|
Camera.main.transform.DORotate(originRot, 1);
|
|
|
|
Camera.main.transform.DOMove(originPos, 1);
|
|
}
|
|
|
|
public void Update()
|
|
{
|
|
//if (GameManager.Inst.magnifyState)
|
|
//{
|
|
// show_roof(true);
|
|
//}
|
|
//else
|
|
//{
|
|
// show_roof(false);
|
|
//}
|
|
|
|
//if (Camera.main.transform.position.y <= 3)
|
|
//{
|
|
// if (ExtendedFlycam.Inst.room == ExtendedFlycam.Room.None)
|
|
// {
|
|
// if (ExtendedFlycam.Inst.jiFang[1].activeInHierarchy && ExtendedFlycam.Inst.peiDianShi[1].activeInHierarchy)
|
|
// {
|
|
// ExtendedFlycam.Inst.peiDianShiD.SetActive(true);
|
|
// ExtendedFlycam.Inst.jiFangD.SetActive(true);
|
|
// }
|
|
|
|
// }
|
|
// else if (ExtendedFlycam.Inst.room == ExtendedFlycam.Room.机房)
|
|
// {
|
|
// if (ExtendedFlycam.Inst.jiFang[1].activeInHierarchy)
|
|
// {
|
|
// ExtendedFlycam.Inst.peiDianShiD.SetActive(false);
|
|
// ExtendedFlycam.Inst.jiFangD.SetActive(true);
|
|
// }
|
|
// }
|
|
// else if (ExtendedFlycam.Inst.room == ExtendedFlycam.Room.配电室)
|
|
// {
|
|
// if (ExtendedFlycam.Inst.peiDianShi[1].activeInHierarchy)
|
|
// {
|
|
// ExtendedFlycam.Inst.peiDianShiD.SetActive(true);
|
|
// ExtendedFlycam.Inst.jiFangD.SetActive(false);
|
|
// }
|
|
// }
|
|
//}
|
|
//else
|
|
//{
|
|
// ExtendedFlycam.Inst.peiDianShiD.SetActive(false);
|
|
// ExtendedFlycam.Inst.jiFangD.SetActive(false);
|
|
//}
|
|
}
|
|
|
|
//public void show_roof(bool isshow)
|
|
//{
|
|
// if (ExtendedFlycam.Inst.room == ExtendedFlycam.Room.机房)
|
|
// ExtendedFlycam.Inst.jiFangD.SetActive(isshow);
|
|
// else if (ExtendedFlycam.Inst.room == ExtendedFlycam.Room.配电室)
|
|
// ExtendedFlycam.Inst.peiDianShiD.SetActive(isshow);
|
|
// else
|
|
// {
|
|
// ExtendedFlycam.Inst.peiDianShiD.SetActive(isshow);
|
|
// ExtendedFlycam.Inst.jiFangD.SetActive(isshow);
|
|
// }
|
|
//}
|
|
|
|
#region 自动切换预设视角
|
|
//[Header("漫游视角自动切换")]
|
|
//public bool autoChangeView = false;
|
|
|
|
//public float changeViewTimer;
|
|
|
|
//public List<Transform> autoChangeViewList;
|
|
|
|
//int index = 0;
|
|
//void ChangeView()
|
|
//{
|
|
// if (!autoChangeView)
|
|
// return;
|
|
|
|
|
|
// if (index > autoChangeViewList.Count - 1)
|
|
// {
|
|
// index = 0;
|
|
|
|
// ReturnToMain();
|
|
// return;
|
|
// }
|
|
|
|
// Camera.main.transform.position = autoChangeViewList[index].position;
|
|
// Camera.main.transform.localEulerAngles = autoChangeViewList[index].localEulerAngles;
|
|
|
|
// index++;
|
|
//}
|
|
|
|
//public void AutoChangeView_Open()
|
|
//{
|
|
// autoChangeView = true;
|
|
// CancelInvoke("ChangeView");
|
|
// InvokeRepeating("ChangeView", 15, 15);
|
|
//}
|
|
|
|
//public void AutoChangeView_Close()
|
|
//{
|
|
// autoChangeView = false;
|
|
//}
|
|
|
|
#endregion
|
|
}
|