인터랙션 hidden( interactor side )과 available( interactable side ) 분리

This commit is contained in:
Jeonghyeon Ha 2025-08-28 18:16:46 +09:00
parent c1b1dbb14b
commit 3eeed819b2
8 changed files with 54 additions and 23 deletions

View File

@ -39,7 +39,7 @@ public InteractionDisplayParameters(string messageKey = "")
public interface IInteractable
{
bool CanInteract();
bool IsInteractionHidden(IInteractor interactor = null);
bool IsInteractionAvailable();
void OnInteracted(IInteractor interactor, ScriptableObject causerPayload = null);
InteractionType GetInteractionType();
GameObject GetInteractableGameObject();
@ -54,6 +54,7 @@ public interface IInteractor
GameObject GetInteractorGameObject();
IInteractable GetFocusedInteractable();
bool CanSolveInteractionType(InteractionType interactionType);
bool IsInteractionHidden(IInteractable interactable);
bool CanInteractTo(IInteractable interactable,
ScriptableObject payloadSo = null);
}
@ -62,5 +63,6 @@ public interface IInteractionSolver
{
bool ExecuteInteraction(IInteractor interactor, IInteractable interactable, ScriptableObject payload = null);
bool CanExecuteInteraction(IInteractor interactor = null, IInteractable interactable = null, ScriptableObject payload = null);
bool CanSolveInteraction(IInteractor interactor, IInteractable interactable);
}
}

View File

@ -16,11 +16,11 @@ public interface IInteractionSubsystemObject<T> : IInteractionSubsystemObject wh
}
public interface IInteractionSubsystemSolver
{
}
public interface IInteractionSubsystemSolver<T> : IInteractionSubsystemSolver where T : Enum
{
bool ExecuteInteractionSubsystem(IInteractor interactor, IInteractable interactable, ScriptableObject payload = null);
bool CanExecuteInteractionSubsystem(IInteractor interactor = null, IInteractable interactable = null, ScriptableObject payload = null);
}
public interface IInteractionSubsystemSolver<T> : IInteractionSubsystemSolver where T : Enum
{
}
}

View File

@ -82,8 +82,10 @@ private bool TryGetSolverForType(InteractionType type, out IInteractionSolver so
public bool CanSolveInteractionType(InteractionType type)
{
if (_cachedSolvers.TryGetValue(type, out var cachedSolver)) return cachedSolver != null;
if (_cachedSolvers.TryGetValue(type, out var cachedSolver))
{
return cachedSolver != null;
}
if (!FetchSolverTypeForInteraction(type, out var solverType)) return false;
if (transform.TryGetComponent(solverType, out var component) == false) return false;
@ -93,6 +95,19 @@ public bool CanSolveInteractionType(InteractionType type)
return solver != null;
}
public bool IsInteractionHidden(IInteractable interactable)
{
var interactionType = interactable.GetInteractionType();
if (GetInteractionSolver(interactionType) is var solver)
{
if (solver != null && solver.CanSolveInteraction(this, interactable))
{
return false;
}
}
return true;
}
protected virtual bool FetchSolverTypeForInteraction(InteractionType type, out Type solverType)
{
return RestaurantInteractionEventSolvers.TypeToSolver.TryGetValue(type, out solverType);

View File

@ -37,6 +37,11 @@ public bool CanSolveInteractionType(InteractionType interactionType)
return _interactionComponent.CanSolveInteractionType(interactionType);
}
public bool IsInteractionHidden(IInteractable interactable)
{
return _interactionComponent.IsInteractionHidden(interactable);
}
public bool CanInteractTo(IInteractable interactable, ScriptableObject payloadSo = null)
{
return _interactionComponent.CanInteractTo(interactable, payloadSo);

View File

@ -185,8 +185,9 @@ protected IInteractable GetNearestInteractable()
if (col.TryGetComponent<IInteractable>(out var interactable) == false) continue;
var type = interactable.GetInteractionType();
if (interactable.IsInteractionHidden(this)) continue;
if (!interactable.IsInteractionAvailable()) continue;
if (CanSolveInteractionType(type) == false) continue;
if (IsInteractionHidden(interactable)) continue;
float distance = Vector3.Distance(transform.position, col.transform.position);
if (distance < closestDistance)

View File

@ -159,7 +159,11 @@ private InteractionOutlineType GetCurrentOutlineType()
if (_interactionComponent is not IInteractable interactable)
return InteractionOutlineType.None;
if (_interactionComponent.IsInteractionHidden(_interactor))
if (!_interactionComponent.IsInteractionAvailable())
{
return InteractionOutlineType.None;
}
if (_interactor.IsInteractionHidden(_interactionComponent))
{
return InteractionOutlineType.None;
}

View File

@ -58,37 +58,28 @@ private static IEnumerable GetAllInteractionTypes()
public virtual bool CanInteract()
{
bool isInteractionVisible = !IsInteractionHidden();
bool isInteractionAvailable = IsInteractionAvailable();
bool hasValidSubsystem = true;
if (HasSubsystem(_interactionType))
{
hasValidSubsystem = GetSubsystem(_interactionType).CanInteract();
}
return isInteractionVisible && hasValidSubsystem;
return isInteractionAvailable && hasValidSubsystem;
}
public virtual bool IsInteractionHidden(IInteractor interactor = null)
public virtual bool IsInteractionAvailable()
{
var currentGameFlowState = GameFlowManager.Instance.GameFlowDataSo.CurrentGameState;
var flowDisabled = (currentGameFlowState & _interactionAvailableFlows) == 0;
if (flowDisabled)
{
return true;
}
// only check if interactor is valid. if not, pass the check.
if (interactor != null && HasSubsystem(_interactionType))
{
bool canSolve = interactor.CanSolveInteractionType(_interactionType);
if (!canSolve)
{
return true;
}
}
return false;
}
return true;
}
public virtual void OnInteracted(IInteractor interactor, ScriptableObject payload = null)
{
// TODO : Do Something cosmetic?

View File

@ -30,6 +30,19 @@ public bool CanExecuteInteraction(IInteractor interactor = null, IInteractable i
solver.CanExecuteInteractionSubsystem(interactor, interactable, payload);
}
public bool CanSolveInteraction(IInteractor interactor, IInteractable interactable)
{
if (interactable is IInteractionSubsystemOwner subsystemOwner)
{
if (subsystemOwner.TryGetSubsystemEnumType(out T subsystemType))
{
return _solvers.ContainsKey(subsystemType);
}
}
return false;
}
// Solver를 가져오는 공통 로직
private bool TryGetSolver(IInteractable interactable, out IInteractionSubsystemSolver<T> solver)
{