2026-06-19 UI, UI로직
This commit is contained in:
112
Assets/My project/RoomSelect/Scripts/RoomDetailUI.cs
Normal file
112
Assets/My project/RoomSelect/Scripts/RoomDetailUI.cs
Normal file
@@ -0,0 +1,112 @@
|
||||
using TMPro;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Events;
|
||||
using UnityEngine.UI;
|
||||
|
||||
public class RoomDetailUI : MonoBehaviour
|
||||
{
|
||||
[Header("References")]
|
||||
[SerializeField] private TMP_Text roomNameText;
|
||||
[SerializeField] private TMP_Text roomDescriptionText;
|
||||
[SerializeField] private TMP_Text roomStatusText;
|
||||
[SerializeField] private Button enterButton;
|
||||
[SerializeField] private TMP_Text enterButtonText;
|
||||
|
||||
[Header("Default Text")]
|
||||
[SerializeField] private string emptyNameText = "방을 선택하세요";
|
||||
[TextArea(2, 4)]
|
||||
[SerializeField] private string emptyDescriptionText = "이동할 방을 선택하면 설명이 표시됩니다.";
|
||||
[SerializeField] private string emptyStatusText = "상태: -";
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
ShowEmpty();
|
||||
}
|
||||
|
||||
public void ShowEmpty()
|
||||
{
|
||||
if (roomNameText != null)
|
||||
{
|
||||
roomNameText.text = emptyNameText;
|
||||
}
|
||||
|
||||
if (roomDescriptionText != null)
|
||||
{
|
||||
roomDescriptionText.text = emptyDescriptionText;
|
||||
}
|
||||
|
||||
if (roomStatusText != null)
|
||||
{
|
||||
roomStatusText.text = emptyStatusText;
|
||||
}
|
||||
|
||||
if (enterButtonText != null)
|
||||
{
|
||||
enterButtonText.text = "입장하기";
|
||||
}
|
||||
|
||||
if (enterButton != null)
|
||||
{
|
||||
enterButton.onClick.RemoveAllListeners();
|
||||
enterButton.interactable = false;
|
||||
}
|
||||
}
|
||||
|
||||
public void ShowRoom(RoomData roomData, RoomState state, int currentMemoryPieces, UnityAction enterAction)
|
||||
{
|
||||
if (roomData == null)
|
||||
{
|
||||
ShowEmpty();
|
||||
return;
|
||||
}
|
||||
|
||||
if (roomNameText != null)
|
||||
{
|
||||
roomNameText.text = roomData.RoomName;
|
||||
}
|
||||
|
||||
if (roomDescriptionText != null)
|
||||
{
|
||||
roomDescriptionText.text = roomData.Description;
|
||||
}
|
||||
|
||||
if (roomStatusText != null)
|
||||
{
|
||||
roomStatusText.text = GetStatusText(roomData, state, currentMemoryPieces);
|
||||
}
|
||||
|
||||
bool canEnter = state != RoomState.Locked;
|
||||
|
||||
if (enterButtonText != null)
|
||||
{
|
||||
enterButtonText.text = canEnter ? "입장하기" : "입장 불가";
|
||||
}
|
||||
|
||||
if (enterButton != null)
|
||||
{
|
||||
enterButton.onClick.RemoveAllListeners();
|
||||
enterButton.interactable = canEnter;
|
||||
|
||||
if (canEnter && enterAction != null)
|
||||
{
|
||||
enterButton.onClick.AddListener(enterAction);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private string GetStatusText(RoomData roomData, RoomState state, int currentMemoryPieces)
|
||||
{
|
||||
switch (state)
|
||||
{
|
||||
case RoomState.Locked:
|
||||
return $"잠김 - {roomData.GetLockedMessage(currentMemoryPieces)}";
|
||||
case RoomState.Cleared:
|
||||
return "클리어 완료";
|
||||
case RoomState.MemoryGot:
|
||||
return "기억의 조각 획득 완료";
|
||||
case RoomState.Unlocked:
|
||||
default:
|
||||
return "입장 가능";
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user