2026-06-19 UI, UI로직
This commit is contained in:
82
Assets/My project/Memory Scripts/UI/MemoryProgressUI.cs
Normal file
82
Assets/My project/Memory Scripts/UI/MemoryProgressUI.cs
Normal file
@@ -0,0 +1,82 @@
|
||||
using TMPro;
|
||||
using UnityEngine;
|
||||
|
||||
public class MemoryProgressUI : MonoBehaviour
|
||||
{
|
||||
[Header("Text")]
|
||||
[SerializeField] private TMP_Text titleText;
|
||||
[SerializeField] private TMP_Text countText;
|
||||
|
||||
[Header("Piece Icons")]
|
||||
[Tooltip("획득한 조각 아이콘입니다. PieceSlot_01~05 안의 FilledIcon을 순서대로 넣으세요.")]
|
||||
[SerializeField] private GameObject[] filledIcons;
|
||||
|
||||
[Tooltip("완성 또는 획득 연출용 Glow입니다. 없어도 됩니다.")]
|
||||
[SerializeField] private GameObject[] glowIcons;
|
||||
|
||||
[Header("Optional Objects")]
|
||||
[Tooltip("5개를 모두 모았을 때 켤 전체 완성 이펙트입니다. 없어도 됩니다.")]
|
||||
[SerializeField] private GameObject completedEffect;
|
||||
|
||||
[Header("Settings")]
|
||||
[SerializeField] private int maxPieces = 5;
|
||||
[SerializeField] private string title = "기억의 조각";
|
||||
[SerializeField] private bool showGlowOnlyWhenCompleted = true;
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
if (titleText != null)
|
||||
titleText.text = title;
|
||||
|
||||
SetProgress(0, maxPieces);
|
||||
}
|
||||
|
||||
public void SetProgress(int current, int max)
|
||||
{
|
||||
maxPieces = Mathf.Max(1, max);
|
||||
current = Mathf.Clamp(current, 0, maxPieces);
|
||||
|
||||
if (titleText != null)
|
||||
titleText.text = title;
|
||||
|
||||
if (countText != null)
|
||||
countText.text = $"{current} / {maxPieces}";
|
||||
|
||||
UpdatePieceIcons(current);
|
||||
UpdateCompletedEffect(current >= maxPieces);
|
||||
}
|
||||
|
||||
private void UpdatePieceIcons(int current)
|
||||
{
|
||||
if (filledIcons != null)
|
||||
{
|
||||
for (int i = 0; i < filledIcons.Length; i++)
|
||||
{
|
||||
if (filledIcons[i] != null)
|
||||
filledIcons[i].SetActive(i < current);
|
||||
}
|
||||
}
|
||||
|
||||
if (glowIcons == null)
|
||||
return;
|
||||
|
||||
bool completed = current >= maxPieces;
|
||||
|
||||
for (int i = 0; i < glowIcons.Length; i++)
|
||||
{
|
||||
if (glowIcons[i] == null)
|
||||
continue;
|
||||
|
||||
if (showGlowOnlyWhenCompleted)
|
||||
glowIcons[i].SetActive(completed);
|
||||
else
|
||||
glowIcons[i].SetActive(i < current);
|
||||
}
|
||||
}
|
||||
|
||||
private void UpdateCompletedEffect(bool completed)
|
||||
{
|
||||
if (completedEffect != null)
|
||||
completedEffect.SetActive(completed);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user