Projext/Assets/Scripts/Level_Scripts/LevelUpUIManager.cs

95 lines
2.9 KiB
C#
Raw Normal View History

2026-01-29 06:58:38 +00:00
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI; // ⭐ 버튼 제어를 위해 필수!
2026-01-29 06:58:38 +00:00
public class LevelUpUIManager : MonoBehaviour
{
[SerializeField] private GameObject panel;
[SerializeField] private CardUI[] cardPrefabs;
[SerializeField] private Transform cardParent;
[SerializeField] private List<CardData> cardPool;
[Header("--- 확정 버튼 설정 ---")]
// ⭐ 이 변수가 있어야 인스펙터에 Apply Button 칸이 보입니다!
[SerializeField] private Button applyButton;
private CardUI _selectedCardUI; // 현재 클릭된 카드 저장용
2026-01-29 06:58:38 +00:00
private void OnEnable()
{
PlayerLevelSystem.OnLevelUp += Show;
// ⭐ 버튼 클릭 시 OnApplyButtonClick 실행하도록 연결
if (applyButton != null) applyButton.onClick.AddListener(OnApplyButtonClick);
2026-01-29 06:58:38 +00:00
}
private void OnDisable()
{
PlayerLevelSystem.OnLevelUp -= Show;
if (applyButton != null) applyButton.onClick.RemoveListener(OnApplyButtonClick);
2026-01-29 06:58:38 +00:00
}
void Show()
{
panel.SetActive(true);
Time.timeScale = 0f;
_selectedCardUI = null;
2026-02-02 10:51:54 +00:00
if (applyButton != null) applyButton.interactable = false;
2026-01-29 06:58:38 +00:00
foreach (Transform child in cardParent)
Destroy(child.gameObject);
int slotCount = 2;
2026-02-02 10:51:54 +00:00
/* =========================
* 1 CardData ( )
* ========================= */
2026-01-29 06:58:38 +00:00
List<CardData> selectedCards = new List<CardData>();
2026-02-02 10:51:54 +00:00
List<CardData> tempDataPool = new List<CardData>(cardPool);
2026-01-29 06:58:38 +00:00
2026-02-02 10:51:54 +00:00
for (int i = 0; i < slotCount; i++)
2026-01-29 06:58:38 +00:00
{
2026-02-02 10:51:54 +00:00
int idx = Random.Range(0, tempDataPool.Count);
selectedCards.Add(tempDataPool[idx]);
tempDataPool.RemoveAt(idx);
2026-01-29 06:58:38 +00:00
}
2026-02-02 10:51:54 +00:00
/* =========================
* 2 CardUI ( )
* ========================= */
List<CardUI> tempPrefabs = new List<CardUI>(cardPrefabs);
2026-01-29 06:58:38 +00:00
for (int i = 0; i < slotCount; i++)
{
2026-02-02 10:51:54 +00:00
int idx = Random.Range(0, tempPrefabs.Count);
CardUI ui = Instantiate(tempPrefabs[idx], cardParent);
ui.Setup(selectedCards[i], this);
tempPrefabs.RemoveAt(idx);
2026-01-29 06:58:38 +00:00
}
}
// 카드를 클릭했을 때 호출 (선택 상태 표시)
public void OnCardClick(CardUI clickedUI)
{
if (_selectedCardUI != null) _selectedCardUI.SetSelected(false);
_selectedCardUI = clickedUI;
_selectedCardUI.SetSelected(true);
if (applyButton != null) applyButton.interactable = true; // ⭐ 드디어 버튼 활성화!
}
// APPLY 버튼을 눌렀을 때만 최종 적용!
private void OnApplyButtonClick()
{
if (_selectedCardUI == null) return;
_selectedCardUI.ApplyCurrentEffect();
Close();
}
2026-01-29 06:58:38 +00:00
public void Close()
{
Time.timeScale = 1f;
panel.SetActive(false);
}
}