AutoInitialize.cs 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. using SRDebugger.Services;
  2. using SRF.Service;
  3. namespace SRDebugger
  4. {
  5. using UnityEngine;
  6. public static class AutoInitialize
  7. {
  8. #if UNITY_2018
  9. private const RuntimeInitializeLoadType InitializeLoadType = RuntimeInitializeLoadType.BeforeSceneLoad;
  10. #else
  11. private const RuntimeInitializeLoadType InitializeLoadType = RuntimeInitializeLoadType.SubsystemRegistration;
  12. #endif
  13. /// <summary>
  14. /// Initialize the console service before the scene has loaded to catch more of the initialization log.
  15. /// </summary>
  16. [RuntimeInitializeOnLoadMethod(InitializeLoadType)]
  17. public static void OnLoadBeforeScene()
  18. {
  19. // Populate service manager with types from SRDebugger assembly (asmdef)
  20. SRServiceManager.RegisterAssembly<IDebugService>();
  21. if (Settings.Instance.IsEnabled)
  22. {
  23. // Initialize console if it hasn't already initialized.
  24. SRServiceManager.GetService<IConsoleService>();
  25. }
  26. }
  27. /// <summary>
  28. /// Initialize SRDebugger after the scene has loaded.
  29. /// </summary>
  30. [RuntimeInitializeOnLoadMethod(RuntimeInitializeLoadType.AfterSceneLoad)]
  31. public static void OnLoad()
  32. {
  33. if (Settings.Instance.IsEnabled)
  34. {
  35. SRDebug.Init();
  36. }
  37. }
  38. }
  39. }