DI updates
This commit is contained in:
@@ -1,3 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 8e389af561a242dba68aea66075684fd
|
||||
timeCreated: 1740888613
|
||||
@@ -12,8 +12,7 @@ MonoBehaviour:
|
||||
m_Script: {fileID: 19101, guid: 0000000000000000e000000000000000, type: 0}
|
||||
m_Name: Panel Settings
|
||||
m_EditorClassIdentifier:
|
||||
themeUss: {fileID: -4733365628477956816, guid: 5dd55e8f9f3419144b6d6fc3fcc478d0,
|
||||
type: 3}
|
||||
themeUss: {fileID: -4733365628477956816, guid: 5dd55e8f9f3419144b6d6fc3fcc478d0, type: 3}
|
||||
m_DisableNoThemeWarning: 0
|
||||
m_TargetTexture: {fileID: 0}
|
||||
m_RenderMode: 0
|
||||
|
||||
@@ -1,2 +1,16 @@
|
||||
fileFormatVersion: 2
|
||||
guid: ae5fb4e9fdf89f64b8d2e2d147cb0231
|
||||
guid: ae5fb4e9fdf89f64b8d2e2d147cb0231
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences:
|
||||
- ConsoleService: {fileID: 11400000, guid: c5c519d68547d704da8672695e382c08, type: 2}
|
||||
- InputService: {fileID: 11400000, guid: 64a8b10c553e44f488e183dd04990761, type: 2}
|
||||
- WorldService: {fileID: 11400000, guid: d6d951b44dc41664fb301e470fac8f80, type: 2}
|
||||
- GameService: {fileID: 11400000, guid: 75254d95c14787546b733dc1b448fb3d, type: 2}
|
||||
- StartingGameMode: {instanceID: 0}
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
|
||||
@@ -58,9 +58,7 @@ namespace RebootKit.Engine.Foundation {
|
||||
Type type = typeof(T);
|
||||
|
||||
foreach (FieldInfo field in type.GetFields(k_fieldsBindingFlags)) {
|
||||
if (!InjectField(field, target)) {
|
||||
return;
|
||||
}
|
||||
InjectField(field, target);
|
||||
}
|
||||
|
||||
foreach (MethodInfo method in type.GetMethods(k_methodsBindingFlags)) {
|
||||
|
||||
@@ -1,15 +1,11 @@
|
||||
using System;
|
||||
using System.Threading;
|
||||
using Cysharp.Threading.Tasks;
|
||||
using UnityEngine;
|
||||
|
||||
namespace RebootKit.Engine.Foundation {
|
||||
public interface IService : IDisposable {
|
||||
UniTask OnInit(CancellationToken cancellationToken);
|
||||
}
|
||||
|
||||
public abstract class ServiceMonoBehaviour : MonoBehaviour, IService {
|
||||
public abstract UniTask OnInit(CancellationToken cancellationToken);
|
||||
public abstract void Dispose();
|
||||
}
|
||||
|
||||
|
||||
@@ -1,6 +1,4 @@
|
||||
using System.Threading;
|
||||
using Cysharp.Threading.Tasks;
|
||||
using RebootKit.Engine.Foundation;
|
||||
using RebootKit.Engine.Foundation;
|
||||
using UnityEngine;
|
||||
|
||||
namespace RebootKit.Engine.Graphics {
|
||||
@@ -8,10 +6,6 @@ namespace RebootKit.Engine.Graphics {
|
||||
[field: SerializeField]
|
||||
public Camera Camera { get; private set; }
|
||||
|
||||
public override async UniTask OnInit(CancellationToken cancellationToken) {
|
||||
await UniTask.Yield(cancellationToken);
|
||||
}
|
||||
|
||||
public override void Dispose() {
|
||||
}
|
||||
}
|
||||
|
||||
@@ -46,8 +46,10 @@ namespace RebootKit.Engine {
|
||||
_diContext = new DIContext();
|
||||
_diContext.AddInjector(new CVarFieldInjector());
|
||||
|
||||
await CreateCoreServices(cancellationToken);
|
||||
await RegisterServicesFromMainSceneAsync(cancellationToken);
|
||||
CreateCoreServices();
|
||||
InstallMainScene();
|
||||
|
||||
await UniTask.Yield(cancellationToken);
|
||||
}
|
||||
|
||||
public async UniTask Run(CancellationToken cancellationToken) {
|
||||
@@ -55,25 +57,23 @@ namespace RebootKit.Engine {
|
||||
await _gameService.Start(_engineConfigAsset.StartingGameMode, cancellationToken);
|
||||
}
|
||||
|
||||
private async UniTask<TService> CreateServiceAsync<TService>(ServiceAsset<TService> asset, CancellationToken cancellationToken = default) where TService : IService {
|
||||
private TService CreateService<TService>(ServiceAsset<TService> asset) where TService : IService {
|
||||
TService service = asset.Create();
|
||||
_diContext.Bind<TService>(service);
|
||||
_diContext.Bind(service);
|
||||
_diContext.Inject(service);
|
||||
|
||||
await service.OnInit(cancellationToken);
|
||||
return service;
|
||||
}
|
||||
|
||||
private async UniTask CreateCoreServices(CancellationToken cancellationToken) {
|
||||
private void CreateCoreServices() {
|
||||
Logger.Debug("Registering core services");
|
||||
|
||||
_consoleService = await CreateServiceAsync(_engineConfigAsset.ConsoleService, cancellationToken);
|
||||
_inputService = await CreateServiceAsync(_engineConfigAsset.InputService, cancellationToken);
|
||||
_worldService = await CreateServiceAsync(_engineConfigAsset.WorldService, cancellationToken);
|
||||
_gameService = await CreateServiceAsync(_engineConfigAsset.GameService, cancellationToken);
|
||||
_consoleService = CreateService(_engineConfigAsset.ConsoleService);
|
||||
_inputService = CreateService(_engineConfigAsset.InputService);
|
||||
_worldService = CreateService(_engineConfigAsset.WorldService);
|
||||
_gameService = CreateService(_engineConfigAsset.GameService);
|
||||
}
|
||||
|
||||
private async UniTask RegisterServicesFromMainSceneAsync(CancellationToken cancellationToken = default) {
|
||||
private void InstallMainScene() {
|
||||
GameObject[] gameObjects = SceneManager.GetSceneByBuildIndex(RConsts.MainSceneBuildIndex).GetRootGameObjects();
|
||||
if (gameObjects.Length == 0) {
|
||||
return;
|
||||
@@ -88,8 +88,6 @@ namespace RebootKit.Engine {
|
||||
|
||||
di.Install(_diContext);
|
||||
}
|
||||
|
||||
await UniTask.Yield();
|
||||
}
|
||||
|
||||
//
|
||||
|
||||
@@ -1,16 +1,16 @@
|
||||
using UnityEngine;
|
||||
|
||||
namespace RebootKit.Engine.Services.Console {
|
||||
[CreateAssetMenu(fileName = RConsts.AssetMenu + "cvar")]
|
||||
[CreateAssetMenu(menuName = RConsts.AssetMenu + "cvar", fileName = "cvar")]
|
||||
public class CVarAsset : ScriptableObject {
|
||||
[SerializeField]
|
||||
private CVar _cvar;
|
||||
|
||||
public CVar Create(string name = null) {
|
||||
CVar cvar = new CVar(_cvar);
|
||||
public CVar Create(string cvarName = null) {
|
||||
CVar cvar = new(_cvar);
|
||||
|
||||
if (name != null) {
|
||||
cvar.Name = name;
|
||||
if (cvarName != null) {
|
||||
cvar.Name = cvarName;
|
||||
}
|
||||
|
||||
return cvar;
|
||||
|
||||
@@ -46,7 +46,7 @@ namespace RebootKit.Engine.Services.Console {
|
||||
_config = config;
|
||||
}
|
||||
|
||||
public async UniTask OnInit(CancellationToken cancellationToken) {
|
||||
public async UniTask OnWakeUp(CancellationToken cancellationToken) {
|
||||
_logger.Info("Waking up");
|
||||
|
||||
_ui = UnityEngine.Object.Instantiate(_config.ConsoleUIPrefab);
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
using Cysharp.Threading.Tasks;
|
||||
using RebootKit.Engine.Foundation;
|
||||
using RebootKit.Engine.Services.Console;
|
||||
using UnityEngine.Assertions;
|
||||
|
||||
namespace RebootKit.Engine.Services.Game {
|
||||
public class GameService : IService {
|
||||
@@ -11,7 +12,7 @@ namespace RebootKit.Engine.Services.Game {
|
||||
private GameMode _gameMode;
|
||||
private bool _running;
|
||||
|
||||
public async UniTask OnInit(CancellationToken cancellationToken) {
|
||||
public async UniTask OnWakeUp(CancellationToken cancellationToken) {
|
||||
await UniTask.Yield(cancellationToken);
|
||||
}
|
||||
|
||||
@@ -21,6 +22,8 @@ namespace RebootKit.Engine.Services.Game {
|
||||
}
|
||||
|
||||
public async UniTask Start(GameModeAsset asset, CancellationToken cancellationToken) {
|
||||
Assert.IsNotNull(asset);
|
||||
|
||||
_gameMode = asset.Create();
|
||||
await _gameMode.Start(cancellationToken);
|
||||
|
||||
|
||||
@@ -21,10 +21,6 @@ namespace RebootKit.Engine.Services.Input {
|
||||
public void Dispose() {
|
||||
}
|
||||
|
||||
public async UniTask OnInit(CancellationToken cancellationToken) {
|
||||
await UniTask.Yield(cancellationToken);
|
||||
}
|
||||
|
||||
public void EnableControls() {
|
||||
_config.InputAsset.Enable();
|
||||
}
|
||||
|
||||
@@ -13,10 +13,6 @@ namespace RebootKit.Engine.Services.Simulation {
|
||||
private WorldConfig _config;
|
||||
private List<Actor> _actors = new();
|
||||
|
||||
public async UniTask OnInit(CancellationToken cancellationToken) {
|
||||
await UniTask.Yield(cancellationToken);
|
||||
}
|
||||
|
||||
public void Dispose() {
|
||||
KillAllActors();
|
||||
}
|
||||
|
||||
@@ -4,7 +4,7 @@ using RebootKit.Engine.Foundation;
|
||||
|
||||
namespace RebootKit.Engine.Services {
|
||||
public class UpdateLoopService : IService {
|
||||
public async UniTask OnInit(CancellationToken cancellationToken) {
|
||||
public async UniTask OnWakeUp(CancellationToken cancellationToken) {
|
||||
await UniTask.Yield(cancellationToken);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,6 +1,4 @@
|
||||
using NUnit.Framework;
|
||||
using NUnit.Framework.Interfaces;
|
||||
using NUnit.Framework.Internal;
|
||||
using RebootKit.Engine.Foundation;
|
||||
|
||||
namespace Tests.Runtime.Engine {
|
||||
|
||||
@@ -10,6 +10,6 @@
|
||||
"com.unity.render-pipelines.universal": "17.0.4",
|
||||
"com.unity.cinemachine": "2.10.3",
|
||||
"com.unity.collections": "2.5.3",
|
||||
"com.cysharp.unitask": "https://github.com/Cysharp/UniTask.git?path=src/UniTask/Assets/Plugins/UniTask"
|
||||
"com.cysharp.unitask": "2.5.10"
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user