using DG.Tweening; using UnityEngine; namespace DDD { public class FadeUi : MonoBehaviour, IEventHandler, IEventHandler { private CanvasGroup _canvasGroup; private GameObject _panel; private void Awake() { _canvasGroup = GetComponent(); _panel = transform.Find(CommonConstants.Panel).gameObject; _canvasGroup.alpha = 0f; _panel.SetActive(false); } private void OnEnable() { EventBus.Register(this); EventBus.Register(this); } private void OnDisable() { EventBus.Unregister(this); EventBus.Unregister(this); } public async void Invoke(FadeInEvent evt) { await _canvasGroup.DOFade(0f, evt.Duration) .SetUpdate(true) .AsyncWaitForCompletion(); _panel.SetActive(false); evt.CompletionSource.SetResult(true); } public async void Invoke(FadeOutEvent evt) { _panel.SetActive(true); await _canvasGroup.DOFade(1f, evt.Duration) .SetUpdate(true) .AsyncWaitForCompletion(); evt.CompletionSource.SetResult(true); } } }