// Cinema Suite using CinemaDirector.Helpers; using UnityEngine; namespace CinemaDirector { /// /// A simple event for Disabling a Game Object. /// [CutsceneItemAttribute("Game Object", "Disable Game Object", CutsceneItemGenre.GlobalItem)] public class DisableGameObjectGlobal : CinemaGlobalEvent, IRevertable { // The target Game Object public GameObject target; // 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 bool previousState; /// /// Cache the initial state of the target GameObject's active state. /// /// The Info necessary to revert this event. public RevertInfo[] CacheState() { if (target != null) return new RevertInfo[] { new RevertInfo(this, target, "SetActive", target.activeInHierarchy) }; return null; } /// /// Trigger this event and set the given GameObject to disabled. /// public override void Trigger() { if (target != null) { previousState = target.activeInHierarchy; target.SetActive(false); } } /// /// Reverse this Event and put the GameObject into its' previous state. /// public override void Reverse() { if (target != null) { target.SetActive(previousState); } } /// /// 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; } } } }