108 lines
2.6 KiB
C#
108 lines
2.6 KiB
C#
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
using DG.Tweening;
|
|
using UnityEngine.UIElements;
|
|
|
|
public class CameraController : MonoBehaviour
|
|
{
|
|
public static CameraController instance;
|
|
/// <summary>
|
|
/// 禁止操作
|
|
/// </summary>
|
|
//[HideInInspector]
|
|
public bool ShieldingOperation;
|
|
|
|
protected Quaternion myLocalAng;
|
|
protected Vector3 myPos;
|
|
|
|
/// <summary>
|
|
/// 定位目标
|
|
/// </summary>
|
|
protected Transform Target;
|
|
/// <summary>
|
|
/// 默认定位距离
|
|
/// </summary>
|
|
protected float distance = 200;
|
|
public float Distance => distance;
|
|
|
|
public float eulerx;
|
|
public float eulery;
|
|
public float horizontal;
|
|
public float vertical;
|
|
|
|
public Vector2 XLimit = new Vector2(-500, 500);
|
|
public Vector2 YLimit = new Vector2(5, 500);
|
|
public Vector2 ZLimit = new Vector2(-500, 500);
|
|
protected virtual void Awake()
|
|
{
|
|
instance = this;
|
|
}
|
|
|
|
protected virtual void Start()
|
|
{
|
|
|
|
}
|
|
|
|
protected virtual void Update()
|
|
{
|
|
//if (Target != null)
|
|
// Distance = Vector3.Distance(Target.position, transform.position);
|
|
}
|
|
|
|
protected void InitTransform()
|
|
{
|
|
//ShieldingOperation = true;
|
|
myLocalAng = transform.rotation;
|
|
horizontal = eulerx = myLocalAng.eulerAngles.y;
|
|
vertical = eulery = myLocalAng.eulerAngles.x;
|
|
if (vertical > 180)
|
|
vertical -= 360;
|
|
myPos = transform.position;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 设置相机位置
|
|
/// 开启自动漫游时设置
|
|
/// </summary>
|
|
/// <param name="position"></param>
|
|
/// <param name="angle"></param>
|
|
public void SetTransform(Vector3 position,Vector3 angle)
|
|
{
|
|
Target = null;
|
|
transform.position = position;
|
|
transform.eulerAngles = angle;
|
|
InitTransform();
|
|
}
|
|
|
|
/// <summary>
|
|
/// 设置坐标及角度
|
|
/// </summary>
|
|
/// <param name="_position"></param>
|
|
/// <param name="_rotation"></param>
|
|
public void SetTransform(Vector3 _position,Quaternion _rotation)
|
|
{
|
|
Target = null;
|
|
transform.position = _position;
|
|
transform.rotation = _rotation;
|
|
InitTransform();
|
|
}
|
|
|
|
/// <summary>
|
|
/// 定位至目标
|
|
/// </summary>
|
|
/// <param name="target"></param>
|
|
public void LocateToTarget(Transform target)
|
|
{
|
|
if (target == null) return;
|
|
Target = target;
|
|
ShieldingOperation = true;
|
|
|
|
transform.DOMove((transform.rotation * Vector3.back * Distance + Target.position), 0.5f).OnComplete(() =>
|
|
{
|
|
myPos = transform.position;
|
|
ShieldingOperation = false;
|
|
});
|
|
}
|
|
}
|