// Cinema Suite using CinemaDirector.Helpers; using UnityEngine; namespace CinemaDirector { /// /// An event for changing Time Scale. /// [CutsceneItem("Time", "Set Time Scale", CutsceneItemGenre.GlobalItem)] public class SetTimeScaleEvent : CinemaGlobalEvent, IRevertable { // The new timescale public float TimeScale = 1f; // 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 previous time scale when calling Trigger. private float previousTimescale = 1f; /// /// 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 this event and set a new time scale. /// public override void Trigger() { previousTimescale = Time.timeScale; Time.timeScale = TimeScale; } /// /// Reverse this event and set time scale back to it's previous state. /// public override void Reverse() { Time.timeScale = previousTimescale; } /// /// 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; } } } }