[UI] 스킬 퀵슬롯 UI 구현

- SkillSlotUI: 개별 슬롯 (아이콘, 쿨다운 오버레이, 텍스트)
- SkillQuickSlotUI: 6개 슬롯 관리 및 PlayerSkillInput 연동
- Animator 제어 문제 해결: 수동 SetActive로 쿨다운 표시
- UI_Bar에 PlayerHUD, StatBar 컴포넌트 추가

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-03-10 20:58:28 +09:00
parent 2ac491683f
commit 8add066c3c
9 changed files with 2472 additions and 926 deletions

View File

@@ -0,0 +1,142 @@
using UnityEngine;
using Colosseum.Player;
using Colosseum.Skills;
namespace Colosseum.UI
{
/// <summary>
/// 스킬 퀵슬롯 UI 관리자.
/// PlayerSkillInput과 연동하여 쿨타임, 마나 등을 표시합니다.
/// </summary>
public class SkillQuickSlotUI : MonoBehaviour
{
[Header("Skill Slots")]
[Tooltip("6개의 스킬 슬롯 UI (인덱스 순서대로)")]
[SerializeField] private SkillSlotUI[] skillSlots = new SkillSlotUI[6];
[Header("Debug")]
[SerializeField] private bool debugMode = false;
[Header("Keybind Labels")]
[Tooltip("키바인딩 표시 텍스트 (기본: Q, W, E, R, A, S)")]
[SerializeField] private string[] keyLabels = { "Q", "W", "E", "R", "A", "S" };
private PlayerSkillInput playerSkillInput;
private PlayerNetworkController networkController;
private void Start()
{
// 로컬 플레이어 찾기
FindLocalPlayer();
}
private void FindLocalPlayer()
{
var players = FindObjectsByType<PlayerSkillInput>(FindObjectsSortMode.None);
if (players.Length == 0)
{
Debug.LogWarning("[SkillQuickSlotUI] No PlayerSkillInput found in scene");
return;
}
foreach (var player in players)
{
if (player.IsOwner)
{
playerSkillInput = player;
networkController = player.GetComponent<PlayerNetworkController>();
Debug.Log($"[SkillQuickSlotUI] Found local player: {player.name}");
InitializeSlots();
return;
}
}
Debug.LogWarning("[SkillQuickSlotUI] No local player found (IsOwner = false)");
}
private void InitializeSlots()
{
if (playerSkillInput == null) return;
int initializedCount = 0;
for (int i = 0; i < skillSlots.Length && i < keyLabels.Length; i++)
{
SkillData skill = playerSkillInput.GetSkill(i);
string keyLabel = i < keyLabels.Length ? keyLabels[i] : (i + 1).ToString();
if (skillSlots[i] != null)
{
skillSlots[i].Initialize(i, skill, keyLabel);
if (skill != null) initializedCount++;
}
else
{
Debug.LogWarning($"[SkillQuickSlotUI] Slot {i} is not assigned");
}
}
Debug.Log($"[SkillQuickSlotUI] Initialized {initializedCount} skill slots");
}
private void Update()
{
if (playerSkillInput == null)
{
// 플레이어가 아직 없으면 다시 찾기 시도
FindLocalPlayer();
return;
}
UpdateSlotStates();
}
private float debugLogTimer = 0f;
private void UpdateSlotStates()
{
bool shouldLog = debugMode && Time.time > debugLogTimer;
if (shouldLog) debugLogTimer = Time.time + 1f;
for (int i = 0; i < skillSlots.Length; i++)
{
if (skillSlots[i] == null) continue;
SkillData skill = playerSkillInput.GetSkill(i);
if (skill == null) continue;
float remainingCooldown = playerSkillInput.GetRemainingCooldown(i);
float totalCooldown = skill.Cooldown;
bool hasEnoughMana = networkController == null || networkController.Mana >= skill.ManaCost;
if (shouldLog && remainingCooldown > 0f)
{
Debug.Log($"[SkillQuickSlotUI] Slot {i}: {skill.SkillName}, CD: {remainingCooldown:F1}/{totalCooldown:F1}");
}
skillSlots[i].UpdateState(remainingCooldown, totalCooldown, hasEnoughMana);
}
}
/// <summary>
/// 플레이어 참조 수동 설정 (씬 전환 등에서 사용)
/// </summary>
public void SetPlayer(PlayerSkillInput player)
{
playerSkillInput = player;
networkController = player?.GetComponent<PlayerNetworkController>();
InitializeSlots();
}
/// <summary>
/// 특정 슬롯의 스킬 변경
/// </summary>
public void UpdateSkillSlot(int slotIndex, SkillData skill)
{
if (slotIndex < 0 || slotIndex >= skillSlots.Length) return;
string keyLabel = slotIndex < keyLabels.Length ? keyLabels[slotIndex] : (slotIndex + 1).ToString();
skillSlots[slotIndex].Initialize(slotIndex, skill, keyLabel);
}
}
}

View File

@@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: 637160b507db7634aba029b1624bc4a5

View File

@@ -0,0 +1,175 @@
using UnityEngine;
using UnityEngine.UI;
using TMPro;
using Colosseum.Skills;
namespace Colosseum.UI
{
/// <summary>
/// 개별 스킬 슬롯 UI
/// </summary>
public class SkillSlotUI : MonoBehaviour
{
[Header("References")]
[SerializeField] private Image iconImage;
[SerializeField] private Image cooldownOverlay;
[SerializeField] private TMP_Text cooldownText;
[SerializeField] private TMP_Text keybindText;
[Header("Settings")]
[SerializeField] private Color availableColor = Color.white;
[SerializeField] private Color cooldownColor = new Color(0.2f, 0.2f, 0.2f, 0.9f);
[SerializeField] private Color noManaColor = new Color(0.5f, 0.2f, 0.2f, 0.8f);
private SkillData skill;
private int slotIndex;
private bool useIconForCooldown = false;
private Animator cooldownAnimator; // 쿨다운 오버레이를 제어하는 Animator
private GameObject cooldownContainer; // 쿨다운 오버레이의 부모 GameObject (Cooldown)
public int SlotIndex => slotIndex;
private void Awake()
{
if (cooldownOverlay == null)
{
useIconForCooldown = true;
}
else if (cooldownOverlay.type != Image.Type.Filled)
{
useIconForCooldown = true;
}
else
{
// 쿨다운 오버레이의 상위 GameObject에 있는 Animator 찾기
// 구조: CooldownItem (Animator) -> Cooldown -> SPR_Cooldown (Image)
cooldownAnimator = cooldownOverlay.GetComponentInParent<Animator>();
// Animator가 Cooldown GameObject를 제어하므로
// 쿨다운 표시를 위해 Animator를 비활성화하고 수동으로 제어
if (cooldownAnimator != null)
{
cooldownAnimator.enabled = false;
// Animator가 제어하던 Cooldown GameObject 찾기
// SPR_Cooldown의 부모가 Cooldown
cooldownContainer = cooldownOverlay.transform.parent?.gameObject;
}
// 쿨다운 오버레이 초기화
cooldownOverlay.fillAmount = 0f;
cooldownOverlay.enabled = false;
// Cooldown 컨테이너 비활성화
if (cooldownContainer != null)
{
cooldownContainer.SetActive(false);
}
}
}
public void Initialize(int index, SkillData skillData, string keyLabel)
{
slotIndex = index;
skill = skillData;
if (keybindText != null)
keybindText.text = keyLabel;
if (skill != null && iconImage != null)
{
iconImage.sprite = skill.Icon;
iconImage.enabled = true;
iconImage.color = availableColor;
}
else if (iconImage != null)
{
iconImage.enabled = false;
}
Debug.Log($"[SkillSlotUI] Init slot {index}: skill={skillData?.SkillName}, useIcon={useIconForCooldown}");
}
public void UpdateState(float cooldownRemaining, float cooldownTotal, bool hasEnoughMana)
{
if (skill == null)
{
if (cooldownContainer != null) cooldownContainer.SetActive(false);
if (cooldownOverlay != null) cooldownOverlay.enabled = false;
if (cooldownText != null) cooldownText.text = "";
return;
}
if (cooldownRemaining > 0f)
{
float ratio = cooldownRemaining / cooldownTotal;
if (useIconForCooldown && iconImage != null)
{
// 아이콘 색상으로 쿨다운 표시
float brightness = Mathf.Lerp(0.3f, 1f, 1f - ratio);
iconImage.color = new Color(brightness, brightness, brightness, 1f);
}
else if (cooldownOverlay != null)
{
// Cooldown 컨테이너 활성화
if (cooldownContainer != null && !cooldownContainer.activeSelf)
{
cooldownContainer.SetActive(true);
}
// Image 컴포넌트 활성화
cooldownOverlay.enabled = true;
cooldownOverlay.fillAmount = ratio;
}
if (cooldownText != null)
{
cooldownText.text = cooldownRemaining < 1f
? $"{cooldownRemaining:F1}"
: $"{Mathf.CeilToInt(cooldownRemaining)}";
}
}
else
{
// 쿨다운 완료
if (useIconForCooldown && iconImage != null)
{
iconImage.color = hasEnoughMana ? availableColor : noManaColor;
}
else if (cooldownOverlay != null)
{
// Image 컴포넌트 비활성화
cooldownOverlay.enabled = false;
// Cooldown 컨테이너 비활성화
if (cooldownContainer != null)
{
cooldownContainer.SetActive(false);
}
}
if (cooldownText != null)
{
cooldownText.text = "";
}
}
}
public void SetSkill(SkillData skillData)
{
skill = skillData;
if (skill != null && iconImage != null)
{
iconImage.sprite = skill.Icon;
iconImage.enabled = true;
iconImage.color = availableColor;
}
else if (iconImage != null)
{
iconImage.enabled = false;
}
}
}
}

View File

@@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: bad7358e0082af244b16b0a515710fbc