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.
116 lines
2.5 KiB
C#
116 lines
2.5 KiB
C#
using System;
|
|
using UnityEngine;
|
|
|
|
public class LevelManager : MonoBehaviour
|
|
{
|
|
public static LevelManager Instance { get; private set; }
|
|
|
|
[SerializeField] private bool _debugMode = false;
|
|
[SerializeField] private Door _doorReference;
|
|
|
|
private bool _keyCollected = false;
|
|
private bool _levelComplete = false;
|
|
|
|
public bool KeyCollected => _keyCollected;
|
|
public bool LevelComplete => _levelComplete;
|
|
|
|
public event EventHandler OnKeyCollected;
|
|
public event EventHandler OnDoorUnlocked;
|
|
public event EventHandler OnLevelComplete;
|
|
|
|
private void Awake()
|
|
{
|
|
// Singleton pattern
|
|
if (Instance != null && Instance != this)
|
|
{
|
|
Destroy(gameObject);
|
|
return;
|
|
}
|
|
|
|
Instance = this;
|
|
}
|
|
|
|
private void Start()
|
|
{
|
|
// Subscribe to GameManager key state changes
|
|
if (GameManager.Instance != null)
|
|
{
|
|
GameManager.Instance.OnKeyStateChanged += HandleKeyStateChanged;
|
|
}
|
|
}
|
|
|
|
public void NotifyKeyCollected()
|
|
{
|
|
if (_keyCollected)
|
|
return;
|
|
|
|
_keyCollected = true;
|
|
|
|
if (_debugMode)
|
|
Debug.Log("[LevelManager] Key collected!");
|
|
|
|
OnKeyCollected?.Invoke(this, EventArgs.Empty);
|
|
UnlockDoor();
|
|
}
|
|
|
|
public void UnlockDoor()
|
|
{
|
|
if (_doorReference == null)
|
|
{
|
|
Debug.LogWarning("[LevelManager] Door reference not assigned!");
|
|
return;
|
|
}
|
|
|
|
_doorReference.OpenDoor();
|
|
|
|
if (_debugMode)
|
|
Debug.Log("[LevelManager] Door unlocked!");
|
|
|
|
OnDoorUnlocked?.Invoke(this, EventArgs.Empty);
|
|
}
|
|
|
|
public void NotifyLevelComplete()
|
|
{
|
|
if (_levelComplete)
|
|
return;
|
|
|
|
_levelComplete = true;
|
|
|
|
if (_debugMode)
|
|
Debug.Log("[LevelManager] Level complete!");
|
|
|
|
OnLevelComplete?.Invoke(this, EventArgs.Empty);
|
|
|
|
// Also notify GameManager
|
|
if (GameManager.Instance != null)
|
|
{
|
|
GameManager.Instance.CompletLevel();
|
|
}
|
|
}
|
|
|
|
public void Reset()
|
|
{
|
|
_keyCollected = false;
|
|
_levelComplete = false;
|
|
|
|
if (_debugMode)
|
|
Debug.Log("[LevelManager] Reset");
|
|
}
|
|
|
|
private void HandleKeyStateChanged(object sender, bool hasKey)
|
|
{
|
|
if (hasKey && !_keyCollected)
|
|
{
|
|
NotifyKeyCollected();
|
|
}
|
|
}
|
|
|
|
private void OnDestroy()
|
|
{
|
|
if (GameManager.Instance != null)
|
|
{
|
|
GameManager.Instance.OnKeyStateChanged -= HandleKeyStateChanged;
|
|
}
|
|
}
|
|
}
|