69 lines
2.7 KiB
C#
69 lines
2.7 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
|
|
namespace DDD
|
|
{
|
|
public static class RestaurantInteractionEvents
|
|
{
|
|
public static RestaurantInteractionEvent RestaurantInteraction = new();
|
|
}
|
|
|
|
public static class RestaurantInteractionEventSolvers
|
|
{
|
|
public static Dictionary<InteractionType, Type> TypeToSolver = new()
|
|
{
|
|
{InteractionType.RestaurantManagementUi, typeof(RestaurantManagementUiEventSolver)}
|
|
};
|
|
}
|
|
|
|
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 (RestaurantInteractionEventSolvers.TypeToSolver.TryGetValue(interactionType, out var solverType))
|
|
{
|
|
Component solverComponent = causer.GetComponent(solverType);
|
|
IInteractionSolver solver = solverComponent as IInteractionSolver;
|
|
IInteractor interactor = causer.GetComponent<IInteractor>();
|
|
IInteractable interactable = target.GetComponent<IInteractable>();
|
|
|
|
// Cast solverComponent to IInteractable
|
|
if (solver is not null && interactor is not null)
|
|
{
|
|
evt.EventResult = solver.ExecuteInteraction(interactor, interactable, interactionPayloadSo);
|
|
}
|
|
else
|
|
{
|
|
// Should not reach here!
|
|
Debug.Assert(false, "Solver Component or Interactor is null");
|
|
}
|
|
}
|
|
|
|
EventBus.Broadcast(evt);// 이벤트 결과를 이거 받아서 처리하면 될듯.
|
|
return evt.EventResult;
|
|
}
|
|
}
|
|
} |