상호작용 시 모달 UI 추가(임시)
기타 디버깅 로그 제거
This commit is contained in:
96
Assets/Scripts/InteractableModalManager.cs
Normal file
96
Assets/Scripts/InteractableModalManager.cs
Normal file
@@ -0,0 +1,96 @@
|
||||
using UnityEngine;
|
||||
|
||||
namespace Northbound
|
||||
{
|
||||
public class InteractableModalManager : MonoBehaviour
|
||||
{
|
||||
[Header("UI Reference")]
|
||||
public InteractableModal interactableModal;
|
||||
|
||||
[Header("References")]
|
||||
[SerializeField] private PlayerInteraction playerInteraction;
|
||||
|
||||
private IInteractable _currentInteractable;
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
if (playerInteraction == null)
|
||||
{
|
||||
playerInteraction = GetComponent<PlayerInteraction>();
|
||||
}
|
||||
|
||||
if (interactableModal == null)
|
||||
{
|
||||
interactableModal = FindObjectOfType<InteractableModal>();
|
||||
}
|
||||
}
|
||||
|
||||
private void Start()
|
||||
{
|
||||
if (interactableModal != null)
|
||||
{
|
||||
interactableModal.HideModal();
|
||||
}
|
||||
}
|
||||
|
||||
private void Update()
|
||||
{
|
||||
if (playerInteraction == null)
|
||||
return;
|
||||
|
||||
IInteractable detectedInteractable = GetDetectedInteractable();
|
||||
|
||||
if (detectedInteractable != _currentInteractable)
|
||||
{
|
||||
_currentInteractable = detectedInteractable;
|
||||
|
||||
if (_currentInteractable != null)
|
||||
{
|
||||
ShowModal(_currentInteractable);
|
||||
}
|
||||
else
|
||||
{
|
||||
HideModal();
|
||||
}
|
||||
}
|
||||
else if (_currentInteractable != null)
|
||||
{
|
||||
UpdateModalContent();
|
||||
}
|
||||
}
|
||||
|
||||
private IInteractable GetDetectedInteractable()
|
||||
{
|
||||
var field = playerInteraction.GetType().GetField("_currentInteractable", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance);
|
||||
if (field != null)
|
||||
{
|
||||
return field.GetValue(playerInteraction) as IInteractable;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private void ShowModal(IInteractable interactable)
|
||||
{
|
||||
if (interactableModal != null)
|
||||
{
|
||||
interactableModal.ShowModal(interactable);
|
||||
}
|
||||
}
|
||||
|
||||
private void HideModal()
|
||||
{
|
||||
if (interactableModal != null)
|
||||
{
|
||||
interactableModal.HideModal();
|
||||
}
|
||||
}
|
||||
|
||||
private void UpdateModalContent()
|
||||
{
|
||||
if (interactableModal != null)
|
||||
{
|
||||
interactableModal.UpdateModalContent();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user