Interactor 인터페이스에 Solver type fetch하는 함수 추가
This commit is contained in:
parent
6d1973a312
commit
8a1b13d075
@ -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);
|
||||
|
@ -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);
|
||||
}
|
||||
|
@ -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))
|
||||
{
|
||||
|
@ -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<InteractionType, Type> TypeToSolver = new()
|
||||
public static readonly Dictionary<InteractionType, Type> TypeToSolver = new()
|
||||
{
|
||||
{InteractionType.RestaurantManagement, typeof(RestaurantManagementSolver)},
|
||||
{InteractionType.RestaurantOrder, typeof(RestaurantOrderSolver)},
|
||||
{InteractionType.RestaurantCook, typeof(RestaurantCookSolver)}
|
||||
};
|
||||
public static Dictionary<InteractionType, Type> TypeToPlayerSolver = new()
|
||||
public static readonly Dictionary<InteractionType, Type> 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))
|
||||
{
|
||||
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)
|
||||
IInteractor interactor = causer.GetComponent<IInteractor>();
|
||||
if (interactor != null && interactor.CanSolveInteractionType(interactionType))
|
||||
{
|
||||
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);
|
||||
IInteractionSolver solver = causer.GetComponent(solverType) as IInteractionSolver;
|
||||
IInteractable interactable = target.GetComponent<IInteractable>();
|
||||
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");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
evt.EventResult = false;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// Should not reach here!
|
||||
Debug.Assert(false, "Solver Component or Interactor is null");
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user