using System; using System.Collections.Generic; using UnityEngine; using OctoCore.Navigation.Data; using OctoRef = OctoCore.OctoCore; namespace Unheimlich.Navigation.Debuging { /// /// ScriptableObject holding the ordered list of debug scenes. /// Drag OctoSceneData assets in the desired order in the inspector. /// [CreateAssetMenu(fileName = "DebugNavigation", menuName = "Unheimlich/Debug/Debug Navigation")] public class DebugNavigation : ScriptableObject { [Tooltip("Ordered list of scenes available in debug mode.")] [SerializeField] private List _scenes = new List(); public IReadOnlyList Scenes => _scenes; /// Invoked when a debug scene change is requested. public Action OnDebugSceneRequested; private int _currentIndex = -1; public int CurrentIndex => _currentIndex; /// /// Sync the current index with the active scene. /// If the active scene is not in the list, _currentIndex stays at -1 /// so Next() will correctly start at index 0. /// public void SyncWithCurrentScene(OctoSceneData currentScene) { _currentIndex = currentScene != null ? _scenes.IndexOf(currentScene) : -1; if (_currentIndex == -1) UnityEngine.Debug.Log("[DebugNavigation] Scene not found in debug list — Next() will start at index 0."); } /// Load the previous scene in the list (wraps). public void Previous() { if (_scenes == null || _scenes.Count == 0) return; // If not in list, go to last _currentIndex = (_currentIndex <= 0) ? _scenes.Count - 1 : _currentIndex - 1; RequestScene(_currentIndex); } /// Load the next scene in the list (wraps). public void Next() { if (_scenes == null || _scenes.Count == 0) return; // If not in list (-1), go to 0. Otherwise increment. _currentIndex = (_currentIndex >= _scenes.Count - 1) ? 0 : _currentIndex + 1; RequestScene(_currentIndex); } /// Load a scene by index directly (called by Debug Menu UI buttons). public void LoadByIndex(int index) { if (index < 0 || index >= _scenes.Count) { Debug.LogWarning($"[DebugNavigation] Index {index} out of range."); return; } _currentIndex = index; RequestScene(_currentIndex); } private void RequestScene(int index) { OctoSceneData scene = _scenes[index]; if (scene == null) { Debug.LogWarning($"[DebugNavigation] Scene at index {index} is null."); return; } // Don't reload the scene that's already active if (OctoRef.Instance != null && OctoRef.Instance.Navigation.CurrentScene == scene) { Debug.Log($"[DebugNavigation] Scene '{scene.SceneName}' is already loaded, skipping."); return; } OnDebugSceneRequested?.Invoke(scene); if (OctoRef.Instance) OctoRef.Instance.Navigation.LoadScene(scene); else Debug.LogError("[DebugNavigation] OctoCore instance not found."); } } }