/// <summary> /// Slowly fades the object and then deactivates it. /// </summary> /// <param name="image"> The UI component that will be subject to the colour fade. </param> /// <param name="deActivateTime"> The total time in seconds it will take to deactivate the object. </param> /// <param name="fadePoint"> The seconds after which the fading will start. </param> /// <param name="resetColor"> If set to true, the object will be reset to its original transparency after being deactivated. </param> public static void FadeDeActivate(object UIComponent, float deActivateTime, float fadePoint, bool resetColor) { FadeRoutineInfo info = new FadeRoutineInfo(); info.resetColor = resetColor; info.type = FadeType.DeActivate; info.theObject = UIComponent; if (UIComponent is Image) { //image info.routine = singleton.StartCoroutine(singleton.DeActivateImageFadeEnumerator(UIComponent as Image, deActivateTime, fadePoint, resetColor)); Color c = (UIComponent as Image).color; info.originalColor = new Color(c.r, c.g, c.b, c.a); info.objectType = typeof(Image); FadeRoutines.Add(info); } else if (UIComponent is TMP_Text) { //tmp text info.routine = singleton.StartCoroutine(singleton.DeActivateTmpTextFadeEnumerator(UIComponent as TMP_Text, deActivateTime, fadePoint, resetColor)); Color c = (UIComponent as TMP_Text).color; info.originalColor = new Color(c.r, c.g, c.b, c.a); info.objectType = typeof(TMP_Text); FadeRoutines.Add(info); } else { Debug.LogError("UI component type not defined!"); } }
/// <summary> /// Slowly fades the object and then deactivates it. /// </summary> /// <param name="image"> The UI component that will be subject to the colour fade. </param> /// <param name="duration"> The total time in seconds it will take to fade the object. </param> public static void Fade(object UIComponent, float duration) { FadeRoutineInfo info = new FadeRoutineInfo(); info.resetColor = false; info.type = FadeType.Nothing; info.theObject = UIComponent; if (UIComponent is Image) { //image info.routine = singleton.StartCoroutine(singleton.ImageFadeEnumerator(UIComponent as Image, duration)); FadeRoutines.Add(info); info.objectType = typeof(Image); } else if (UIComponent is TMP_Text) { //tmp text singleton.StartCoroutine(singleton.TmpTextFadeEnumerator(UIComponent as TMP_Text, duration)); FadeRoutines.Add(info); info.objectType = typeof(TMP_Text); } else { Debug.LogError("UI component type not defined!"); } }
/// <summary> /// Slowly fades the object and destroys it in the end. /// </summary> /// <param name="UIComponent"> The UI component that will be subject to the colour fade. </param> /// <param name="destructionTime"> The total time in seconds it will take to destroy the object. </param> /// <param name="fadePoint"> The seconds after which the fading will start </param> public static void FadeDestroy(object UIComponent, float destructionTime, float fadePoint) { FadeRoutineInfo info = new FadeRoutineInfo(); info.resetColor = false; info.type = FadeType.Destroy; info.theObject = UIComponent; if (UIComponent is Image) { //image info.routine = singleton.StartCoroutine(singleton.DestroyImageFadeEnumerator(UIComponent as Image, destructionTime, fadePoint)); info.objectType = typeof(Image); FadeRoutines.Add(info); } else if (UIComponent is TMP_Text) { //tmp text info.routine = singleton.StartCoroutine(singleton.DestroyTmpTextFadeEnumerator(UIComponent as TMP_Text, destructionTime, fadePoint)); info.objectType = typeof(Image); FadeRoutines.Add(info); } else { Debug.LogError("UI component type not defined!"); } }