123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051 |
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- using Zenject;
- using Sirenix.OdinInspector;
- namespace KairoEngine.Core.ModuleSystem
- {
- [HideMonoScript, AddComponentMenu("KairoEngine/Game Installer"), RequireComponent(typeof(SceneContext))]
- public class GameInstaller : MonoInstaller
- {
- [InlineEditor(InlineEditorObjectFieldModes.Boxed)] public GameConfig gameConfig;
- public override void InstallBindings()
- {
- //Container.Bind<string>().FromInstance("Hello World!");
- //Container.Bind<GlobalManager>().AsSingle().NonLazy();
- //Container.Bind<ICursorRules>().To<SneakyCursorRules>().AsSingle();
- for (int i = 0; i < gameConfig.modules.Count; i++)
- {
- if(gameConfig.modules[i].enableModule) gameConfig.modules[i].Load(this.transform);
- }
- }
- public override void Start()
- {
- for (int i = 0; i < gameConfig.modules.Count; i++)
- {
- if(gameConfig.modules[i].enableModule) gameConfig.modules[i].Start();
- }
- for (int i = 0; i < gameConfig.configOptions.list.Count; i++)
- {
- gameConfig.configOptions.list[i].LoadValue(gameConfig.configOptions.debug);
- }
- }
- void OnDestroy()
- {
- int c = 0;
- for (int i = 0; i < gameConfig.modules.Count; i++)
- {
- if(gameConfig.modules[i].enableModule)
- {
- gameConfig.modules[i].Destroy();
- c += 1;
- }
- }
- Debug.Log($"Unloaded {c} module{(c > 1 || c == 0 ? 's' : ' ')}");
- }
- }
- }
|