parent
da60751b32
commit
8154b7e676
@ -0,0 +1,18 @@
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
namespace CameraRoll.Client.Tool {
|
||||
public abstract class Animatable {
|
||||
protected readonly List<GameObject> PathPoints;
|
||||
|
||||
protected Animatable(List<GameObject> pathPoints) {
|
||||
PathPoints = pathPoints;
|
||||
}
|
||||
|
||||
public abstract void Animate(ref int pointIndex, Camera cam);
|
||||
public abstract void Reset();
|
||||
|
||||
protected Vector3 GetPos(int index) => PathPoints[index].transform.position;
|
||||
protected Quaternion GetRot(int index) => PathPoints[index].transform.rotation;
|
||||
}
|
||||
}
|
@ -0,0 +1,33 @@
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
namespace CameraRoll.Client.Tool {
|
||||
public class CurveAnimation : InterpolationAnimation {
|
||||
public CurveAnimation(List<GameObject> pathPoints, float speed) : base(pathPoints, speed) { }
|
||||
|
||||
public override void Animate(ref int pointIndex, Camera cam) {
|
||||
if (pointIndex >= PathPoints.Count - 1) {
|
||||
// it's the last point
|
||||
base.Animate(ref pointIndex, cam); // animate simple interpolation
|
||||
return;
|
||||
}
|
||||
|
||||
Vector3 prevPos = GetPos(pointIndex - 1);
|
||||
Vector3 middlePos = GetPos(pointIndex);
|
||||
Vector3 nextPos = GetPos(pointIndex + 1);
|
||||
Vector3 curveA = Vector3.Lerp(prevPos, middlePos, InterpolationState);
|
||||
Vector3 curveB = Vector3.Lerp(middlePos, nextPos, InterpolationState);
|
||||
cam.transform.position = Vector3.Lerp(curveA, curveB, InterpolationState);
|
||||
|
||||
Quaternion prevRot = GetRot(pointIndex - 1);
|
||||
Quaternion nextRot = GetRot(pointIndex + 1);
|
||||
cam.transform.rotation = Quaternion.Slerp(prevRot, nextRot, InterpolationState);
|
||||
|
||||
InterpolationState += Speed;
|
||||
|
||||
if (InterpolationState >= 1.0f) {
|
||||
pointIndex += 2;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,34 @@
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
namespace CameraRoll.Client.Tool {
|
||||
public class InterpolationAnimation : Animatable {
|
||||
protected float InterpolationState;
|
||||
protected readonly float Speed;
|
||||
|
||||
public InterpolationAnimation(List<GameObject> pathPoints, float speed) : base(pathPoints) {
|
||||
InterpolationState = 0.0f;
|
||||
Speed = speed;
|
||||
}
|
||||
|
||||
public override void Animate(ref int pointIndex, Camera cam) {
|
||||
Vector3 prevPos = GetPos(pointIndex - 1);
|
||||
Vector3 nextPos = GetPos(pointIndex);
|
||||
cam.transform.position = Vector3.Lerp(prevPos, nextPos, InterpolationState);
|
||||
|
||||
Quaternion prevRot = GetRot(pointIndex - 1);
|
||||
Quaternion nextRot = GetRot(pointIndex);
|
||||
cam.transform.rotation = Quaternion.Slerp(prevRot, nextRot, InterpolationState);
|
||||
|
||||
InterpolationState += Speed;
|
||||
|
||||
if (InterpolationState >= 1.0f) {
|
||||
pointIndex++;
|
||||
}
|
||||
}
|
||||
|
||||
public override void Reset() {
|
||||
InterpolationState = 0.0f;
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,15 @@
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
namespace CameraRoll.Client.Tool {
|
||||
public class TeleportAnimation : Animatable {
|
||||
public TeleportAnimation(List<GameObject> pathPoints) : base(pathPoints) { }
|
||||
|
||||
public override void Animate(ref int pointIndex, Camera cam) {
|
||||
cam.transform.position = GetPos(pointIndex);
|
||||
pointIndex++;
|
||||
}
|
||||
|
||||
public override void Reset() { }
|
||||
}
|
||||
}
|
Loading…
Reference in new issue