Interactor 인터페이스에 Solver type fetch하는 함수 추가
This commit is contained in:
parent
6d1973a312
commit
8a1b13d075
@ -56,6 +56,7 @@ public interface IInteractor
|
|||||||
GameObject GetInteractorGameObject();
|
GameObject GetInteractorGameObject();
|
||||||
IInteractable GetFocusedInteractable();
|
IInteractable GetFocusedInteractable();
|
||||||
bool CanSolveInteractionType(InteractionType interactionType);
|
bool CanSolveInteractionType(InteractionType interactionType);
|
||||||
|
bool FetchSolverTypeForInteraction(InteractionType type, out Type solverType);
|
||||||
bool IsInteractionHidden(IInteractable interactable);
|
bool IsInteractionHidden(IInteractable interactable);
|
||||||
bool CanInteractTo(IInteractable interactable,
|
bool CanInteractTo(IInteractable interactable,
|
||||||
ScriptableObject payloadSo = null);
|
ScriptableObject payloadSo = null);
|
||||||
|
@ -108,7 +108,7 @@ public bool IsInteractionHidden(IInteractable interactable)
|
|||||||
return true;
|
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);
|
return RestaurantInteractionEventSolvers.TypeToSolver.TryGetValue(type, out solverType);
|
||||||
}
|
}
|
||||||
|
@ -201,7 +201,7 @@ protected IInteractable GetNearestInteractable()
|
|||||||
return closest;
|
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))
|
if (RestaurantInteractionEventSolvers.TypeToPlayerSolver.TryGetValue(type, out solverType))
|
||||||
{
|
{
|
||||||
|
@ -1,18 +1,19 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using JetBrains.Annotations;
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
|
|
||||||
namespace DDD.Restaurant
|
namespace DDD.Restaurant
|
||||||
{
|
{
|
||||||
public static class RestaurantInteractionEventSolvers
|
public static class RestaurantInteractionEventSolvers
|
||||||
{
|
{
|
||||||
public static Dictionary<InteractionType, Type> TypeToSolver = new()
|
public static readonly Dictionary<InteractionType, Type> TypeToSolver = new()
|
||||||
{
|
{
|
||||||
{InteractionType.RestaurantManagement, typeof(RestaurantManagementSolver)},
|
{InteractionType.RestaurantManagement, typeof(RestaurantManagementSolver)},
|
||||||
{InteractionType.RestaurantOrder, typeof(RestaurantOrderSolver)},
|
{InteractionType.RestaurantOrder, typeof(RestaurantOrderSolver)},
|
||||||
{InteractionType.RestaurantCook, typeof(RestaurantCookSolver)}
|
{InteractionType.RestaurantCook, typeof(RestaurantCookSolver)}
|
||||||
};
|
};
|
||||||
public static Dictionary<InteractionType, Type> TypeToPlayerSolver = new()
|
public static readonly Dictionary<InteractionType, Type> TypeToPlayerSolver = new()
|
||||||
{
|
{
|
||||||
{InteractionType.RestaurantOrder, typeof(RestaurantOrderPlayerSolver)},
|
{InteractionType.RestaurantOrder, typeof(RestaurantOrderPlayerSolver)},
|
||||||
};
|
};
|
||||||
@ -46,31 +47,28 @@ public bool RequestInteraction(GameObject causer, GameObject target, Interaction
|
|||||||
|
|
||||||
var evt = MakeInteractionEvent(causer, target, interactionType, payload);
|
var evt = MakeInteractionEvent(causer, target, interactionType, payload);
|
||||||
evt.EventResult = false;
|
evt.EventResult = false;
|
||||||
// Solve event directly. 이벤트 처리는 여기서 하고, 이벤트 호출로는 이런 이벤트가 호출되었고 결과가 어떻다는 거 전파하는 식으로.
|
|
||||||
if (RestaurantInteractionEventSolvers.TypeToSolver.TryGetValue(interactionType, out var solverType))
|
IInteractor interactor = causer.GetComponent<IInteractor>();
|
||||||
|
if (interactor != null && interactor.CanSolveInteractionType(interactionType))
|
||||||
{
|
{
|
||||||
Component solverComponent = causer.GetComponent(solverType);
|
if (interactor.FetchSolverTypeForInteraction(interactionType, out var 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)
|
|
||||||
{
|
{
|
||||||
bool canExecute = solver.CanExecuteInteraction(interactor, interactable, evt.Payload);
|
// Solve event directly. 이벤트 처리는 여기서 하고, 이벤트 호출로는 이런 이벤트가 호출되었고 결과가 어떻다는 거 전파하는 식으로.
|
||||||
if (canExecute)
|
if (solverType != null)
|
||||||
{
|
{
|
||||||
evt.EventResult = solver.ExecuteInteraction(interactor, interactable, evt.Payload);
|
IInteractionSolver solver = causer.GetComponent(solverType) as IInteractionSolver;
|
||||||
}
|
IInteractable interactable = target.GetComponent<IInteractable>();
|
||||||
else
|
if (solver is not null)
|
||||||
{
|
{
|
||||||
evt.EventResult = false;
|
bool canExecute = solver.CanExecuteInteraction(interactor, interactable, evt.Payload);
|
||||||
}
|
evt.EventResult = canExecute && solver.ExecuteInteraction(interactor, interactable, evt.Payload);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
// Should not reach here!
|
// Should not reach here!
|
||||||
Debug.Assert(false, "Solver Component or Interactor is null");
|
Debug.Assert(false, "Solver Component or Interactor is null");
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user