using CinemaDirector.Helpers;
using System.Collections.Generic;
using UnityEngine;
namespace CinemaDirector
{
///
/// Set the intensity of a light component of a given actor.
///
[CutsceneItemAttribute("Light", "Set Intensity", CutsceneItemGenre.ActorItem)]
public class SetIntensityLight : CinemaActorEvent, IRevertable
{
// The new intensity to be set.
public float Intensity;
// Options for reverting in editor.
[SerializeField]
private RevertMode editorRevertMode = RevertMode.Revert;
// Options for reverting during runtime.
[SerializeField]
private RevertMode runtimeRevertMode = RevertMode.Revert;
private float previousIntensity;
///
/// Cache the state of all actors related to this event.
///
///
public RevertInfo[] CacheState()
{
List actors = new List(GetActors());
List reverts = new List();
foreach (Transform go in actors)
{
if (go != null)
{
Light light = go.GetComponent();
if (light != null)
{
reverts.Add(new RevertInfo(this, light, "intensity", light.intensity));
}
}
}
return reverts.ToArray();
}
///
/// Initialize and save the original intensity state.
///
/// The actor to initialize the light intensity with.
public override void Initialize(GameObject actor)
{
Light light = actor.GetComponent();
if (light != null)
{
previousIntensity = light.intensity;
}
}
///
/// Trigger this event and change the intensity of a given actor's light component.
///
/// The actor with the light component to be altered.
public override void Trigger(GameObject actor)
{
Light light = actor.GetComponent();
if (light != null)
{
previousIntensity = light.intensity;
light.intensity = Intensity;
}
}
///
/// Reverse setting the light intensity.
///
/// The actor to reverse the light setting on.
public override void Reverse(GameObject actor)
{
Light light = actor.GetComponent();
if (light != null)
{
light.intensity = previousIntensity;
}
}
///
/// 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; }
}
}
}