95 lines
2.9 KiB
C#
95 lines
2.9 KiB
C#
using System.Collections;
|
||
using System.Collections.Generic;
|
||
using UnityEngine;
|
||
using UnityEngine.UI; // ⭐ 버튼 제어를 위해 필수!
|
||
|
||
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; // 현재 클릭된 카드 저장용
|
||
|
||
private void OnEnable()
|
||
{
|
||
PlayerLevelSystem.OnLevelUp += Show;
|
||
// ⭐ 버튼 클릭 시 OnApplyButtonClick 실행하도록 연결
|
||
if (applyButton != null) applyButton.onClick.AddListener(OnApplyButtonClick);
|
||
}
|
||
|
||
private void OnDisable()
|
||
{
|
||
PlayerLevelSystem.OnLevelUp -= Show;
|
||
if (applyButton != null) applyButton.onClick.RemoveListener(OnApplyButtonClick);
|
||
}
|
||
|
||
void Show()
|
||
{
|
||
panel.SetActive(true);
|
||
Time.timeScale = 0f;
|
||
|
||
_selectedCardUI = null;
|
||
if (applyButton != null) applyButton.interactable = false;
|
||
|
||
foreach (Transform child in cardParent)
|
||
Destroy(child.gameObject);
|
||
|
||
int slotCount = 2;
|
||
|
||
/* =========================
|
||
* 1️⃣ CardData 선택 (중복 없음)
|
||
* ========================= */
|
||
List<CardData> selectedCards = new List<CardData>();
|
||
List<CardData> tempDataPool = new List<CardData>(cardPool);
|
||
|
||
for (int i = 0; i < slotCount; i++)
|
||
{
|
||
int idx = Random.Range(0, tempDataPool.Count);
|
||
selectedCards.Add(tempDataPool[idx]);
|
||
tempDataPool.RemoveAt(idx);
|
||
}
|
||
|
||
/* =========================
|
||
* 2️⃣ CardUI 프리팹 선택 (중복 없음)
|
||
* ========================= */
|
||
List<CardUI> tempPrefabs = new List<CardUI>(cardPrefabs);
|
||
|
||
for (int i = 0; i < slotCount; i++)
|
||
{
|
||
int idx = Random.Range(0, tempPrefabs.Count);
|
||
CardUI ui = Instantiate(tempPrefabs[idx], cardParent);
|
||
ui.Setup(selectedCards[i], this);
|
||
tempPrefabs.RemoveAt(idx);
|
||
}
|
||
}
|
||
|
||
// 카드를 클릭했을 때 호출 (선택 상태 표시)
|
||
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();
|
||
}
|
||
|
||
public void Close()
|
||
{
|
||
Time.timeScale = 1f;
|
||
panel.SetActive(false);
|
||
}
|
||
} |