using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.Events; [CreateAssetMenu(menuName = "Events/UI/Fade Channel")] public class FadeChannelSO : ScriptableObject { public UnityAction OnEventRaised; /// /// Generic fade function. Communicates with . /// /// If true, the rectangle fades in. If false, the rectangle fades out. /// How long it takes to the image to fade in/out. /// Target color for the image to reach. Disregarded when fading out. public void Fade(bool fadeIn, float duration, Color color = default) { if (color == default && fadeIn) // If no fadein color is assigned, black is given as default. If we are supposed to fadeout the rectangle, default is simply passed through. color = Color.black; if (OnEventRaised != null) OnEventRaised.Invoke(fadeIn, duration, color); } /// /// Fade helper function to simplify usage. Fades in the rectangle. /// /// How long it takes to the image to fade in. /// Target color for the image to reach. public void FadeIn(float duration, Color color = default) { if (color == default) color = Color.black; Fade(true, duration, color); } /// /// Fade helper function to simplify usage. Fades out the rectangle. /// /// How long it takes to the image to fade out. public void FadeOut(float duration, Color color = default) { Fade(false, duration, color); } }