parent
be581b7c74
commit
520d9cb2b3
|
@ -59,4 +59,14 @@ public enum Purpose
|
|||
{
|
||||
进货 = 1,
|
||||
出货 = 2
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public enum LookType
|
||||
{
|
||||
PATH = 5,
|
||||
TRANSFORM,
|
||||
POINT,
|
||||
}
|
|
@ -70,10 +70,26 @@ public class CameraRoamManager : Singleton<CameraRoamManager>
|
|||
[Range(0, 1)]
|
||||
public float look = 0;
|
||||
|
||||
/// <summary>
|
||||
/// 约束X轴
|
||||
/// </summary>
|
||||
public bool ConstraintXAxis;
|
||||
/// <summary>
|
||||
/// 约束Y轴
|
||||
/// </summary>
|
||||
public bool ConstraintYAxis;
|
||||
/// <summary>
|
||||
/// 约束Z轴
|
||||
/// </summary>
|
||||
public bool ConstraintZAxis;
|
||||
/// <summary>
|
||||
/// 约束值
|
||||
/// </summary>
|
||||
public Vector3 ConstraintValue;
|
||||
///// <summary>
|
||||
///// 漫游相机查看类型
|
||||
///// </summary>
|
||||
//public LookType LookType;
|
||||
// Start is called before the first frame update
|
||||
void Start()
|
||||
{
|
||||
|
@ -130,51 +146,227 @@ public class CameraRoamManager : Singleton<CameraRoamManager>
|
|||
/// <param name="_roming_finish_callback"></param>
|
||||
public void AutoRoaming(bool _roaming, bool _looping = false, bool _roam_continue = true, Action _roming_finish_callback = null)
|
||||
{
|
||||
isRoaming = _roaming;
|
||||
#region Old
|
||||
//isRoaming = _roaming;
|
||||
//if (_roaming)
|
||||
//{
|
||||
// CameraMove.Instance.ShieldingOperation = true;
|
||||
// //判断是否继续上次的漫游
|
||||
// if (_roam_continue)
|
||||
// {
|
||||
// if (m_RoamingTween != null)
|
||||
// {
|
||||
// TargetCamera.eulerAngles = Vector3.zero;
|
||||
// m_RoamingTween.Play();
|
||||
// return;
|
||||
// }
|
||||
// }
|
||||
|
||||
// //重新开始漫游
|
||||
|
||||
// if (BezierDrawer.UseCurvePath)
|
||||
// {
|
||||
// if (BezierCurve == null)
|
||||
// {
|
||||
// BezierCurve = new BezierCurve(m_RoamingPoints, BezierDrawer != null ? BezierDrawer.accuracy : 10);
|
||||
// }
|
||||
// TargetCamera.position = BezierCurve.CurvePoints[0];
|
||||
// TargetCamera.LookAt(BezierCurve.CurvePoints[1]);
|
||||
// m_RoamingTween = TargetCamera.DOPath(BezierCurve.CurvePoints, BezierCurve.CurveLength / RoamingSpeed).SetEase(Ease.Linear).SetLoops(_looping ? -1 : 0).SetLookAt(look).OnComplete(() => { _roming_finish_callback?.Invoke(); });
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// TargetCamera.position = m_RoamingPoints[0];
|
||||
// TargetCamera.LookAt(m_RoamingPoints[1]);
|
||||
// m_RoamingTween = TargetCamera.DOPath(m_RoamingPoints, RoamingPathLength / RoamingSpeed).SetEase(Ease.Linear).SetLoops(_looping ? -1 : 0).SetLookAt(look).OnComplete(() => { _roming_finish_callback?.Invoke(); });
|
||||
// }
|
||||
|
||||
//}
|
||||
//else
|
||||
//{
|
||||
// if (m_RoamingTween != null)
|
||||
// {
|
||||
// if (_roam_continue)
|
||||
// {
|
||||
// m_RoamingTween.Pause();
|
||||
// }
|
||||
// }
|
||||
// CameraMove.Instance.ReInitTransform();
|
||||
//}
|
||||
#endregion
|
||||
if (_roaming)
|
||||
{
|
||||
CameraMove.Instance.ShieldingOperation = true;
|
||||
//判断是否继续上次的漫游
|
||||
if (_roam_continue)
|
||||
{
|
||||
if (m_RoamingTween != null)
|
||||
{
|
||||
TargetCamera.eulerAngles = Vector3.zero;
|
||||
m_RoamingTween.Play();
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
//重新开始漫游
|
||||
|
||||
if (BezierDrawer.UseCurvePath)
|
||||
{
|
||||
if (BezierCurve == null)
|
||||
{
|
||||
BezierCurve = new BezierCurve(m_RoamingPoints, BezierDrawer != null ? BezierDrawer.accuracy : 10);
|
||||
}
|
||||
TargetCamera.position = BezierCurve.CurvePoints[0];
|
||||
TargetCamera.LookAt(BezierCurve.CurvePoints[1]);
|
||||
m_RoamingTween = TargetCamera.DOPath(BezierCurve.CurvePoints, BezierCurve.CurveLength / RoamingSpeed).SetEase(Ease.Linear).SetLoops(_looping ? -1 : 0).SetLookAt(look).OnComplete(() => { _roming_finish_callback?.Invoke(); });
|
||||
}
|
||||
else
|
||||
{
|
||||
TargetCamera.position = m_RoamingPoints[0];
|
||||
TargetCamera.LookAt(m_RoamingPoints[1]);
|
||||
m_RoamingTween = TargetCamera.DOPath(m_RoamingPoints, RoamingPathLength / RoamingSpeed).SetEase(Ease.Linear).SetLoops(_looping ? -1 : 0).SetLookAt(look).OnComplete(() => { _roming_finish_callback?.Invoke(); });
|
||||
}
|
||||
|
||||
Coroutine = StartCoroutine(PathMove(-1, LoopStartPoint, true));
|
||||
}
|
||||
else
|
||||
{
|
||||
if (m_RoamingTween != null)
|
||||
{
|
||||
if (_roam_continue)
|
||||
{
|
||||
m_RoamingTween.Pause();
|
||||
}
|
||||
}
|
||||
StopCoroutine(Coroutine);
|
||||
CameraMove.Instance.ReInitTransform();
|
||||
}
|
||||
isRoaming = _roaming;
|
||||
}
|
||||
/// <summary>
|
||||
/// 路径移动协程
|
||||
/// </summary>
|
||||
Coroutine Coroutine;
|
||||
/// <summary>
|
||||
/// 等待时间
|
||||
/// </summary>
|
||||
WaitForSeconds WaitForSeconds = null;
|
||||
/// <summary>
|
||||
/// 模拟帧率
|
||||
/// </summary>
|
||||
float _frame = 0.02f;
|
||||
/// <summary>
|
||||
/// 下一个路径点
|
||||
/// </summary>
|
||||
int _Next_Index = -1;
|
||||
/// <summary>
|
||||
/// 实时路径点
|
||||
/// </summary>
|
||||
List<RoamingAnchor> _Anchor_Point = new List<RoamingAnchor>();
|
||||
/// <summary>
|
||||
/// 计算循环点
|
||||
/// </summary>
|
||||
bool _init_anchor_points = false;
|
||||
/// <summary>
|
||||
/// 漫游是否已开始
|
||||
/// </summary>
|
||||
bool _roaming_started = false;
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public int LoopStartPoint = 3;
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="_loop"></param>
|
||||
/// <param name="_loop_point">循环起始点</param>
|
||||
/// <param name="_roam_continue">是否继续漫游</param>
|
||||
/// <returns></returns>
|
||||
IEnumerator PathMove(int _loop, int _loop_point = 0, bool _roam_continue = false)
|
||||
{
|
||||
int _loop_time = 0;
|
||||
|
||||
if (WaitForSeconds == null)
|
||||
{
|
||||
WaitForSeconds = new WaitForSeconds(_frame);
|
||||
}
|
||||
|
||||
if (!_roaming_started)
|
||||
{
|
||||
ForceInit();
|
||||
_roaming_started = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
//初始化
|
||||
if (_roam_continue)
|
||||
{
|
||||
TargetCamera.position = m_Position;
|
||||
TargetCamera.rotation = m_Rotation;
|
||||
}
|
||||
else
|
||||
{
|
||||
ForceInit();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
bool _at_point = false;//是否完成当此Lerp
|
||||
var _pos = TargetCamera.position;//每次Lerp的基坐标
|
||||
Vector3 _rt_pos;//实时坐标
|
||||
float _t = 0.1f;//Lerp频次
|
||||
float _to = 0;//Lerp进度
|
||||
float _lerp_speed = 10;//Lerp速度
|
||||
|
||||
|
||||
while (_loop < 0 ? true : _loop_time <= _loop)//判断循环次数
|
||||
{
|
||||
_loop_time++;
|
||||
|
||||
if (_at_point)
|
||||
{
|
||||
if (_Next_Index < _Anchor_Point.Count - 1)
|
||||
{
|
||||
_Next_Index += 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
_Next_Index = 0;
|
||||
if (!_init_anchor_points && _loop_point > 0 && _loop_point < m_RoamingAnchors.Count - 2)
|
||||
{
|
||||
_init_anchor_points = true;
|
||||
_Anchor_Point.Clear();
|
||||
for (int i = _loop_point; i < m_RoamingAnchors.Count; i++)
|
||||
{
|
||||
_Anchor_Point.Add(m_RoamingAnchors[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
_pos = TargetCamera.position;
|
||||
_to = 0;
|
||||
}
|
||||
|
||||
_to += _t;
|
||||
_rt_pos = Lerp(_pos, _Anchor_Point[_Next_Index].Position, _to / Vector3.Distance(_pos, _Anchor_Point[_Next_Index].Position) * _lerp_speed);
|
||||
TargetCamera.position = _rt_pos;
|
||||
_at_point = TargetCamera.position == _Anchor_Point[_Next_Index].Position;
|
||||
|
||||
switch (_Anchor_Point[_Next_Index].LookType)
|
||||
{
|
||||
case LookType.PATH:
|
||||
TargetCamera.LookAt(_Anchor_Point[_Next_Index].Position);
|
||||
break;
|
||||
case LookType.TRANSFORM:
|
||||
TargetCamera.LookAt(_Anchor_Point[_Next_Index].LookTransform);
|
||||
break;
|
||||
case LookType.POINT:
|
||||
TargetCamera.LookAt(_Anchor_Point[_Next_Index].LookPoint);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
yield return WaitForSeconds;
|
||||
}
|
||||
yield return null;
|
||||
}
|
||||
|
||||
private void ForceInit()
|
||||
{
|
||||
TargetCamera.position = m_RoamingAnchors[0].Position;
|
||||
switch (m_RoamingAnchors[0].LookType)
|
||||
{
|
||||
case LookType.PATH:
|
||||
TargetCamera.LookAt(m_RoamingAnchors[1].Position);
|
||||
break;
|
||||
case LookType.TRANSFORM:
|
||||
TargetCamera.LookAt(m_RoamingAnchors[1].LookTransform);
|
||||
break;
|
||||
case LookType.POINT:
|
||||
TargetCamera.LookAt(m_RoamingAnchors[1].LookPoint);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
_Next_Index = 1;
|
||||
_Anchor_Point = new List<RoamingAnchor>(m_RoamingAnchors);
|
||||
}
|
||||
|
||||
public Vector3 Lerp(Vector3 _a, Vector3 _b, float _t)
|
||||
{
|
||||
if (_t <= 0)
|
||||
{
|
||||
return _a;
|
||||
}
|
||||
else if (_t >= 1)
|
||||
{
|
||||
return _b;
|
||||
}
|
||||
|
||||
return _a + (_b - _a) * _t;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,8 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 1dd3b57be54dc384c9941537ee3c134d
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
|
@ -0,0 +1,45 @@
|
|||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEditor;
|
||||
|
||||
[CustomEditor(typeof(RoamingAnchor)),CanEditMultipleObjects]
|
||||
public class RoamingAnchorEditor : Editor
|
||||
{
|
||||
RoamingAnchor _target;
|
||||
SerializedProperty LookTransform;
|
||||
SerializedProperty LookPoint;
|
||||
SerializedProperty LookType;
|
||||
|
||||
private void OnEnable()
|
||||
{
|
||||
_target = (RoamingAnchor)target;
|
||||
|
||||
LookTransform = serializedObject.FindProperty("LookTransform");
|
||||
LookPoint = serializedObject.FindProperty("LookPoint");
|
||||
LookType = serializedObject.FindProperty("LookType");
|
||||
}
|
||||
|
||||
public override void OnInspectorGUI()
|
||||
{
|
||||
//base.OnInspectorGUI();
|
||||
serializedObject.Update();
|
||||
|
||||
EditorGUILayout.PropertyField(LookType);
|
||||
switch (_target.LookType)
|
||||
{
|
||||
case global::LookType.PATH:
|
||||
break;
|
||||
case global::LookType.TRANSFORM:
|
||||
EditorGUILayout.PropertyField(LookTransform);
|
||||
break;
|
||||
case global::LookType.POINT:
|
||||
EditorGUILayout.PropertyField(LookPoint);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
serializedObject.ApplyModifiedProperties();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 9ac8cd38c5ff6774ab31c68b6e6fdb0d
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
|
@ -1,33 +1,38 @@
|
|||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class RoamingAnchor : MonoBehaviour
|
||||
{
|
||||
/// <summary>
|
||||
/// 锚点编号
|
||||
/// </summary>
|
||||
public int Index;
|
||||
/// <summary>
|
||||
/// 视角
|
||||
/// </summary>
|
||||
public Vector3 Angle;
|
||||
/// <summary>
|
||||
/// 位置
|
||||
/// </summary>
|
||||
public Vector3 Position => transform.position;
|
||||
/// <summary>
|
||||
/// 路径用时
|
||||
/// </summary>
|
||||
public float Duration;
|
||||
|
||||
//public void Init()
|
||||
// {
|
||||
// Position = transform.position;
|
||||
// }
|
||||
|
||||
//public void OnDrawGizmos()
|
||||
//{
|
||||
// Gizmos.DrawGUITexture()
|
||||
//}
|
||||
}
|
||||
using JetBrains.Annotations;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class RoamingAnchor : MonoBehaviour
|
||||
{
|
||||
/// <summary>
|
||||
/// 锚点编号
|
||||
/// </summary>
|
||||
public int Index;
|
||||
/// <summary>
|
||||
/// 视角
|
||||
/// </summary>
|
||||
public Vector3 Angle;
|
||||
/// <summary>
|
||||
/// 位置
|
||||
/// </summary>
|
||||
public Vector3 Position => transform.position;
|
||||
/// <summary>
|
||||
/// 路径用时
|
||||
/// </summary>
|
||||
public float Duration;
|
||||
|
||||
public Transform LookTransform;
|
||||
public Vector3 LookPoint;
|
||||
|
||||
public LookType LookType = LookType.PATH;
|
||||
//public void Init()
|
||||
// {
|
||||
// Position = transform.position;
|
||||
// }
|
||||
|
||||
//public void OnDrawGizmos()
|
||||
//{
|
||||
// Gizmos.DrawGUITexture()
|
||||
//}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue