using System.Reflection; using UnityEngine; namespace CinemaDirector { /// /// An Event for disabling any behaviour that has an "enabled" property. /// [CutsceneItemAttribute("Game Object", "Disable Behaviour", CutsceneItemGenre.ActorItem)] public class DisableBehaviour : CinemaActorEvent { public Component Behaviour; // Options for reverting in editor. [SerializeField] private RevertMode editorRevertMode = RevertMode.Revert; // Options for reverting during runtime. [SerializeField] private RevertMode runtimeRevertMode = RevertMode.Revert; /// /// Trigger this event and Disable the chosen Behaviour. /// /// The actor to perform the behaviour disable on. public override void Trigger(GameObject actor) { Component b = actor.GetComponent(Behaviour.GetType()) as Component; if (b != null) { Behaviour.GetType().GetMember("enabled"); PropertyInfo fieldInfo = Behaviour.GetType().GetProperty("enabled"); fieldInfo.SetValue(Behaviour, false, null); } } /// /// Reverse trigger this event and Enable the chosen Behaviour. /// /// The actor to perform the behaviour enable on. public override void Reverse(GameObject actor) { Component b = actor.GetComponent(Behaviour.GetType()) as Component; if (b != null) { PropertyInfo fieldInfo = Behaviour.GetType().GetProperty("enabled"); fieldInfo.SetValue(b, true, null); } } /// /// 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; } } } }