Danro-Jump/Assets/Scripts/Runtime/Bootstrap/StartupProtectionController.cs
Danil Iarosh 77186697f8 Prepare v0.1 gameplay and hardware foundation
Подробные изменения:

- Расширен основной gameplay loop: джетпак, новые платформы, оборудование, враги, прогрессия сложности и ограничения взаимодействий игрока.

- Добавлены Bootstrap-сервисы запуска приложения, защита, фокус окна, управление курсором и настройки сервисов через DI.

- Добавлена COM-интеграция с технической схемой Input System, обработкой кнопок/ADC, подсветкой и консольной диагностикой.

- Добавлен отдельный debug/logging модуль с каналами, обработчиками консоли и файловым выводом.

- Добавлены asmdef, link.xml, EditMode/PlayMode тесты и обновлена дорожная карта проекта.

Проверки:

- dotnet build .\\DanroJump.Runtime.csproj --no-restore

- dotnet build .\\DanroJump.Tests.EditMode.csproj --no-restore

- dotnet build .\\DanroJump.Tests.PlayMode.csproj --no-restore
2026-06-08 14:22:48 +03:00

86 lines
2.7 KiB
C#

using System.Threading;
using Cysharp.Threading.Tasks;
using UnityEngine;
namespace DanroJump.Bootstrap
{
/// <summary>
/// Запускает проверку защиты на уровне приложения до загрузки первых сцен.
/// </summary>
[DefaultExecutionOrder(-12000)]
public sealed class StartupProtectionController : MonoBehaviour
{
private static StartupProtectionController instance;
[SerializeField] private StartupProtectionOptions options = new StartupProtectionOptions();
private CancellationTokenSource lifetimeCancellation;
public static StartupProtectionState CurrentState { get; private set; } = StartupProtectionState.NotStarted;
public static bool HasInstance => instance != null;
public static async UniTask<StartupProtectionState> WaitUntilFinishedAsync(CancellationToken cancellationToken)
{
while (!IsFinished(CurrentState))
{
await UniTask.Yield(PlayerLoopTiming.Update, cancellationToken);
}
return CurrentState;
}
private void Awake()
{
if (instance != null && instance != this)
{
Destroy(gameObject);
return;
}
instance = this;
MoveToPersistentScene(gameObject);
CurrentState = StartupProtectionState.NotStarted;
lifetimeCancellation = new CancellationTokenSource();
RunStartupProtectionAsync(lifetimeCancellation.Token).Forget(Debug.LogException);
}
private void OnDestroy()
{
if (instance == this)
{
instance = null;
}
lifetimeCancellation?.Cancel();
lifetimeCancellation?.Dispose();
lifetimeCancellation = null;
}
private static void MoveToPersistentScene(GameObject gameObject)
{
if (Application.isPlaying)
{
DontDestroyOnLoad(gameObject);
}
}
private static bool IsFinished(StartupProtectionState state)
{
return state == StartupProtectionState.Skipped
|| state == StartupProtectionState.Licensed
|| state == StartupProtectionState.Failed;
}
private async UniTask RunStartupProtectionAsync(CancellationToken cancellationToken)
{
var runtime = new UnityStartupProtectionRuntime();
var checker = new WindowsLauncherLicenseChecker(runtime);
var service = new StartupProtectionService(options, checker, runtime);
CurrentState = await service.RunAsync(cancellationToken);
}
}
}