GameInstaller.cs 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  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. 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].module.Load(this.transform);
  20. }
  21. }
  22. public override void Start()
  23. {
  24. for (int i = 0; i < gameConfig.configOptions.list.Count; i++)
  25. {
  26. gameConfig.configOptions.list[i].LoadValue(gameConfig.configOptions.debug);
  27. }
  28. }
  29. void OnDestroy()
  30. {
  31. int c = 0;
  32. for (int i = 0; i < gameConfig.modules.Count; i++)
  33. {
  34. if(gameConfig.modules[i].enableModule)
  35. {
  36. gameConfig.modules[i].module.Destroy();
  37. c += 1;
  38. }
  39. }
  40. Debug.Log($"Unloaded {c} module{(c > 1 || c == 0 ? 's' : ' ')}");
  41. }
  42. }
  43. }