#if HAVE_SLATE
using System;
using UnityEngine;
using Slate;
using Slate.ActionClips;
using Framework.Support;
namespace Framework.Cinematics {
/// Changes the alpha value of a standard shader based material
[Category("Material")]
[Description("Change the transparency level of a standard shader based material")]
public class SetMaterialAlphaAction : ActorActionClip {
/// Opacity level that will be assigned to the material
public float Opacity = 0.5f;
/// Summary of what this action does
public override string info {
get { return "Material Alpha\n" + this.Opacity.ToString("0.0"); }
}
/// Called before the event is played back for the first time
protected override void OnEnter() {
this.materials = MaterialHelper.GetMeshMaterials(actor);
int materialCount = this.materials.Length;
this.previousAlpha = new float[materialCount];
for(int index = 0; index < materialCount; ++index) {
previousAlpha[index] = this.materials[index].color.a;
}
for(int index = 0; index < materialCount; ++index) {
Color color = this.materials[index].color;
color.a = previousAlpha[index] * this.Opacity;
this.materials[index].color = color;
}
}
/// 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() {
int materialCount = this.materials.Length;
for(int index = 0; index < materialCount; ++index) {
Color color = this.materials[index].color;
color.a = this.previousAlpha[index];
this.materials[index].color = color;
}
}
/// All materials in whom the opacity level will be changed
private Material[] materials;
/// Opacity levels the materials had before the action
private float[] previousAlpha;
}
} // namespace Framework.Cinematics
#endif // HAVE_SLATE