From 8a1b13d075c3ac90073921609896061e5b1d4f3e Mon Sep 17 00:00:00 2001 From: Jeonghyeon Ha Date: Fri, 29 Aug 2025 16:50:54 +0900 Subject: [PATCH] =?UTF-8?q?Interactor=20=EC=9D=B8=ED=84=B0=ED=8E=98?= =?UTF-8?q?=EC=9D=B4=EC=8A=A4=EC=97=90=20Solver=20type=20fetch=ED=95=98?= =?UTF-8?q?=EB=8A=94=20=ED=95=A8=EC=88=98=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../_Scripts/Game/GameEvent/IInteractable.cs | 1 + .../Character/Core/CharacterInteraction.cs | 2 +- .../Character/Player/PlayerInteraction.cs | 2 +- .../Event/RestaurantInteractionEvents.cs | 46 +++++++++---------- 4 files changed, 25 insertions(+), 26 deletions(-) diff --git a/Assets/_DDD/_Scripts/Game/GameEvent/IInteractable.cs b/Assets/_DDD/_Scripts/Game/GameEvent/IInteractable.cs index 093af0d2f..834137f1f 100644 --- a/Assets/_DDD/_Scripts/Game/GameEvent/IInteractable.cs +++ b/Assets/_DDD/_Scripts/Game/GameEvent/IInteractable.cs @@ -56,6 +56,7 @@ public interface IInteractor GameObject GetInteractorGameObject(); IInteractable GetFocusedInteractable(); bool CanSolveInteractionType(InteractionType interactionType); + bool FetchSolverTypeForInteraction(InteractionType type, out Type solverType); bool IsInteractionHidden(IInteractable interactable); bool CanInteractTo(IInteractable interactable, ScriptableObject payloadSo = null); diff --git a/Assets/_DDD/_Scripts/Restaurant/Character/Core/CharacterInteraction.cs b/Assets/_DDD/_Scripts/Restaurant/Character/Core/CharacterInteraction.cs index ee8e89e6b..7dcb8ab7a 100644 --- a/Assets/_DDD/_Scripts/Restaurant/Character/Core/CharacterInteraction.cs +++ b/Assets/_DDD/_Scripts/Restaurant/Character/Core/CharacterInteraction.cs @@ -108,7 +108,7 @@ public bool IsInteractionHidden(IInteractable interactable) return true; } - protected virtual bool FetchSolverTypeForInteraction(InteractionType type, out Type solverType) + public virtual bool FetchSolverTypeForInteraction(InteractionType type, out Type solverType) { return RestaurantInteractionEventSolvers.TypeToSolver.TryGetValue(type, out solverType); } diff --git a/Assets/_DDD/_Scripts/Restaurant/Character/Player/PlayerInteraction.cs b/Assets/_DDD/_Scripts/Restaurant/Character/Player/PlayerInteraction.cs index b22e70148..ad6c189f7 100644 --- a/Assets/_DDD/_Scripts/Restaurant/Character/Player/PlayerInteraction.cs +++ b/Assets/_DDD/_Scripts/Restaurant/Character/Player/PlayerInteraction.cs @@ -201,7 +201,7 @@ protected IInteractable GetNearestInteractable() return closest; } - protected override bool FetchSolverTypeForInteraction(InteractionType type, out Type solverType) + public override bool FetchSolverTypeForInteraction(InteractionType type, out Type solverType) { if (RestaurantInteractionEventSolvers.TypeToPlayerSolver.TryGetValue(type, out solverType)) { diff --git a/Assets/_DDD/_Scripts/Restaurant/Event/RestaurantInteractionEvents.cs b/Assets/_DDD/_Scripts/Restaurant/Event/RestaurantInteractionEvents.cs index 99e36aa31..772d4e02e 100644 --- a/Assets/_DDD/_Scripts/Restaurant/Event/RestaurantInteractionEvents.cs +++ b/Assets/_DDD/_Scripts/Restaurant/Event/RestaurantInteractionEvents.cs @@ -1,18 +1,19 @@ using System; using System.Collections.Generic; +using JetBrains.Annotations; using UnityEngine; namespace DDD.Restaurant { public static class RestaurantInteractionEventSolvers { - public static Dictionary TypeToSolver = new() + public static readonly Dictionary TypeToSolver = new() { {InteractionType.RestaurantManagement, typeof(RestaurantManagementSolver)}, {InteractionType.RestaurantOrder, typeof(RestaurantOrderSolver)}, {InteractionType.RestaurantCook, typeof(RestaurantCookSolver)} }; - public static Dictionary TypeToPlayerSolver = new() + public static readonly Dictionary TypeToPlayerSolver = new() { {InteractionType.RestaurantOrder, typeof(RestaurantOrderPlayerSolver)}, }; @@ -46,31 +47,28 @@ public bool RequestInteraction(GameObject causer, GameObject target, Interaction var evt = MakeInteractionEvent(causer, target, interactionType, payload); evt.EventResult = false; - // Solve event directly. 이벤트 처리는 여기서 하고, 이벤트 호출로는 이런 이벤트가 호출되었고 결과가 어떻다는 거 전파하는 식으로. - if (RestaurantInteractionEventSolvers.TypeToSolver.TryGetValue(interactionType, out var solverType)) + + IInteractor interactor = causer.GetComponent(); + if (interactor != null && interactor.CanSolveInteractionType(interactionType)) { - Component solverComponent = causer.GetComponent(solverType); - IInteractionSolver solver = solverComponent as IInteractionSolver; - IInteractor interactor = causer.GetComponent(); - IInteractable interactable = target.GetComponent(); - - // Cast solverComponent to IInteractable - if (solver is not null && interactor is not null) + if (interactor.FetchSolverTypeForInteraction(interactionType, out var solverType)) { - bool canExecute = solver.CanExecuteInteraction(interactor, interactable, evt.Payload); - if (canExecute) + // Solve event directly. 이벤트 처리는 여기서 하고, 이벤트 호출로는 이런 이벤트가 호출되었고 결과가 어떻다는 거 전파하는 식으로. + if (solverType != null) { - evt.EventResult = solver.ExecuteInteraction(interactor, interactable, evt.Payload); - } - else - { - evt.EventResult = false; - } - } - else - { - // Should not reach here! - Debug.Assert(false, "Solver Component or Interactor is null"); + IInteractionSolver solver = causer.GetComponent(solverType) as IInteractionSolver; + IInteractable interactable = target.GetComponent(); + if (solver is not null) + { + bool canExecute = solver.CanExecuteInteraction(interactor, interactable, evt.Payload); + evt.EventResult = canExecute && solver.ExecuteInteraction(interactor, interactable, evt.Payload); + } + else + { + // Should not reach here! + Debug.Assert(false, "Solver Component or Interactor is null"); + } + } } }