using System; using System.Collections.Generic; using UnityEngine; namespace DDD.RestaurantEvent { public static class RestaurantEvents { public static RestaurantInteractionEvent RestaurantInteraction = new(); } public static class RestaurantEventSolvers { public static Dictionary TypeToSolver = new() { {InteractionType.RestaurantManagement, typeof(RestaurantManagementEventSolver)} }; } public class RestaurantInteractionEvent : IEvent { public GameObject Causer; public GameObject Target; public InteractionType InteractionType; public ScriptableObject InteractionPayloadSo; public bool eventResult = false; public RestaurantInteractionEvent MakeInteractionEvent(GameObject causer, GameObject target, InteractionType interactionType, ScriptableObject interactionPayloadSo) { Causer = causer; Target = target; return this; } public bool RequestInteraction(GameObject causer, GameObject target, InteractionType interactionType, ScriptableObject interactionPayloadSo = null, bool shouldBroadcastAfterSolve = true) { if (interactionType == InteractionType.None) { return false; } var evt = MakeInteractionEvent(causer, target, interactionType, interactionPayloadSo); evt.eventResult = false; // Solve event directly. 이벤트 처리는 여기서 하고, 이벤트 호출로는 이런 이벤트가 호출되었고 결과가 어떻다는 거 전파하는 식으로. if (RestaurantEventSolvers.TypeToSolver.TryGetValue(interactionType, out var solverType)) { Component solverComponent = target.GetComponent(solverType); IInteractionSolver solver = solverComponent as IInteractionSolver; IInteractor interactor = causer.GetComponent(); // Cast solverComponent to IInteractable if (solver is not null && interactor is not null) { evt.eventResult = solver.ExecuteInteraction(interactor, interactionPayloadSo); } else { // Should not reach here! Debug.Assert(false, "Solver Component or Interactor is null"); } } EventBus.Broadcast(evt);// 이벤트 결과를 이거 받아서 처리하면 될듯. return evt.eventResult; } } }