상호작용 시 모달 UI 추가(임시)
기타 디버깅 로그 제거
This commit is contained in:
90
Assets/Scripts/InteractableModal.cs
Normal file
90
Assets/Scripts/InteractableModal.cs
Normal file
@@ -0,0 +1,90 @@
|
||||
using TMPro;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Northbound
|
||||
{
|
||||
public class InteractableModal : MonoBehaviour
|
||||
{
|
||||
[Header("UI References")]
|
||||
[SerializeField] private GameObject modalPanel;
|
||||
[SerializeField] private TextMeshProUGUI keyText;
|
||||
[SerializeField] private TextMeshProUGUI interactText;
|
||||
|
||||
[Header("Settings")]
|
||||
[SerializeField] private string defaultKey = "E";
|
||||
|
||||
private IInteractable _currentInteractable;
|
||||
private Canvas _parentCanvas;
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
_parentCanvas = GetComponentInParent<Canvas>();
|
||||
}
|
||||
|
||||
private void Start()
|
||||
{
|
||||
if (modalPanel != null)
|
||||
{
|
||||
modalPanel.SetActive(false);
|
||||
}
|
||||
}
|
||||
|
||||
public void ShowModal(IInteractable interactable)
|
||||
{
|
||||
if (interactable == null)
|
||||
{
|
||||
HideModal();
|
||||
return;
|
||||
}
|
||||
|
||||
_currentInteractable = interactable;
|
||||
|
||||
if (modalPanel != null)
|
||||
{
|
||||
modalPanel.SetActive(true);
|
||||
UpdateModalContent();
|
||||
}
|
||||
}
|
||||
|
||||
public void HideModal()
|
||||
{
|
||||
_currentInteractable = null;
|
||||
|
||||
if (modalPanel != null)
|
||||
{
|
||||
modalPanel.SetActive(false);
|
||||
}
|
||||
}
|
||||
|
||||
public void UpdateModalContent()
|
||||
{
|
||||
if (_currentInteractable == null)
|
||||
return;
|
||||
|
||||
if (keyText != null)
|
||||
{
|
||||
keyText.text = defaultKey;
|
||||
}
|
||||
|
||||
if (interactText != null)
|
||||
{
|
||||
string prompt = _currentInteractable.GetInteractionPrompt();
|
||||
interactText.text = ExtractInteractText(prompt);
|
||||
}
|
||||
}
|
||||
|
||||
private string ExtractInteractText(string prompt)
|
||||
{
|
||||
if (string.IsNullOrEmpty(prompt))
|
||||
return string.Empty;
|
||||
|
||||
int startIndex = prompt.IndexOf(']');
|
||||
if (startIndex >= 0 && startIndex + 1 < prompt.Length)
|
||||
{
|
||||
return prompt.Substring(startIndex + 1).Trim();
|
||||
}
|
||||
|
||||
return prompt;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user