// Cinema Suite
using CinemaDirector.Helpers;
using UnityEngine;
namespace CinemaDirector
{
[CutsceneItem("Time", "Time Scale Curve", CutsceneItemGenre.GlobalItem)]
public class TimeScaleCurveAction : CinemaGlobalAction, IRevertable
{
// The curve that controls time scale. Make sure that it goes from 0 to the duration of this action.
public AnimationCurve Curve;
// Options for reverting in editor.
[SerializeField]
private RevertMode editorRevertMode = RevertMode.Revert;
// Options for reverting during runtime.
[SerializeField]
private RevertMode runtimeRevertMode = RevertMode.Revert;
// Keep track of the GameObject's previous state when calling Trigger.
private float previousScale;
///
/// Cache the initial state of the time scale.
///
/// The Info necessary to revert this event.
public RevertInfo[] CacheState()
{
return new RevertInfo[]{ new RevertInfo(this, typeof(Time), "timeScale", Time.timeScale)};
}
///
/// Trigger the start of the time curve. Save the current time scale.
///
public override void Trigger()
{
previousScale = Time.timeScale;
}
///
/// Update the Time Scale using the animation curve.
///
/// The time of this action.
/// The time since the last update.
public override void UpdateTime(float time, float deltaTime)
{
if (Curve != null)
{
Time.timeScale = Curve.Evaluate(time);
}
}
///
/// End the Time Scale action.
///
public override void End() { }
///
/// Reset the time scale to the previous value when exiting this action in reverse.
///
public override void ReverseTrigger()
{
Time.timeScale = previousScale;
}
///
/// Option for choosing when this Event will Revert to initial state in Editor.
///
public RevertMode EditorRevertMode
{
get { return editorRevertMode; }
set { editorRevertMode = value; }
}
///
/// Option for choosing when this Event will Revert to initial state in Runtime.
///
public RevertMode RuntimeRevertMode
{
get { return runtimeRevertMode; }
set { runtimeRevertMode = value; }
}
}
}