using CinemaDirector.Helpers;
using System.Collections.Generic;
using UnityEngine;
namespace CinemaDirector
{
///
/// Enable the Actor related to this event.
///
[CutsceneItemAttribute("Game Object", "Temporary Enable", CutsceneItemGenre.ActorItem)]
public class EnableGameObjectAction : CinemaActorAction, IRevertable
{
// Options for reverting in editor.
[SerializeField]
private RevertMode editorRevertMode = RevertMode.Revert;
// Options for reverting during runtime.
[SerializeField]
private RevertMode runtimeRevertMode = RevertMode.Revert;
///
/// Cache the state of all actors related to this event.
///
/// All the revert info related to this event.
public RevertInfo[] CacheState()
{
List actors = new List(GetActors());
List reverts = new List();
foreach (Transform go in actors)
{
if (go != null)
{
reverts.Add(new RevertInfo(this, go.gameObject, "SetActive", go.gameObject.activeSelf));
}
}
return reverts.ToArray();
}
///
/// Enable the given actor temporarily.
///
/// The actor to be enabled.
public override void Trigger(GameObject actor)
{
if (actor != null)
{
actor.SetActive(true);
}
}
///
/// End the action and disable the game object.
///
/// The actor.
public override void End(GameObject actor)
{
if (actor != null)
{
actor.SetActive(false);
}
}
///
/// The trigger time has been hit while playing in reverse. disable the action.
///
/// The actor to disable
public override void ReverseTrigger(GameObject Actor)
{
this.End(Actor);
}
///
/// The end time has been hit while playing in reverse. enable the action.
///
/// The actor to enable
public override void ReverseEnd(GameObject Actor)
{
Trigger(Actor);
}
///
/// Set the action to an arbitrary time.
///
/// The current actor.
/// the running time of the action
/// The deltaTime since the last update call.
public override void SetTime(GameObject actor, float time, float deltaTime)
{
if (actor != null)
{
actor.SetActive(time >= 0 && time < Duration);
}
}
///
/// 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; }
}
}
}