#if HAVE_NODECANVAS using System; using UnityEngine; #if HAVE_BEAUTIFY using BeautifyEffect; #endif using ParadoxNotion.Design; using NodeCanvas.Framework; namespace Framework.Cameras { /// Adjusts the vignette effect on a camera's image [Category("Camera")] [Description("Adjusts the vignette effect on a camera's image")] public class VignetteCameraTask : ActionTask { /// Camera whose blur level will be adjusted [RequiredField] public BBParameter Camera; /// Duration of the action in seconds public float Length; /// Color the vignette effect begins with public Color StartColor; /// Color the vignette effect ends with public Color TargetColor; /// Summary of what this action does protected override string info { get { if(this.Length == 0.0f) { if(this.TargetColor.a == 0.0f) { return "Set Vignette Off"; } else if(this.TargetColor.a == 1.0f) { return "Set Vignette Full"; } else { return "Set Vignette to " + this.TargetColor.a.ToString(); } } else if(this.TargetColor.a > this.StartColor.a) { return "Camera Vignette Appears"; } else if(this.TargetColor.a < this.StartColor.a) { return "Camera Vignette Fades"; } else { return "Camera Keeps Vignette"; } } } /// Called once when the action is executed protected override void OnExecute() { bool enable = (this.StartColor.a > 0.0f) || (this.TargetColor.a > 0.0f); #if HAVE_BEAUTIFY if (this.beautify != null) { this.beautify.vignetting = enable; } #endif // HAVE_BEAUTIFY } /// Called once before the action is executed for the first time /// An error message or null if no error occurred protected override string OnInit() { string error = base.OnInit(); if(error == null) { #if !HAVE_BEAUTIFY Debug.LogError( "Camera blur tasks will not function because no effects package " + "has been enabled. Set HAVE_STANDARDEFFECTS for standard Unity blur." ); #endif #if HAVE_BEAUTIFY this.beautify = this.Camera.value.GetComponent(); if (this.beautify == null) { Debug.LogError( "Camera '" + this.Camera.name + "' does not have the 'Beautify' effect " + "on it. Vignette adjustment will not work." ); } #endif // HAVE_BEAUTIFY } return error; } /// /// Called every frame, if and while the action is running and until it ends /// protected override void OnUpdate() { float t = (elapsedTime / this.Length); Color color = Color.LerpUnclamped(this.StartColor, this.TargetColor, t); #if HAVE_BEAUTIFY if(this.beautify != null) { this.beautify.vignettingColor = color; } #endif // HAVE_BEAUTIFY if(elapsedTime >= this.Length) { EndAction(); } } /// Called once when the task ends for any reason protected override void OnStop() { base.OnStop(); #if HAVE_BEAUTIFY if (this.beautify != null) { this.beautify.vignettingColor = this.TargetColor; if (this.TargetColor.a == 0.0f) { this.beautify.vignetting = false; } } #endif // HAVE_BEAUTIFY } #if HAVE_BEAUTIFY /// All-in-one effect package [NonSerialized] private Beautify beautify; #endif // HAVE_BEAUTIFY } } // namespace Framework.Cameras #endif // HAVE_NODECANVAS && HAVE_STANDARDEFFECTS