#if HAVE_SLATE
using System;
using UnityEngine;
using Slate;
using Slate.ActionClips;
using Framework.Support;
namespace Framework.Cinematics {
/// Toggles a GameObject's renderers on or off
[Category("Material")]
[Description("Toggle the renderers on a GameObject on or off")]
public class ToggleRendererAction : ActorActionClip {
/// State to which the renderers will be toggled
public bool State = true;
/// Summary of what this action does
public override string info {
get {
if(this.State) {
return "Show";
} else {
return "Hide";
}
}
}
/// Called before the event is played back for the first time
protected override void OnEnter() {
this.renderers = actor.GetComponentsInChildren();
if(this.renderers != null) {
int rendererCount = this.renderers.Length;
this.previousStates = new bool[rendererCount];
for(int index = 0; index < rendererCount; ++index) {
this.previousStates[index] = this.renderers[index].enabled;
this.renderers[index].enabled = this.State;
}
} else {
this.previousStates = null;
}
}
/// Called when the action's effects should be reversed
///
/// Called either after the event has been scrubbed/played in reverse
/// or when the stop button is hit after the event was played.
///
protected override void OnReverse() {
if(this.renderers != null) {
int rendererCount = this.renderers.Length;
for(int index = 0; index < rendererCount; ++index) {
this.renderers[index].enabled = this.previousStates[index];
}
this.renderers = null;
}
}
/// All renderers that were toggled
private Renderer[] renderers;
/// State of the renderers before the action ran
private bool[] previousStates;
}
} // namespace Framework.Cinematics
#endif // HAVE_SLATE