using System; using UnityEngine; public class GameManager : MonoBehaviour { public static GameManager Instance { get; private set; } [SerializeField] private bool _debugMode = false; private bool _hasKey = false; private int _treasureCount = 0; public bool HasKey => _hasKey; public int TreasureCount => _treasureCount; public event EventHandler OnKeyStateChanged; public event EventHandler OnTreasureCountChanged; public event EventHandler OnLevelComplete; private void Awake() { // Singleton pattern if (Instance != null && Instance != this) { Destroy(gameObject); return; } Instance = this; DontDestroyOnLoad(gameObject); } public void SetKeyState(bool hasKey) { if (_hasKey == hasKey) return; _hasKey = hasKey; OnKeyStateChanged?.Invoke(this, _hasKey); if (_debugMode) Debug.Log($"[GameManager] Key state changed: {_hasKey}"); } public void AddTreasure(int amount = 1) { _treasureCount += amount; OnTreasureCountChanged?.Invoke(this, _treasureCount); if (_debugMode) Debug.Log($"[GameManager] Treasure count: {_treasureCount}"); } public void CompletLevel() { if (_debugMode) Debug.Log("[GameManager] Level completed!"); OnLevelComplete?.Invoke(this, EventArgs.Empty); } public void Reset() { _hasKey = false; _treasureCount = 0; if (_debugMode) Debug.Log("[GameManager] Reset"); } }