174 lines
5.8 KiB
C#
174 lines
5.8 KiB
C#
|
using System.Collections;
|
|||
|
using System.Collections.Generic;
|
|||
|
using UnityEngine;
|
|||
|
using UnityEngine.UI;
|
|||
|
using Cinemachine;
|
|||
|
using Games.Events;
|
|||
|
using UnityEngine.Playables;
|
|||
|
|
|||
|
public class CinePathCreate : MonoBehaviour
|
|||
|
{
|
|||
|
public enum PointType
|
|||
|
{
|
|||
|
None,
|
|||
|
MainPlayer,
|
|||
|
MainCamera,
|
|||
|
}
|
|||
|
|
|||
|
[System.Serializable]
|
|||
|
public class PathPointInfo
|
|||
|
{
|
|||
|
public PointType _pointType;
|
|||
|
public Vector3 _pointPos;
|
|||
|
public int _pointIndex;
|
|||
|
}
|
|||
|
|
|||
|
private float startTime = -1;
|
|||
|
private float endTime = -1;
|
|||
|
|
|||
|
public float delayMove = 0;
|
|||
|
public float PauseTime = 0;
|
|||
|
public CinemachineSmoothPath _SmoothPath;
|
|||
|
public CinemachineDollyCart _CineDollCart = null;
|
|||
|
public PathPointInfo[] PathPoints;
|
|||
|
|
|||
|
public CinePathCreate _NextCinePath = null;
|
|||
|
|
|||
|
private bool _ActiveStart = false;
|
|||
|
public bool ActiveStart
|
|||
|
{
|
|||
|
set { _ActiveStart = value;
|
|||
|
if(_ActiveStart && _CineDollCart!=null)
|
|||
|
{
|
|||
|
_CineDollCart.m_Position = 0;
|
|||
|
Start();
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
private void Start()
|
|||
|
{
|
|||
|
startTime = Time.time + delayMove;
|
|||
|
if(_ActiveStart)
|
|||
|
DollCartInitPost();
|
|||
|
AddCreateWayPoint();
|
|||
|
if (_CineDollCart != null)
|
|||
|
{
|
|||
|
float overtime = _SmoothPath.PathLength / _CineDollCart.m_Speed;
|
|||
|
endTime = Time.time + overtime + delayMove + PauseTime;
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
private void DollCartInitPost()
|
|||
|
{
|
|||
|
if (_CineDollCart == null)
|
|||
|
return;
|
|||
|
PathPointInfo point = null;
|
|||
|
if(PathPoints!=null)
|
|||
|
{
|
|||
|
for (int i = 0; i < PathPoints.Length; i++)
|
|||
|
{
|
|||
|
if (PathPoints[i]._pointIndex == 0)
|
|||
|
point = PathPoints[i];
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
if(point==null)
|
|||
|
{
|
|||
|
if(_SmoothPath.m_Waypoints.Length > 0)
|
|||
|
_CineDollCart.transform.position = _SmoothPath.transform.TransformPoint( _SmoothPath.m_Waypoints[0].position);
|
|||
|
return;
|
|||
|
}
|
|||
|
if(point._pointType == PointType.None)
|
|||
|
{
|
|||
|
_CineDollCart.transform.position = point._pointPos;
|
|||
|
}
|
|||
|
if(point._pointType == PointType.MainPlayer && Singleton<ObjManager>.Instance.MainPlayer!=null)
|
|||
|
{
|
|||
|
_CineDollCart.transform.position = Singleton<ObjManager>.Instance.MainPlayer.Position;
|
|||
|
}
|
|||
|
if(point._pointType == PointType.MainCamera)
|
|||
|
{
|
|||
|
Transform trans = null;
|
|||
|
if (Games.Scene.SceneLogic.CameraController != null && Games.Scene.SceneLogic.CameraController.MainCamera != null)
|
|||
|
trans = Games.Scene.SceneLogic.CameraController.MainCamera.transform;
|
|||
|
else if (Camera.main != null)
|
|||
|
trans = Camera.main.transform;
|
|||
|
if(trans!=null)
|
|||
|
{
|
|||
|
_CineDollCart.transform.position = trans.position;
|
|||
|
_CineDollCart.transform.eulerAngles = trans.eulerAngles;
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
private void AddCreateWayPoint()
|
|||
|
{
|
|||
|
if (_SmoothPath == null || PathPoints == null || PathPoints.Length<=0)
|
|||
|
return;
|
|||
|
List<CinemachineSmoothPath.Waypoint> points = new List<CinemachineSmoothPath.Waypoint>(_SmoothPath.m_Waypoints);
|
|||
|
|
|||
|
for (int i = 0; i < PathPoints.Length; i++)
|
|||
|
{
|
|||
|
PathPointInfo point = PathPoints[i];
|
|||
|
if (point == null)
|
|||
|
continue;
|
|||
|
CinemachineSmoothPath.Waypoint Waypoint = new CinemachineSmoothPath.Waypoint();
|
|||
|
if (point._pointType == PointType.MainCamera && Games.Scene.SceneLogic.CameraController != null)
|
|||
|
{
|
|||
|
if (Camera.main == null && Games.Scene.SceneLogic.CameraController == null && Games.Scene.SceneLogic.CameraController.MainCamera != null)
|
|||
|
continue;
|
|||
|
if (Games.Scene.SceneLogic.CameraController != null && Games.Scene.SceneLogic.CameraController.MainCamera!=null)
|
|||
|
Waypoint.position = _SmoothPath.transform.InverseTransformPoint(Games.Scene.SceneLogic.CameraController.MainCamera.transform.position);
|
|||
|
else
|
|||
|
Waypoint.position = _SmoothPath.transform.InverseTransformPoint(Camera.main.transform.position);
|
|||
|
}
|
|||
|
if (point._pointType == PointType.MainPlayer)
|
|||
|
{
|
|||
|
if (Singleton<ObjManager>.Instance.MainPlayer == null)
|
|||
|
continue;
|
|||
|
Vector3 FocusOffset = Vector3.zero;
|
|||
|
if (Games.Scene.SceneLogic.CameraController != null)
|
|||
|
FocusOffset = Games.Scene.SceneLogic.CameraController.FocusOffset;
|
|||
|
Waypoint.position = _SmoothPath.transform.InverseTransformPoint(Singleton<ObjManager>.Instance.MainPlayer.Position + FocusOffset);
|
|||
|
}
|
|||
|
if (point._pointType == PointType.None)
|
|||
|
{
|
|||
|
Waypoint.position = point._pointPos;
|
|||
|
}
|
|||
|
if (point._pointIndex <= 0)
|
|||
|
points.Insert(0, Waypoint);
|
|||
|
else if (point._pointIndex > points.Count)
|
|||
|
points.Add(Waypoint);
|
|||
|
else
|
|||
|
points.Insert(point._pointIndex, Waypoint);
|
|||
|
}
|
|||
|
_SmoothPath.m_Waypoints = points.ToArray();
|
|||
|
PathPoints = null;
|
|||
|
}
|
|||
|
|
|||
|
private void Update()
|
|||
|
{
|
|||
|
if (_ActiveStart == false)
|
|||
|
return;
|
|||
|
if(_CineDollCart!=null && startTime >=0 && startTime - Time.time<=0)
|
|||
|
{
|
|||
|
startTime = -1;
|
|||
|
_CineDollCart.m_Position = 0;
|
|||
|
_CineDollCart.m_Path = _SmoothPath;
|
|||
|
}
|
|||
|
|
|||
|
if(endTime >= 0 && endTime - Time.time <=0 )
|
|||
|
{
|
|||
|
endTime = -1;
|
|||
|
if (_NextCinePath != null)
|
|||
|
{
|
|||
|
_CineDollCart.m_Path = null;
|
|||
|
_CineDollCart.m_Position = 0;
|
|||
|
_NextCinePath.ActiveStart = true;
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
}
|