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_Script: {fileID: 19101, guid: 0000000000000000e000000000000000, type: 0}
|
||||||
m_Name: Panel Settings
|
m_Name: Panel Settings
|
||||||
m_EditorClassIdentifier:
|
m_EditorClassIdentifier:
|
||||||
themeUss: {fileID: -4733365628477956816, guid: 5dd55e8f9f3419144b6d6fc3fcc478d0,
|
themeUss: {fileID: -4733365628477956816, guid: 5dd55e8f9f3419144b6d6fc3fcc478d0, type: 3}
|
||||||
type: 3}
|
|
||||||
m_DisableNoThemeWarning: 0
|
m_DisableNoThemeWarning: 0
|
||||||
m_TargetTexture: {fileID: 0}
|
m_TargetTexture: {fileID: 0}
|
||||||
m_RenderMode: 0
|
m_RenderMode: 0
|
||||||
|
|||||||
@@ -1,2 +1,16 @@
|
|||||||
fileFormatVersion: 2
|
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);
|
Type type = typeof(T);
|
||||||
|
|
||||||
foreach (FieldInfo field in type.GetFields(k_fieldsBindingFlags)) {
|
foreach (FieldInfo field in type.GetFields(k_fieldsBindingFlags)) {
|
||||||
if (!InjectField(field, target)) {
|
InjectField(field, target);
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach (MethodInfo method in type.GetMethods(k_methodsBindingFlags)) {
|
foreach (MethodInfo method in type.GetMethods(k_methodsBindingFlags)) {
|
||||||
|
|||||||
@@ -1,15 +1,11 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Threading;
|
|
||||||
using Cysharp.Threading.Tasks;
|
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
|
|
||||||
namespace RebootKit.Engine.Foundation {
|
namespace RebootKit.Engine.Foundation {
|
||||||
public interface IService : IDisposable {
|
public interface IService : IDisposable {
|
||||||
UniTask OnInit(CancellationToken cancellationToken);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public abstract class ServiceMonoBehaviour : MonoBehaviour, IService {
|
public abstract class ServiceMonoBehaviour : MonoBehaviour, IService {
|
||||||
public abstract UniTask OnInit(CancellationToken cancellationToken);
|
|
||||||
public abstract void Dispose();
|
public abstract void Dispose();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,4 @@
|
|||||||
using System.Threading;
|
using RebootKit.Engine.Foundation;
|
||||||
using Cysharp.Threading.Tasks;
|
|
||||||
using RebootKit.Engine.Foundation;
|
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
|
|
||||||
namespace RebootKit.Engine.Graphics {
|
namespace RebootKit.Engine.Graphics {
|
||||||
@@ -8,10 +6,6 @@ namespace RebootKit.Engine.Graphics {
|
|||||||
[field: SerializeField]
|
[field: SerializeField]
|
||||||
public Camera Camera { get; private set; }
|
public Camera Camera { get; private set; }
|
||||||
|
|
||||||
public override async UniTask OnInit(CancellationToken cancellationToken) {
|
|
||||||
await UniTask.Yield(cancellationToken);
|
|
||||||
}
|
|
||||||
|
|
||||||
public override void Dispose() {
|
public override void Dispose() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -46,8 +46,10 @@ namespace RebootKit.Engine {
|
|||||||
_diContext = new DIContext();
|
_diContext = new DIContext();
|
||||||
_diContext.AddInjector(new CVarFieldInjector());
|
_diContext.AddInjector(new CVarFieldInjector());
|
||||||
|
|
||||||
await CreateCoreServices(cancellationToken);
|
CreateCoreServices();
|
||||||
await RegisterServicesFromMainSceneAsync(cancellationToken);
|
InstallMainScene();
|
||||||
|
|
||||||
|
await UniTask.Yield(cancellationToken);
|
||||||
}
|
}
|
||||||
|
|
||||||
public async UniTask Run(CancellationToken cancellationToken) {
|
public async UniTask Run(CancellationToken cancellationToken) {
|
||||||
@@ -55,25 +57,23 @@ namespace RebootKit.Engine {
|
|||||||
await _gameService.Start(_engineConfigAsset.StartingGameMode, cancellationToken);
|
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();
|
TService service = asset.Create();
|
||||||
_diContext.Bind<TService>(service);
|
_diContext.Bind(service);
|
||||||
_diContext.Inject(service);
|
_diContext.Inject(service);
|
||||||
|
|
||||||
await service.OnInit(cancellationToken);
|
|
||||||
return service;
|
return service;
|
||||||
}
|
}
|
||||||
|
|
||||||
private async UniTask CreateCoreServices(CancellationToken cancellationToken) {
|
private void CreateCoreServices() {
|
||||||
Logger.Debug("Registering core services");
|
Logger.Debug("Registering core services");
|
||||||
|
|
||||||
_consoleService = await CreateServiceAsync(_engineConfigAsset.ConsoleService, cancellationToken);
|
_consoleService = CreateService(_engineConfigAsset.ConsoleService);
|
||||||
_inputService = await CreateServiceAsync(_engineConfigAsset.InputService, cancellationToken);
|
_inputService = CreateService(_engineConfigAsset.InputService);
|
||||||
_worldService = await CreateServiceAsync(_engineConfigAsset.WorldService, cancellationToken);
|
_worldService = CreateService(_engineConfigAsset.WorldService);
|
||||||
_gameService = await CreateServiceAsync(_engineConfigAsset.GameService, cancellationToken);
|
_gameService = CreateService(_engineConfigAsset.GameService);
|
||||||
}
|
}
|
||||||
|
|
||||||
private async UniTask RegisterServicesFromMainSceneAsync(CancellationToken cancellationToken = default) {
|
private void InstallMainScene() {
|
||||||
GameObject[] gameObjects = SceneManager.GetSceneByBuildIndex(RConsts.MainSceneBuildIndex).GetRootGameObjects();
|
GameObject[] gameObjects = SceneManager.GetSceneByBuildIndex(RConsts.MainSceneBuildIndex).GetRootGameObjects();
|
||||||
if (gameObjects.Length == 0) {
|
if (gameObjects.Length == 0) {
|
||||||
return;
|
return;
|
||||||
@@ -88,8 +88,6 @@ namespace RebootKit.Engine {
|
|||||||
|
|
||||||
di.Install(_diContext);
|
di.Install(_diContext);
|
||||||
}
|
}
|
||||||
|
|
||||||
await UniTask.Yield();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
|
|||||||
@@ -1,16 +1,16 @@
|
|||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
|
|
||||||
namespace RebootKit.Engine.Services.Console {
|
namespace RebootKit.Engine.Services.Console {
|
||||||
[CreateAssetMenu(fileName = RConsts.AssetMenu + "cvar")]
|
[CreateAssetMenu(menuName = RConsts.AssetMenu + "cvar", fileName = "cvar")]
|
||||||
public class CVarAsset : ScriptableObject {
|
public class CVarAsset : ScriptableObject {
|
||||||
[SerializeField]
|
[SerializeField]
|
||||||
private CVar _cvar;
|
private CVar _cvar;
|
||||||
|
|
||||||
public CVar Create(string name = null) {
|
public CVar Create(string cvarName = null) {
|
||||||
CVar cvar = new CVar(_cvar);
|
CVar cvar = new(_cvar);
|
||||||
|
|
||||||
if (name != null) {
|
if (cvarName != null) {
|
||||||
cvar.Name = name;
|
cvar.Name = cvarName;
|
||||||
}
|
}
|
||||||
|
|
||||||
return cvar;
|
return cvar;
|
||||||
|
|||||||
@@ -46,7 +46,7 @@ namespace RebootKit.Engine.Services.Console {
|
|||||||
_config = config;
|
_config = config;
|
||||||
}
|
}
|
||||||
|
|
||||||
public async UniTask OnInit(CancellationToken cancellationToken) {
|
public async UniTask OnWakeUp(CancellationToken cancellationToken) {
|
||||||
_logger.Info("Waking up");
|
_logger.Info("Waking up");
|
||||||
|
|
||||||
_ui = UnityEngine.Object.Instantiate(_config.ConsoleUIPrefab);
|
_ui = UnityEngine.Object.Instantiate(_config.ConsoleUIPrefab);
|
||||||
|
|||||||
@@ -2,6 +2,7 @@
|
|||||||
using Cysharp.Threading.Tasks;
|
using Cysharp.Threading.Tasks;
|
||||||
using RebootKit.Engine.Foundation;
|
using RebootKit.Engine.Foundation;
|
||||||
using RebootKit.Engine.Services.Console;
|
using RebootKit.Engine.Services.Console;
|
||||||
|
using UnityEngine.Assertions;
|
||||||
|
|
||||||
namespace RebootKit.Engine.Services.Game {
|
namespace RebootKit.Engine.Services.Game {
|
||||||
public class GameService : IService {
|
public class GameService : IService {
|
||||||
@@ -11,7 +12,7 @@ namespace RebootKit.Engine.Services.Game {
|
|||||||
private GameMode _gameMode;
|
private GameMode _gameMode;
|
||||||
private bool _running;
|
private bool _running;
|
||||||
|
|
||||||
public async UniTask OnInit(CancellationToken cancellationToken) {
|
public async UniTask OnWakeUp(CancellationToken cancellationToken) {
|
||||||
await UniTask.Yield(cancellationToken);
|
await UniTask.Yield(cancellationToken);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -21,6 +22,8 @@ namespace RebootKit.Engine.Services.Game {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public async UniTask Start(GameModeAsset asset, CancellationToken cancellationToken) {
|
public async UniTask Start(GameModeAsset asset, CancellationToken cancellationToken) {
|
||||||
|
Assert.IsNotNull(asset);
|
||||||
|
|
||||||
_gameMode = asset.Create();
|
_gameMode = asset.Create();
|
||||||
await _gameMode.Start(cancellationToken);
|
await _gameMode.Start(cancellationToken);
|
||||||
|
|
||||||
|
|||||||
@@ -21,10 +21,6 @@ namespace RebootKit.Engine.Services.Input {
|
|||||||
public void Dispose() {
|
public void Dispose() {
|
||||||
}
|
}
|
||||||
|
|
||||||
public async UniTask OnInit(CancellationToken cancellationToken) {
|
|
||||||
await UniTask.Yield(cancellationToken);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void EnableControls() {
|
public void EnableControls() {
|
||||||
_config.InputAsset.Enable();
|
_config.InputAsset.Enable();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -13,10 +13,6 @@ namespace RebootKit.Engine.Services.Simulation {
|
|||||||
private WorldConfig _config;
|
private WorldConfig _config;
|
||||||
private List<Actor> _actors = new();
|
private List<Actor> _actors = new();
|
||||||
|
|
||||||
public async UniTask OnInit(CancellationToken cancellationToken) {
|
|
||||||
await UniTask.Yield(cancellationToken);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void Dispose() {
|
public void Dispose() {
|
||||||
KillAllActors();
|
KillAllActors();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ using RebootKit.Engine.Foundation;
|
|||||||
|
|
||||||
namespace RebootKit.Engine.Services {
|
namespace RebootKit.Engine.Services {
|
||||||
public class UpdateLoopService : IService {
|
public class UpdateLoopService : IService {
|
||||||
public async UniTask OnInit(CancellationToken cancellationToken) {
|
public async UniTask OnWakeUp(CancellationToken cancellationToken) {
|
||||||
await UniTask.Yield(cancellationToken);
|
await UniTask.Yield(cancellationToken);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,4 @@
|
|||||||
using NUnit.Framework;
|
using NUnit.Framework;
|
||||||
using NUnit.Framework.Interfaces;
|
|
||||||
using NUnit.Framework.Internal;
|
|
||||||
using RebootKit.Engine.Foundation;
|
using RebootKit.Engine.Foundation;
|
||||||
|
|
||||||
namespace Tests.Runtime.Engine {
|
namespace Tests.Runtime.Engine {
|
||||||
|
|||||||
@@ -10,6 +10,6 @@
|
|||||||
"com.unity.render-pipelines.universal": "17.0.4",
|
"com.unity.render-pipelines.universal": "17.0.4",
|
||||||
"com.unity.cinemachine": "2.10.3",
|
"com.unity.cinemachine": "2.10.3",
|
||||||
"com.unity.collections": "2.5.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