public void FadeGraphic(Graphic uiObject, bool status) { Coroutine coroutine, newCoroutine; if (status) { uiObject.enabled = true; newCoroutine = StartCoroutine(FadeUI.FadeTo(uiObject, 1, settings.uiFadeSpeed, null)); } else { newCoroutine = StartCoroutine(FadeUI.FadeTo(uiObject, 0, settings.uiFadeSpeed, () => { uiObject.enabled = false; })); }; if (fadeCoroutines.TryGetValue(uiObject, out coroutine)) { if (coroutine != null) { StopCoroutine(coroutine); } fadeCoroutines[uiObject] = newCoroutine; } else { fadeCoroutines.Add(uiObject, coroutine); } }
public void FadeCanvasGroup(CanvasGroup fadeCanvasGroup, float alpha, float speed, Action callback = null) { var newRoutine = StartCoroutine(FadeUI.FadeTo(fadeCanvasGroup, alpha, speed, callback)); Coroutine coroutine; if (fadeCoroutines.TryGetValue(fadeCanvasGroup, out coroutine)) { if (coroutine != null) { StopCoroutine(coroutine); } fadeCoroutines[fadeCanvasGroup] = newRoutine; } else { fadeCoroutines.Add(fadeCanvasGroup, newRoutine); } }