모달 UI가 각 플레이어 별로 동작하도록 함

This commit is contained in:
2026-02-04 18:46:46 +09:00
parent 4bd46b2a0a
commit 2bb4797ec5
3 changed files with 358 additions and 290 deletions

View File

@@ -1,42 +1,91 @@
using UnityEngine;
using Unity.Netcode;
namespace Northbound
{
public class InteractableModalManager : MonoBehaviour
{
[Header("UI Reference")]
[Header("UI Reference (Optional - auto-finds if null)")]
public InteractableModal interactableModal;
[Header("References")]
[SerializeField] private PlayerInteraction playerInteraction;
private IInteractable _currentInteractable;
private bool _isEnabled = false;
private void Awake()
{
Debug.Log($"[InteractableModalManager] Awake called on {gameObject.name}");
if (playerInteraction == null)
{
playerInteraction = GetComponent<PlayerInteraction>();
Debug.Log($"[InteractableModalManager] PlayerInteraction: {(playerInteraction != null ? "Found" : "Not Found")}");
}
if (interactableModal == null)
{
interactableModal = FindObjectOfType<InteractableModal>();
}
FindModalComponent();
}
private void Start()
{
Debug.Log($"[InteractableModalManager] Start called on {gameObject.name}");
FindModalComponent();
if (interactableModal != null)
{
interactableModal.HideModal();
}
else
{
Debug.LogError("[InteractableModalManager] InteractableModal is still null in Start!");
}
}
private void FindModalComponent()
{
if (interactableModal != null)
{
Debug.Log($"[InteractableModalManager] InteractableModal already assigned: {interactableModal.gameObject.name}");
return;
}
InteractableModal[] modals = GetComponentsInChildren<InteractableModal>(true);
Debug.Log($"[InteractableModalManager] Found {modals.Length} InteractableModal components in player children");
if (modals.Length > 0)
{
interactableModal = modals[0];
Debug.Log($"[InteractableModalManager] Using InteractableModal on: {interactableModal.gameObject.name}");
}
else
{
Debug.LogWarning("[InteractableModalManager] InteractableModal not found in player children!");
}
}
private void Update()
{
if (playerInteraction == null)
{
Debug.LogWarning("[InteractableModalManager] Update: playerInteraction is null");
return;
}
bool isLocalPlayer = IsLocalPlayer();
if (!isLocalPlayer)
{
if (_isEnabled)
{
HideModal();
_isEnabled = false;
}
return;
}
_isEnabled = true;
IInteractable detectedInteractable = GetDetectedInteractable();
@@ -46,10 +95,12 @@ namespace Northbound
if (_currentInteractable != null)
{
Debug.Log($"[InteractableModalManager] Show modal for interactable");
ShowModal(_currentInteractable);
}
else
{
Debug.Log($"[InteractableModalManager] Hide modal");
HideModal();
}
}
@@ -59,6 +110,19 @@ namespace Northbound
}
}
private bool IsLocalPlayer()
{
if (playerInteraction == null)
return false;
var networkObject = playerInteraction.GetComponent<Unity.Netcode.NetworkObject>();
if (networkObject != null)
{
return networkObject.IsOwner;
}
return false;
}
private IInteractable GetDetectedInteractable()
{
var field = playerInteraction.GetType().GetField("_currentInteractable", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance);