게임 이벤트 정적으로 변경

This commit is contained in:
NTG_Lenovo 2025-07-22 12:55:04 +09:00
parent 7319ee8541
commit e8a7e1c289
4 changed files with 56 additions and 62 deletions

View File

@ -20,6 +20,5 @@ MonoBehaviour:
- {fileID: 6471498998539637564, guid: fa2ad62c75b1549f09597e47ed5f7cfb, type: 3}
- {fileID: 7665229218737596710, guid: 71b177c2a18314c588da30429451666a, type: 3}
- {fileID: 622422277636247943, guid: d95124918e5a4a246abb0d378b14d3fa, type: 3}
- {fileID: 5136368050551183548, guid: 0aa6654feb91ef040b8b99d4f64688fc, type: 3}
- {fileID: 5539371897028506726, guid: 21cff8c1505cd8041a474795e35e0192, type: 3}
- {fileID: 8500549904376788358, guid: d81cf4649bf54485a8b0da7a235f3817, type: 3}

View File

@ -4,16 +4,25 @@
namespace DDD
{
// public static class GameEvents
// {
// public static RequestTimeScaleChangeEvent RequestTimeScaleChangeEvent = new();
// public static RequestShowGlobalMessageEvent RequestShowGlobalMessageEvent = new();
// public static InteractionEvent Interaction = new InteractionEvent();
// }
public static class GameEvents
{
public static TimeScaleChangeEvent RequestTimeScaleChangeEvent = new();
public static FadeInEvent FadeInEvent = new();
public static FadeOutEvent FadeOutEvent = new();
public static OpenScreenUiEvent OpenScreenUiEvent = new();
public static CloseScreenUiEvent CloseScreenUiEvent = new();
public static OpenPopupUiEvent OpenPopupUiEvent = new();
public static ClosePopupUiEvent ClosePopupUiEvent = new();
public static ShowGlobalMessageEvent RequestShowGlobalMessageEvent = new();
public static InteractionEvent Interaction = new();
public static InventoryChangedEvent InventoryChangedEvent = new();
}
// public static class RestaurantEvents
// {
// // Some events...
// }
// public static class VoyageEvents
// {
// // Some events...
@ -21,82 +30,51 @@ namespace DDD
public class TimeScaleChangeEvent : IEvent
{
public readonly object Requester;
public readonly float NewTimeScale;
public TimeScaleChangeEvent(object requester, float newTimeScale)
{
Requester = requester;
NewTimeScale = newTimeScale;
}
public object Requester;
public float NewTimeScale;
}
public class FadeInEvent : IEvent
{
public readonly float Duration;
public readonly TaskCompletionSource<bool> CompletionSource;
public FadeInEvent(float duration)
{
Duration = duration;
CompletionSource = new TaskCompletionSource<bool>();
}
public float Duration;
public TaskCompletionSource<bool> CompletionSource;
public Task WaitAsync() => CompletionSource.Task;
}
public class FadeOutEvent : IEvent
{
public readonly float Duration;
public readonly TaskCompletionSource<bool> CompletionSource;
public FadeOutEvent(float duration)
{
Duration = duration;
CompletionSource = new TaskCompletionSource<bool>();
}
public float Duration;
public TaskCompletionSource<bool> CompletionSource;
public Task WaitAsync() => CompletionSource.Task;
public static InventoryChangedEvent InventoryChangedEvent = new();
public static InteractionEvent Interaction = new();
}
public class ShowGlobalMessageEvent : IEvent
{
public readonly string NewMessageKey;
public readonly float ShowDuration;
public readonly float FadeDuration;
public ShowGlobalMessageEvent(string newMessageKey, float showDuration = 3f, float fadeDuration = 0.3f)
{
NewMessageKey = newMessageKey;
ShowDuration = showDuration;
FadeDuration = fadeDuration;
}
public string NewMessageKey;
public float ShowDuration;
public float FadeDuration;
}
public class OpenScreenUiEvent : IEvent
{
public readonly Type UiType;
public OpenScreenUiEvent(Type uiType) => UiType = uiType;
public Type UiType;
}
public class CloseScreenUiEvent : IEvent
{
public readonly Type UiType;
public CloseScreenUiEvent(Type uiType) => UiType = uiType;
public Type UiType;
}
public class OpenPopupUiEvent : IEvent
{
public readonly Type UiType;
public OpenPopupUiEvent(Type uiType) => UiType = uiType;
public Type UiType;
}
public class ClosePopupUiEvent : IEvent
{
public readonly Type UiType;
public ClosePopupUiEvent(Type uiType) => UiType = uiType;
public Type UiType;
}
public class InteractionEvent : IEvent

View File

@ -17,7 +17,8 @@ public class FadeSceneTransitionHandlerSo : SceneTransitionHandler
public override async Task OnBeforeSceneActivate(SceneType sceneType)
{
var evt = new FadeOutEvent(_fadeOutDuration);
var evt = GameEvents.FadeOutEvent;
evt.Duration = _fadeOutDuration;
EventBus.Broadcast(evt);
await evt.WaitAsync();
}
@ -26,8 +27,9 @@ public override async Task OnAfterSceneActivate(SceneType sceneType)
{
float seconds = _delayBeforeFadeIn * 1000;
await Task.Delay((int)(seconds));
var evt = new FadeInEvent(_fadeInDuration);
var evt = GameEvents.FadeInEvent;
evt.Duration = _fadeInDuration;
EventBus.Broadcast(evt);
await evt.WaitAsync();
}

View File

@ -78,7 +78,10 @@ private void CloseAllScreenUIs()
if (screen.IsBlockingTime)
{
EventBus.Broadcast(new TimeScaleChangeEvent(_uiPauseRequester, 1f));
var timeScaleChangeEvent = GameEvents.RequestTimeScaleChangeEvent;
timeScaleChangeEvent.Requester = _uiPauseRequester;
timeScaleChangeEvent.NewTimeScale = 1f;
EventBus.Broadcast(timeScaleChangeEvent);
}
}
}
@ -93,7 +96,10 @@ public void Invoke(OpenScreenUiEvent evt)
if (screen.IsBlockingTime)
{
EventBus.Broadcast(new TimeScaleChangeEvent(screen, 0f));
var timeScaleChangeEvent = GameEvents.RequestTimeScaleChangeEvent;
timeScaleChangeEvent.Requester = screen;
timeScaleChangeEvent.NewTimeScale = 0f;
EventBus.Broadcast(timeScaleChangeEvent);
}
}
}
@ -106,7 +112,10 @@ public void Invoke(CloseScreenUiEvent evt)
if (screen.IsBlockingTime)
{
EventBus.Broadcast(new TimeScaleChangeEvent(screen, 1f));
var timeScaleChangeEvent = GameEvents.RequestTimeScaleChangeEvent;
timeScaleChangeEvent.Requester = screen;
timeScaleChangeEvent.NewTimeScale = 1f;
EventBus.Broadcast(timeScaleChangeEvent);
}
}
}
@ -119,20 +128,26 @@ public void Invoke(OpenPopupUiEvent evt)
if (popup.IsBlockingTime)
{
EventBus.Broadcast(new TimeScaleChangeEvent(popup, 0f));
var timeScaleChangeEvent = GameEvents.RequestTimeScaleChangeEvent;
timeScaleChangeEvent.Requester = popup;
timeScaleChangeEvent.NewTimeScale = 0f;
EventBus.Broadcast(timeScaleChangeEvent);
}
}
}
public void Invoke(ClosePopupUiEvent evt)
{
if (_screenUIs.TryGetValue(evt.UiType, out var popUp))
if (_screenUIs.TryGetValue(evt.UiType, out var popup))
{
popUp.Close();
popup.Close();
if (popUp.IsBlockingTime)
if (popup.IsBlockingTime)
{
EventBus.Broadcast(new TimeScaleChangeEvent(popUp, 1f));
var timeScaleChangeEvent = GameEvents.RequestTimeScaleChangeEvent;
timeScaleChangeEvent.Requester = popup;
timeScaleChangeEvent.NewTimeScale = 1f;
EventBus.Broadcast(timeScaleChangeEvent);
}
}
}