99 lines
3.5 KiB
C#
99 lines
3.5 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
using OctoCore.Navigation.Data;
|
|
using OctoRef = OctoCore.OctoCore;
|
|
|
|
namespace Unheimlich.Navigation.Debuging
|
|
{
|
|
/// <summary>
|
|
/// ScriptableObject holding the ordered list of debug scenes.
|
|
/// Drag OctoSceneData assets in the desired order in the inspector.
|
|
/// </summary>
|
|
[CreateAssetMenu(fileName = "DebugNavigation", menuName = "Unheimlich/Debug/Debug Navigation")]
|
|
public class DebugNavigation : ScriptableObject
|
|
{
|
|
[Tooltip("Ordered list of scenes available in debug mode.")]
|
|
[SerializeField] private List<OctoSceneData> _scenes = new List<OctoSceneData>();
|
|
|
|
public IReadOnlyList<OctoSceneData> Scenes => _scenes;
|
|
|
|
/// <summary>Invoked when a debug scene change is requested.</summary>
|
|
public Action<OctoSceneData> OnDebugSceneRequested;
|
|
|
|
private int _currentIndex = -1;
|
|
public int CurrentIndex => _currentIndex;
|
|
|
|
/// <summary>
|
|
/// 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.
|
|
/// </summary>
|
|
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.");
|
|
}
|
|
|
|
/// <summary>Load the previous scene in the list (wraps).</summary>
|
|
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);
|
|
}
|
|
|
|
/// <summary>Load the next scene in the list (wraps).</summary>
|
|
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);
|
|
}
|
|
|
|
/// <summary>Load a scene by index directly (called by Debug Menu UI buttons).</summary>
|
|
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.");
|
|
}
|
|
}
|
|
} |