This commit is contained in:
2025-03-30 16:06:57 +02:00
parent e62bd2aa6d
commit 623ba3f621
148 changed files with 2773 additions and 1441 deletions

View File

@@ -1,50 +1,59 @@
using System.Threading;
using Cysharp.Threading.Tasks;
using UnityEditor;
using UnityEngine;
using UnityEngine.SceneManagement;
namespace RebootKit.Engine.Foundation {
public static class EntryPoint {
private static readonly Logger _logger = new(nameof(EntryPoint));
static readonly Logger s_logger = new(nameof(EntryPoint));
private static CancellationTokenSource _cancellationTokenSource;
static CancellationTokenSource s_cancellationTokenSource;
[RuntimeInitializeOnLoadMethod(RuntimeInitializeLoadType.AfterSceneLoad)]
[RuntimeInitializeOnLoadMethod(RuntimeInitializeLoadType.BeforeSplashScreen)]
public static void Start() {
if (_cancellationTokenSource != null) {
_cancellationTokenSource.Cancel();
if (s_cancellationTokenSource != null) {
s_cancellationTokenSource.Cancel();
}
RR.Shared = null;
RR.s_Shared = null;
_cancellationTokenSource = new CancellationTokenSource();
SceneManager.LoadScene(0, LoadSceneMode.Single);
RunAsync(_cancellationTokenSource.Token).Forget();
s_cancellationTokenSource = new CancellationTokenSource();
RunAsync(s_cancellationTokenSource.Token).Forget();
#if UNITY_EDITOR
static void OnPlayerModeState(UnityEditor.PlayModeStateChange state) {
if (state == UnityEditor.PlayModeStateChange.ExitingPlayMode) {
_cancellationTokenSource.Cancel();
}
static void OnPlayerModeState(PlayModeStateChange state) {
if (state == PlayModeStateChange.ExitingPlayMode) s_cancellationTokenSource.Cancel();
}
UnityEditor.EditorApplication.playModeStateChanged -= OnPlayerModeState;
UnityEditor.EditorApplication.playModeStateChanged += OnPlayerModeState;
EditorApplication.playModeStateChanged -= OnPlayerModeState;
EditorApplication.playModeStateChanged += OnPlayerModeState;
#endif
}
public static async UniTask RunAsync(CancellationToken cancellationToken) {
using RR instance = new RR();
static async UniTask RunAsync(CancellationToken cancellationToken) {
s_logger.Info("Loading engine config");
EngineConfigAsset configAsset = Resources.Load<EngineConfigAsset>(RConsts.k_EngineConfigResourcesPath);
if (configAsset == null) {
s_logger.Error($"Couldn't load engine config from resources: {RConsts.k_EngineConfigResourcesPath}");
return;
}
RR.Shared = instance;
if (!configAsset.initializeOnLoad) {
return;
}
_logger.Debug("running");
using RR instance = new();
RR.s_Shared = instance;
await instance.Init(cancellationToken);
await instance.Run(cancellationToken);
_logger.Debug("stopped");
s_logger.Info("Initializing RR");
await instance.Init(configAsset, cancellationToken);
s_logger.Info("Loading main scene");
await SceneManager.LoadSceneAsync(RConsts.k_MainSceneBuildIndex, LoadSceneMode.Single).ToUniTask(cancellationToken: cancellationToken);
s_logger.Info("Starting RR");
instance.Run();
}
}
}