FadeUi 이벤트 순서 오류 및 동적 할당 오류 수정

This commit is contained in:
NTG_Lenovo 2025-07-22 16:46:07 +09:00
parent 10dbd0dc62
commit 4d9fd78c3a
2 changed files with 13 additions and 10 deletions

View File

@ -35,7 +35,7 @@ public class TimeScaleChangeEvent : IEvent
public class FadeInEvent : IEvent
{
public float Duration;
public TaskCompletionSource<bool> CompletionSource;
public TaskCompletionSource<bool> CompletionSource = new();
public Task WaitAsync() => CompletionSource.Task;
}
@ -43,7 +43,7 @@ public class FadeInEvent : IEvent
public class FadeOutEvent : IEvent
{
public float Duration;
public TaskCompletionSource<bool> CompletionSource;
public TaskCompletionSource<bool> CompletionSource = new();
public Task WaitAsync() => CompletionSource.Task;
}

View File

@ -6,19 +6,24 @@ namespace DDD
public class FadeUi : MonoBehaviour, IEventHandler<FadeInEvent>, IEventHandler<FadeOutEvent>
{
private CanvasGroup _canvasGroup;
private GameObject _panel;
private void Awake()
{
_canvasGroup = GetComponent<CanvasGroup>();
_panel = transform.Find(CommonConstants.Panel).gameObject;
_canvasGroup.alpha = 0f;
_canvasGroup.gameObject.SetActive(false);
_panel.SetActive(false);
}
private void OnEnable()
{
EventBus.Register<FadeInEvent>(this);
EventBus.Register<FadeOutEvent>(this);
}
private void OnDestroy()
private void OnDisable()
{
EventBus.Unregister<FadeInEvent>(this);
EventBus.Unregister<FadeOutEvent>(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)