#if HAVE_NODECANVAS using System; using UnityEngine; using ParadoxNotion.Design; using NodeCanvas.Framework; namespace Framework.Cameras { /// Fades a camera in or out [Category("Camera")] [Description("Fades a camera in or out")] public class FadeCameraTask : ActionTask { /// Camera that will be faded in or out [RequiredField] public BBParameter Camera; /// Duration of the action in seconds public float Length; /// Fade level the camera will begin with public float StartFadeLevel; /// Fade level the camera will end with public float TargetFadeLevel; /// Summary of what this action does protected override string info { get { if(this.Length == 0.0f) { if(this.TargetFadeLevel == 0.0f) { return "Set Camera Faded In"; } else if(this.TargetFadeLevel == 1.0f) { return "Set Camera Faded Out"; } else { return "Set Camera Faded " + this.TargetFadeLevel.ToString(); } } else if(this.TargetFadeLevel > this.StartFadeLevel) { return "Fade Camera Out"; } else if(this.TargetFadeLevel < this.StartFadeLevel) { return "Fade Camera In"; } else { return "Keep Camera Faded"; } } } /// Called once when the action is executed protected override void OnExecute() { this.cameraFader = this.Camera.value.GetComponent(); if(this.cameraFader == null) { Debug.LogWarning( "Camera '" + this.Camera.name + "' is missing the CameraFader " + "component. Camera fading will not work." ); } } /// /// Called every frame, if and while the action is running and until it ends /// protected override void OnUpdate() { if(this.cameraFader != null) { float level = Mathf.Lerp( this.StartFadeLevel, this.TargetFadeLevel, (elapsedTime / this.Length) ); level *= level; this.cameraFader.FadeLevel = level; } if(elapsedTime >= this.Length) { EndAction(); } } /// Called once when the task ends for any reason protected override void OnStop() { base.OnStop(); if(this.cameraFader != null) { this.cameraFader.FadeLevel = this.TargetFadeLevel; } } /// Camera controller through which the fading will be performed [NonSerialized] private CameraFader cameraFader; } } // namespace Framework.Cameras #endif // HAVE_NODECANVAS