using System; using System.Collections.Generic; using UnityEngine; public class GameplayManager : MonoBehaviour { public static GameplayManager Instance = null; [Header("Assign levels in order (Level 1 at index 0)")] public List levels; private int currentLevelIndex = -1; private Level currentLevel; [SerializeField] private List levelStartTriggers; private void Awake() { if (Instance == null) Instance = this; else if (Instance != this) { DestroyImmediate(gameObject); return; } DontDestroyOnLoad(gameObject); // Ensure all levels are disabled initially foreach (var lvl in levels) { if (lvl != null) lvl.gameObject.SetActive(false); } var upcomingLevel = levels[0]; ObjectiveManager.Instance.SetList(upcomingLevel.config.objectives); EnableOnlyTrigger(0); } private void EnableOnlyTrigger(int index) { if (levelStartTriggers == null) return; for (int i = 0; i < levelStartTriggers.Count; i++) if (levelStartTriggers[i] != null) levelStartTriggers[i].SetActive(i == index); } public void StartLevel(int index) { if (index < 0 || index >= levels.Count) { Debug.LogError($"GameplayManager: Invalid level index {index}"); return; } // End previous level if any if (currentLevel != null) { currentLevel.OnLevelEnd(); currentLevel.gameObject.SetActive(false); } currentLevelIndex = index; currentLevel = levels[currentLevelIndex]; currentLevel.gameObject.SetActive(true); currentLevel.OnLevelStart(); Debug.Log($"GameplayManager: Started Level {currentLevelIndex + 1}"); } public void CompleteCurrentLevel() { if (currentLevel == null) return; Debug.Log($"GameplayManager: Level {currentLevelIndex + 1} completed."); currentLevel.OnLevelEnd(); currentLevel.gameObject.SetActive(false); currentLevel = null; // If you want to auto-progress: int next = currentLevelIndex + 1; // var upcomingLevel = levels[currentLevelIndex]; // ObjectiveManager.Instance.SetList(upcomingLevel.config.objectives); if (next < levels.Count) { var upcomingLevel = levels[next]; ObjectiveManager.Instance.SetList( upcomingLevel.config.objectives, upcomingLevel.config.startObjectiveIndex ); } EnableOnlyTrigger(next); // if (next < levels.Count) // { // StartLevel(next); // } // else // { // Debug.Log("GameplayManager: All levels completed!"); // } } private void LoadUpNextLevel() { int next = currentLevelIndex + 1; var upcomingLevel = levels[currentLevelIndex]; ObjectiveManager.Instance.SetList(upcomingLevel.config.objectives); } // Optional: callable by a trigger to start Level 1 specifically public void StartLevelOne() { StartLevel(0); } }