GameInstaller.cs 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using Zenject;
  5. using Sirenix.OdinInspector;
  6. namespace KairoEngine.Core.ModuleSystem
  7. {
  8. [HideMonoScript, AddComponentMenu("KairoEngine/Game Installer"), RequireComponent(typeof(SceneContext))]
  9. public class GameInstaller : MonoInstaller
  10. {
  11. [InlineEditor(InlineEditorObjectFieldModes.Boxed)] public GameConfig gameConfig;
  12. public override void InstallBindings()
  13. {
  14. //Container.Bind<string>().FromInstance("Hello World!");
  15. //Container.Bind<GlobalManager>().AsSingle().NonLazy();
  16. //Container.Bind<ICursorRules>().To<SneakyCursorRules>().AsSingle();
  17. for (int i = 0; i < gameConfig.modules.Count; i++)
  18. {
  19. if(gameConfig.modules[i].enableModule) gameConfig.modules[i].Load(this.transform);
  20. }
  21. }
  22. public override void Start()
  23. {
  24. for (int i = 0; i < gameConfig.modules.Count; i++)
  25. {
  26. if(gameConfig.modules[i].enableModule) gameConfig.modules[i].Start();
  27. }
  28. for (int i = 0; i < gameConfig.configOptions.list.Count; i++)
  29. {
  30. gameConfig.configOptions.list[i].LoadValue(gameConfig.configOptions.debug);
  31. }
  32. }
  33. void OnDestroy()
  34. {
  35. int c = 0;
  36. for (int i = 0; i < gameConfig.modules.Count; i++)
  37. {
  38. if(gameConfig.modules[i].enableModule)
  39. {
  40. gameConfig.modules[i].Destroy();
  41. c += 1;
  42. }
  43. }
  44. Debug.Log($"Unloaded {c} module{(c > 1 || c == 0 ? 's' : ' ')}");
  45. }
  46. }
  47. }