2026-06-19 UI, UI로직
This commit is contained in:
155
Assets/My project/RhythmGame/Scripts/RhythmGameUI.cs
Normal file
155
Assets/My project/RhythmGame/Scripts/RhythmGameUI.cs
Normal file
@@ -0,0 +1,155 @@
|
||||
using System.Collections;
|
||||
using TMPro;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
public class RhythmGameUI : MonoBehaviour
|
||||
{
|
||||
[Header("Panel")]
|
||||
[SerializeField] private GameObject rhythmPanel;
|
||||
[SerializeField] private GameObject fishBonusPanel;
|
||||
[SerializeField] private GameObject finalResultPanel;
|
||||
|
||||
[Header("Text")]
|
||||
[SerializeField] private TMP_Text songTitleText;
|
||||
[SerializeField] private TMP_Text scoreText;
|
||||
[SerializeField] private TMP_Text comboText;
|
||||
[SerializeField] private TMP_Text judgmentText;
|
||||
[SerializeField] private TMP_Text fishBonusText;
|
||||
[SerializeField] private TMP_Text guideText;
|
||||
[SerializeField] private TMP_Text finalResultText;
|
||||
|
||||
[Header("Optional Images")]
|
||||
[SerializeField] private Image fishIcon;
|
||||
|
||||
[Header("Settings")]
|
||||
[SerializeField] private string defaultSongTitle = "고양이 합창단의 노래";
|
||||
[SerializeField] private string defaultGuideText = "박자에 맞춰 양동이를 두드리세요";
|
||||
[SerializeField] private float judgmentShowTime = 0.45f;
|
||||
[SerializeField] private bool hidePanelOnFinalResult = false;
|
||||
|
||||
private Coroutine judgmentRoutine;
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
InitializeUI(defaultSongTitle);
|
||||
}
|
||||
|
||||
public void InitializeUI(string songTitle = null)
|
||||
{
|
||||
SetPanelVisible(true);
|
||||
HideFinalResult();
|
||||
HideJudgment();
|
||||
ShowFishBonus(false);
|
||||
|
||||
SetSongTitle(string.IsNullOrWhiteSpace(songTitle) ? defaultSongTitle : songTitle);
|
||||
UpdateScore(0);
|
||||
UpdateCombo(0);
|
||||
SetGuideText(defaultGuideText);
|
||||
}
|
||||
|
||||
public void SetPanelVisible(bool visible)
|
||||
{
|
||||
if (rhythmPanel != null)
|
||||
rhythmPanel.SetActive(visible);
|
||||
}
|
||||
|
||||
public void SetSongTitle(string title)
|
||||
{
|
||||
if (songTitleText != null)
|
||||
songTitleText.text = title;
|
||||
}
|
||||
|
||||
public void UpdateScore(int score)
|
||||
{
|
||||
if (scoreText != null)
|
||||
scoreText.text = $"점수 {score}";
|
||||
}
|
||||
|
||||
public void UpdateCombo(int combo)
|
||||
{
|
||||
if (comboText != null)
|
||||
comboText.text = $"{combo} COMBO";
|
||||
}
|
||||
|
||||
public void SetGuideText(string text)
|
||||
{
|
||||
if (guideText != null)
|
||||
guideText.text = text;
|
||||
}
|
||||
|
||||
public void ShowFishBonus(bool active)
|
||||
{
|
||||
if (fishBonusPanel != null)
|
||||
fishBonusPanel.SetActive(active);
|
||||
|
||||
if (fishIcon != null)
|
||||
fishIcon.gameObject.SetActive(active);
|
||||
|
||||
if (fishBonusText != null)
|
||||
{
|
||||
fishBonusText.gameObject.SetActive(active);
|
||||
fishBonusText.text = active ? "생선 사용됨! 난이도 감소" : string.Empty;
|
||||
}
|
||||
}
|
||||
|
||||
public void ShowJudgment(string text)
|
||||
{
|
||||
if (judgmentText == null)
|
||||
return;
|
||||
|
||||
if (judgmentRoutine != null)
|
||||
StopCoroutine(judgmentRoutine);
|
||||
|
||||
judgmentRoutine = StartCoroutine(JudgmentRoutine(text));
|
||||
}
|
||||
|
||||
private IEnumerator JudgmentRoutine(string text)
|
||||
{
|
||||
judgmentText.gameObject.SetActive(true);
|
||||
judgmentText.text = text;
|
||||
|
||||
yield return new WaitForSeconds(judgmentShowTime);
|
||||
|
||||
judgmentText.gameObject.SetActive(false);
|
||||
judgmentRoutine = null;
|
||||
}
|
||||
|
||||
public void HideJudgment()
|
||||
{
|
||||
if (judgmentRoutine != null)
|
||||
{
|
||||
StopCoroutine(judgmentRoutine);
|
||||
judgmentRoutine = null;
|
||||
}
|
||||
|
||||
if (judgmentText != null)
|
||||
judgmentText.gameObject.SetActive(false);
|
||||
}
|
||||
|
||||
public void ShowFinalResult(string text)
|
||||
{
|
||||
HideJudgment();
|
||||
|
||||
if (hidePanelOnFinalResult)
|
||||
SetPanelVisible(false);
|
||||
|
||||
if (finalResultPanel != null)
|
||||
finalResultPanel.SetActive(true);
|
||||
|
||||
if (finalResultText != null)
|
||||
{
|
||||
finalResultText.gameObject.SetActive(true);
|
||||
finalResultText.text = text;
|
||||
}
|
||||
}
|
||||
|
||||
public void HideFinalResult()
|
||||
{
|
||||
if (finalResultPanel != null)
|
||||
finalResultPanel.SetActive(false);
|
||||
|
||||
if (finalResultText != null)
|
||||
finalResultText.gameObject.SetActive(false);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user