90 lines
2.6 KiB
C#
90 lines
2.6 KiB
C#
using OctoCore.Navigation.Data;
|
|
using OctoCore.UI;
|
|
using UnityEngine;
|
|
using UnityEngine.EventSystems;
|
|
using UnityEngine.UI;
|
|
|
|
namespace OctoCore.Navigation
|
|
{
|
|
/// <summary>
|
|
/// Main menu manager.
|
|
/// Handles Play, Quit and optional extra buttons.
|
|
/// Relies on OctoCore.Navigation for scene loading.
|
|
/// </summary>
|
|
public class OctoMainMenu : MonoBehaviour
|
|
{
|
|
[Header("Scene Settings")]
|
|
[SerializeField, Tooltip("First scene to load on Play")]
|
|
private OctoSceneData _firstSceneData;
|
|
|
|
[Header("UI Settings")]
|
|
[SerializeField, Tooltip("Optional panel to show/hide (options, credits...)")]
|
|
private GameObject _optionalPanel;
|
|
|
|
[SerializeField] private Button _optionalPanelFirstButton;
|
|
[SerializeField] private Button _mainPanelDefaultButton;
|
|
|
|
void Awake()
|
|
{
|
|
// Hide optional panel on start if assigned
|
|
if (_optionalPanel)
|
|
_optionalPanel.SetActive(false);
|
|
|
|
// Make sure cursor is visible in main menu
|
|
Cursor.visible = true;
|
|
Cursor.lockState = CursorLockMode.None;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Load the first scene. Called by the Play button.
|
|
/// </summary>
|
|
public void OnPlayButton()
|
|
{
|
|
if (!OctoCore.Instance)
|
|
{
|
|
Debug.LogError("[OctoMainMenu] OctoCore instance not found");
|
|
return;
|
|
}
|
|
|
|
if (_firstSceneData == null)
|
|
{
|
|
Debug.LogError("[OctoMainMenu] FirstSceneData is null");
|
|
return;
|
|
}
|
|
|
|
OctoCore.Instance.Navigation.LoadScene(_firstSceneData);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Quit the application. Called by the Quit button.
|
|
/// </summary>
|
|
public void OnQuitButton()
|
|
{
|
|
Application.Quit();
|
|
#if UNITY_EDITOR
|
|
UnityEditor.EditorApplication.isPlaying = false;
|
|
#endif
|
|
}
|
|
|
|
/// <summary>
|
|
/// Toggle an optional panel (options, credits...). Called by any extra button.
|
|
/// </summary>
|
|
public void OnTogglePanel()
|
|
{
|
|
if (_optionalPanel)
|
|
_optionalPanel.SetActive(!_optionalPanel.activeSelf);
|
|
}
|
|
|
|
// --- Add your custom button methods below ---
|
|
|
|
public void SelectDebugFirstButton()
|
|
{
|
|
EventSystem.current.SetSelectedGameObject(_optionalPanelFirstButton.gameObject);
|
|
}
|
|
|
|
public void SelectMainDefaultButton()
|
|
{
|
|
EventSystem.current.SetSelectedGameObject(_mainPanelDefaultButton.gameObject);
|
|
}
|
|
}
|
|
} |