init
This commit is contained in:
commit
001bb14f16
951 changed files with 270074 additions and 0 deletions
105
Assets/Tools/Cinemachine/DollyTrackAnimation/CMCameraRail.cs
Normal file
105
Assets/Tools/Cinemachine/DollyTrackAnimation/CMCameraRail.cs
Normal file
|
@ -0,0 +1,105 @@
|
|||
using Cinemachine;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class CMCameraRail : MonoBehaviour{
|
||||
|
||||
[SerializeField] CinemachineVirtualCamera dollyTrackCamera = default;
|
||||
CinemachineTrackedDolly cameraTrack;
|
||||
|
||||
[Space]
|
||||
[SerializeField] Waypoint[] waypoints = default;
|
||||
int totalCount;
|
||||
int currentCount;
|
||||
|
||||
bool finished;
|
||||
bool paused;
|
||||
|
||||
float easedPercentBetweenWaypoints;
|
||||
float speed;
|
||||
float currentEase;
|
||||
float percentBetweenWaypoints;
|
||||
float nextPos;
|
||||
float lastFieldOfView;
|
||||
|
||||
void Awake(){
|
||||
totalCount = waypoints.Length - 1;
|
||||
if(dollyTrackCamera != null){
|
||||
cameraTrack = dollyTrackCamera.GetCinemachineComponent<CinemachineTrackedDolly>();
|
||||
}
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
void Update(){
|
||||
if(!finished && !paused){
|
||||
Waypoint waypoint = waypoints[currentCount];
|
||||
|
||||
if(currentCount == 0){
|
||||
speed = Time.deltaTime / waypoint.timeBetweenWaypoints * waypoint.endWaypoint;
|
||||
percentBetweenWaypoints += speed / waypoint.endWaypoint;
|
||||
percentBetweenWaypoints = Mathf.Clamp01(percentBetweenWaypoints);
|
||||
easedPercentBetweenWaypoints = Ease(percentBetweenWaypoints);
|
||||
|
||||
nextPos = easedPercentBetweenWaypoints * waypoint.endWaypoint;
|
||||
}else{
|
||||
speed = Time.deltaTime / waypoint.timeBetweenWaypoints * (waypoint.endWaypoint - waypoints[currentCount - 1].endWaypoint);
|
||||
percentBetweenWaypoints += speed / (waypoint.endWaypoint - waypoints[currentCount - 1].endWaypoint);
|
||||
percentBetweenWaypoints = Mathf.Clamp01(percentBetweenWaypoints);
|
||||
easedPercentBetweenWaypoints = Ease(percentBetweenWaypoints);
|
||||
|
||||
nextPos = waypoints[currentCount - 1].endWaypoint + easedPercentBetweenWaypoints * (waypoint.endWaypoint - waypoints[currentCount - 1].endWaypoint);
|
||||
}
|
||||
|
||||
dollyTrackCamera.m_Lens.FieldOfView = Mathf.Lerp(lastFieldOfView, waypoint.fieldOfView, easedPercentBetweenWaypoints);
|
||||
|
||||
if (cameraTrack.m_PathPosition < waypoint.endWaypoint){
|
||||
cameraTrack.m_PathPosition = nextPos;
|
||||
}else{
|
||||
NextWaypoint();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
float Ease(float x){
|
||||
if (waypoints[currentCount].ease){
|
||||
float a = currentEase + 1;
|
||||
return Mathf.Pow(x, a) / (Mathf.Pow(x, a) + Mathf.Pow(1 - x, a));
|
||||
}else{
|
||||
return x;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary> Starts playing the cutscene. </summary>
|
||||
public void StartRail(){
|
||||
lastFieldOfView = dollyTrackCamera.m_Lens.FieldOfView;
|
||||
Waypoint waypoint = waypoints[currentCount];
|
||||
if (waypoint.startDelay > 0){
|
||||
paused = true;
|
||||
StartCoroutine(DelayMovement(waypoint.startDelay));
|
||||
}
|
||||
currentEase = waypoint.ease ? waypoint.easeAmount : 1;
|
||||
}
|
||||
|
||||
void NextWaypoint(){
|
||||
lastFieldOfView = dollyTrackCamera.m_Lens.FieldOfView;
|
||||
if (currentCount >= totalCount){
|
||||
Debug.Log("Finish");
|
||||
finished = true;
|
||||
}else{
|
||||
percentBetweenWaypoints = 0;
|
||||
currentCount++;
|
||||
Waypoint waypoint = waypoints[currentCount];
|
||||
if(waypoint.startDelay > 0){
|
||||
paused = true;
|
||||
StartCoroutine(DelayMovement(waypoint.startDelay));
|
||||
}
|
||||
currentEase = waypoint.ease ? waypoint.easeAmount : 1;
|
||||
}
|
||||
}
|
||||
|
||||
IEnumerator DelayMovement(float delay){
|
||||
yield return new WaitForSeconds(delay);
|
||||
paused = false;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 6e80df5e5cd6b984396c057f7ce9a9c7
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
18
Assets/Tools/Cinemachine/DollyTrackAnimation/Waypoint.cs
Normal file
18
Assets/Tools/Cinemachine/DollyTrackAnimation/Waypoint.cs
Normal file
|
@ -0,0 +1,18 @@
|
|||
using UnityEngine;
|
||||
|
||||
[System.Serializable]
|
||||
public class Waypoint{
|
||||
|
||||
[Min(0)] public float startDelay;
|
||||
|
||||
[Header("Easing")]
|
||||
public bool ease;
|
||||
[Range(0f, 2f)] public float easeAmount;
|
||||
|
||||
[Header("Waypoints")]
|
||||
[Min(0)] public float timeBetweenWaypoints;
|
||||
[Min(0)] public int endWaypoint;
|
||||
|
||||
[Header("Field of View")]
|
||||
[Range(1, 179)] public float fieldOfView = 60;
|
||||
}
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: cbcbf05409a71c34498aea255a6ba921
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
Loading…
Add table
Add a link
Reference in a new issue