Подробные изменения: - Добавлены сцены Bootstrap, MainMenu и Game с текущей вертикальной 9:16 структурой проекта. - Добавлены runtime-скрипты gameplay-архитектуры: DI через Extenject, спавнер платформ, прогрессия этапов, one-way платформы, игрок, камера и оборудование JumpPad. - Добавлены ScriptableObject-этапы сложности, weighted-настройки платформ, оборудования, противников и collectibles. - Добавлены UI Toolkit ресурсы главного меню, preview-материалы, шрифты, спрайты, анимации и игровые prefab-ассеты. - Перенесена и оформлена новая COM-система для работы с аппаратными портами и StreamingAssets. - Обновлены проектные гайды, AGENTS.md, правила Git/Git LFS, .gitignore, Unity Packages и ProjectSettings. - Удалён локальный skill start-required-mcp-servers из репозитория.
156 lines
4.2 KiB
C#
156 lines
4.2 KiB
C#
using UnityEngine;
|
|
using UnityEngine.SceneManagement;
|
|
using UnityEngine.UIElements;
|
|
|
|
namespace DanroJump.UI.MainMenu
|
|
{
|
|
[RequireComponent(typeof(UIDocument))]
|
|
public sealed class MainMenuController : MonoBehaviour
|
|
{
|
|
[SerializeField] private string gameplaySceneName = "Game";
|
|
[SerializeField] private string settingsSceneName = "";
|
|
|
|
private UIDocument document;
|
|
private Button startButton;
|
|
private Button settingsButton;
|
|
private Button serviceButton;
|
|
private Button quitButton;
|
|
private Label versionLabel;
|
|
|
|
private void Awake()
|
|
{
|
|
document = GetComponent<UIDocument>();
|
|
}
|
|
|
|
private void OnEnable()
|
|
{
|
|
var root = document.rootVisualElement;
|
|
|
|
startButton = root.Q<Button>("StartButton");
|
|
settingsButton = root.Q<Button>("SettingsButton");
|
|
serviceButton = root.Q<Button>("ServiceButton");
|
|
quitButton = root.Q<Button>("QuitButton");
|
|
versionLabel = root.Q<Label>("VersionLabel");
|
|
|
|
RegisterCallbacks();
|
|
RefreshStaticLabels();
|
|
}
|
|
|
|
private void OnDisable()
|
|
{
|
|
UnregisterCallbacks();
|
|
}
|
|
|
|
private void RegisterCallbacks()
|
|
{
|
|
if (startButton != null)
|
|
{
|
|
startButton.clicked += StartGame;
|
|
}
|
|
|
|
if (settingsButton != null)
|
|
{
|
|
settingsButton.clicked += OpenSettings;
|
|
}
|
|
|
|
if (serviceButton != null)
|
|
{
|
|
serviceButton.clicked += OpenServicePanel;
|
|
}
|
|
|
|
if (quitButton != null)
|
|
{
|
|
quitButton.clicked += QuitApplication;
|
|
}
|
|
}
|
|
|
|
private void UnregisterCallbacks()
|
|
{
|
|
if (startButton != null)
|
|
{
|
|
startButton.clicked -= StartGame;
|
|
}
|
|
|
|
if (settingsButton != null)
|
|
{
|
|
settingsButton.clicked -= OpenSettings;
|
|
}
|
|
|
|
if (serviceButton != null)
|
|
{
|
|
serviceButton.clicked -= OpenServicePanel;
|
|
}
|
|
|
|
if (quitButton != null)
|
|
{
|
|
quitButton.clicked -= QuitApplication;
|
|
}
|
|
}
|
|
|
|
private void RefreshStaticLabels()
|
|
{
|
|
if (versionLabel != null)
|
|
{
|
|
versionLabel.text = $"Версия: {Application.version}";
|
|
}
|
|
}
|
|
|
|
private void StartGame()
|
|
{
|
|
if (!SceneExists(gameplaySceneName))
|
|
{
|
|
Debug.LogWarning($"Gameplay scene '{gameplaySceneName}' is not available in Build Settings yet.");
|
|
return;
|
|
}
|
|
|
|
SceneManager.LoadSceneAsync(gameplaySceneName, LoadSceneMode.Single);
|
|
}
|
|
|
|
private void OpenSettings()
|
|
{
|
|
if (!string.IsNullOrWhiteSpace(settingsSceneName) && SceneExists(settingsSceneName))
|
|
{
|
|
SceneManager.LoadSceneAsync(settingsSceneName, LoadSceneMode.Single);
|
|
return;
|
|
}
|
|
|
|
Debug.Log("Main menu settings entry selected. Service settings UI will be connected later.");
|
|
}
|
|
|
|
private void OpenServicePanel()
|
|
{
|
|
Debug.Log("Service panel entry selected. Operator tools will be connected later.");
|
|
}
|
|
|
|
private void QuitApplication()
|
|
{
|
|
#if UNITY_EDITOR
|
|
UnityEditor.EditorApplication.isPlaying = false;
|
|
#else
|
|
Application.Quit();
|
|
#endif
|
|
}
|
|
|
|
private static bool SceneExists(string sceneName)
|
|
{
|
|
if (string.IsNullOrWhiteSpace(sceneName))
|
|
{
|
|
return false;
|
|
}
|
|
|
|
for (var index = 0; index < SceneManager.sceneCountInBuildSettings; index++)
|
|
{
|
|
var scenePath = SceneUtility.GetScenePathByBuildIndex(index);
|
|
var candidateName = System.IO.Path.GetFileNameWithoutExtension(scenePath);
|
|
|
|
if (candidateName == sceneName)
|
|
{
|
|
return true;
|
|
}
|
|
}
|
|
|
|
return false;
|
|
}
|
|
}
|
|
}
|