63 lines
1.4 KiB
C#
63 lines
1.4 KiB
C#
using UnityEngine;
|
|
|
|
public class CollectionManager : MonoBehaviour, ISceneInitializable
|
|
{
|
|
public static CollectionManager Instance;
|
|
|
|
[Header("Star Data")]
|
|
private int _currentStars = 0;
|
|
|
|
[Header("CollectionHuds")]
|
|
[SerializeField] private StarPieceHud _starPieceHud;
|
|
|
|
public int GetStarCount => _currentStars;
|
|
void Awake()
|
|
{
|
|
if (Instance != null && Instance != this)
|
|
{
|
|
Destroy(gameObject);
|
|
return;
|
|
}
|
|
|
|
Instance = this;
|
|
DontDestroyOnLoad(gameObject);
|
|
}
|
|
|
|
void Start()
|
|
{
|
|
UpdateUI();
|
|
}
|
|
|
|
// SceneLoadManager가 씬 로드마다 호출. 새 씬의 StarPieceHud를 다시 찾아 연결한다.
|
|
public void OnSceneLoaded()
|
|
{
|
|
FindStarPieceHud();
|
|
UpdateUI();
|
|
}
|
|
|
|
private void FindStarPieceHud()
|
|
{
|
|
// 비활성(토글로 꺼진) HUD도 찾을 수 있도록 Include
|
|
_starPieceHud = FindFirstObjectByType<StarPieceHud>(FindObjectsInactive.Include);
|
|
|
|
if (_starPieceHud == null)
|
|
Debug.LogWarning("[CollectionManager] 현재 씬에서 StarPieceHud를 찾지 못했습니다.", this);
|
|
}
|
|
|
|
public void AddStar(int amount)
|
|
{
|
|
_currentStars += amount;
|
|
UpdateUI();
|
|
|
|
Debug.Log("Star Added: " + amount + " / Total Star: " + _currentStars);
|
|
}
|
|
|
|
void UpdateUI()
|
|
{
|
|
if(_starPieceHud != null)
|
|
{
|
|
_starPieceHud.RefreshUI();
|
|
}
|
|
}
|
|
}
|