refactor
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
using System;
|
||||
|
||||
namespace RebootKit.Engine.Services.Console {
|
||||
namespace RebootKit.Engine.Foundation {
|
||||
public enum CVarValueKind {
|
||||
Number, String
|
||||
}
|
||||
|
||||
@@ -1,68 +0,0 @@
|
||||
using System.Threading;
|
||||
using Cysharp.Threading.Tasks;
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
using UnityEngine.SceneManagement;
|
||||
|
||||
namespace RebootKit.Engine.Foundation {
|
||||
public static class EntryPoint {
|
||||
static readonly Logger s_logger = new(nameof(EntryPoint));
|
||||
|
||||
static CancellationTokenSource s_cancellationTokenSource;
|
||||
|
||||
[RuntimeInitializeOnLoadMethod(RuntimeInitializeLoadType.BeforeSplashScreen)]
|
||||
public static void Start() {
|
||||
if (s_cancellationTokenSource != null) {
|
||||
s_cancellationTokenSource.Cancel();
|
||||
}
|
||||
|
||||
RR.s_Shared = null;
|
||||
|
||||
// unload all scenes
|
||||
|
||||
s_cancellationTokenSource = new CancellationTokenSource();
|
||||
RunAsync(s_cancellationTokenSource.Token).Forget();
|
||||
|
||||
#if UNITY_EDITOR
|
||||
static void OnPlayerModeState(PlayModeStateChange state) {
|
||||
if (state == PlayModeStateChange.ExitingPlayMode) {
|
||||
s_cancellationTokenSource.Cancel();
|
||||
}
|
||||
}
|
||||
|
||||
EditorApplication.playModeStateChanged -= OnPlayerModeState;
|
||||
EditorApplication.playModeStateChanged += OnPlayerModeState;
|
||||
#endif
|
||||
}
|
||||
|
||||
static async UniTask RunAsync(CancellationToken cancellationToken) {
|
||||
s_logger.Info("Loading boot scene");
|
||||
SceneManager.LoadScene(RConsts.k_BootSceneBuildIndex, LoadSceneMode.Single);
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
if (!configAsset.initializeOnLoad) {
|
||||
return;
|
||||
}
|
||||
|
||||
using RR instance = new();
|
||||
RR.s_Shared = instance;
|
||||
|
||||
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();
|
||||
|
||||
await UniTask.WaitUntilCanceled(Application.exitCancellationToken);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,3 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 83bc8a98e30147babef3641863699cd9
|
||||
timeCreated: 1740670775
|
||||
@@ -1,5 +1,6 @@
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
using RebootKit.Engine.Main;
|
||||
|
||||
namespace RebootKit.Engine.Foundation {
|
||||
public enum LogLevel {
|
||||
@@ -19,16 +20,16 @@ namespace RebootKit.Engine.Foundation {
|
||||
public void Log(LogLevel level, string message) {
|
||||
switch (level) {
|
||||
case LogLevel.Info:
|
||||
UnityEngine.Debug.Log(FormatMessage(level, m_Name, message, true));
|
||||
RR.Log(FormatMessage(level, m_Name, message, true));
|
||||
break;
|
||||
case LogLevel.Debug:
|
||||
UnityEngine.Debug.Log(FormatMessage(level, m_Name, message, true));
|
||||
RR.Log(FormatMessage(level, m_Name, message, true));
|
||||
break;
|
||||
case LogLevel.Warning:
|
||||
UnityEngine.Debug.LogWarning(FormatMessage(level, m_Name, message, true));
|
||||
RR.LogWarning(FormatMessage(level, m_Name, message, true));
|
||||
break;
|
||||
case LogLevel.Error:
|
||||
UnityEngine.Debug.LogError(FormatMessage(level, m_Name, message, true));
|
||||
RR.LogError(FormatMessage(level, m_Name, message, true));
|
||||
break;
|
||||
default:
|
||||
throw new ArgumentOutOfRangeException(nameof(level), level, null);
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using UnityEngine;
|
||||
using RebootKit.Engine.Main;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Assertions;
|
||||
|
||||
namespace RebootKit.Engine.Foundation {
|
||||
@@ -20,7 +21,7 @@ namespace RebootKit.Engine.Foundation {
|
||||
DIContext context = RR.DIContext;
|
||||
|
||||
foreach (GameObject root in gameObject.scene.GetRootGameObjects()) {
|
||||
s_logger.Info("Injecting root game object: " + root.name);
|
||||
// s_logger.Info("Injecting root game object: " + root.name);
|
||||
context.InjectGameObject(root);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user