diff --git a/Assets/_DDD/_Scripts/GameEvent/GameEvents.cs b/Assets/_DDD/_Scripts/GameEvent/GameEvents.cs index cafd583ee..bf7a57eff 100644 --- a/Assets/_DDD/_Scripts/GameEvent/GameEvents.cs +++ b/Assets/_DDD/_Scripts/GameEvent/GameEvents.cs @@ -35,7 +35,7 @@ public class TimeScaleChangeEvent : IEvent public class FadeInEvent : IEvent { public float Duration; - public TaskCompletionSource CompletionSource; + public TaskCompletionSource CompletionSource = new(); public Task WaitAsync() => CompletionSource.Task; } @@ -43,7 +43,7 @@ public class FadeInEvent : IEvent public class FadeOutEvent : IEvent { public float Duration; - public TaskCompletionSource CompletionSource; + public TaskCompletionSource CompletionSource = new(); public Task WaitAsync() => CompletionSource.Task; } diff --git a/Assets/_DDD/_Scripts/GameUi/FadeUi.cs b/Assets/_DDD/_Scripts/GameUi/FadeUi.cs index 4469828d9..7f332230f 100644 --- a/Assets/_DDD/_Scripts/GameUi/FadeUi.cs +++ b/Assets/_DDD/_Scripts/GameUi/FadeUi.cs @@ -6,19 +6,24 @@ 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; - _canvasGroup.gameObject.SetActive(false); - + _panel.SetActive(false); + } + + private void OnEnable() + { EventBus.Register(this); EventBus.Register(this); } - private void OnDestroy() + private void OnDisable() { EventBus.Unregister(this); EventBus.Unregister(this); @@ -29,17 +34,15 @@ public async void Invoke(FadeInEvent evt) await _canvasGroup.DOFade(0f, evt.Duration) .SetUpdate(true) .AsyncWaitForCompletion(); - - _canvasGroup.blocksRaycasts = false; - _canvasGroup.gameObject.SetActive(false); + + _panel.SetActive(false); evt.CompletionSource.SetResult(true); } public async void Invoke(FadeOutEvent evt) { - _canvasGroup.gameObject.SetActive(true); - _canvasGroup.blocksRaycasts = true; + _panel.SetActive(true); await _canvasGroup.DOFade(1f, evt.Duration) .SetUpdate(true)