39e4e51866
- Implemented PlayerController.cs to manage player movement and actions. - Created PlayerState.cs to track player lives, coins, and key status. - Added CameraFollow.cs for smooth camera movement following the player. - Developed Character.cs as an abstract class for character behavior. - Introduced Enums.cs for defining TreasureType and MapElementType. - Added IDoor interface for door interactions. - Created InputActions.cs for handling player input actions. - Implemented MainMenu.cs for basic menu functionality including play and exit options.
71 lines
1.6 KiB
C#
71 lines
1.6 KiB
C#
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<bool> OnKeyStateChanged;
|
|
public event EventHandler<int> 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");
|
|
}
|
|
}
|