Entrance.cs 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. using System;
  2. using UnityEngine;
  3. namespace XGame.Framework
  4. {
  5. /// <summary>
  6. /// 入口
  7. /// </summary>
  8. internal static class Entrance
  9. {
  10. /// <summary>
  11. /// 程序入口
  12. /// </summary>
  13. [RuntimeInitializeOnLoadMethod(RuntimeInitializeLoadType.AfterSceneLoad)]
  14. internal static void Access()
  15. {
  16. Profiler.BeginSample(typeof(Entrance), "Log.Initialize");
  17. Log.Initialize();
  18. Profiler.EndSample();
  19. #if UNITY_EDITOR
  20. Profiler.BeginSample(typeof(Entrance), "IsInvalid");
  21. var errorCode = IsInvalid();
  22. if (errorCode != 0)
  23. {
  24. return;
  25. }
  26. Profiler.EndSample();
  27. #endif
  28. Profiler.BeginSample(typeof(Entrance), "AppManager.Initialize");
  29. AppManager.Initialize();
  30. Profiler.EndSample();
  31. }
  32. #if UNITY_EDITOR
  33. private static int IsInvalid()
  34. {
  35. var config = XGameConfig.Load();
  36. if (config == null)
  37. {
  38. Log.Error($"Entrance error: 找不到 XGameConfig.asset.");
  39. return -1;
  40. }
  41. var launchSceneName = config.launchSceneName;
  42. var gameLogicTypeName = config.gameLogicTypeName;
  43. XGameConfig.Unload(config);
  44. if (string.IsNullOrEmpty(launchSceneName))
  45. {
  46. Log.Error($"Entrance error: XGameConfig.asset 没有设置启动场景.");
  47. return -2;
  48. }
  49. if (!UnityEngine.SceneManagement.SceneManager.GetActiveScene().name.Equals(launchSceneName))
  50. {
  51. Log.Error($"Entrance error: XGameConfig.asset 启动场景没有激活.");
  52. return -3;
  53. }
  54. if (string.IsNullOrEmpty(gameLogicTypeName))
  55. {
  56. Log.Error($"Entrance error: XGameConfig.asset 没有设置启动脚本.");
  57. return -4;
  58. }
  59. if (Type.GetType(gameLogicTypeName) == null)
  60. {
  61. Log.Error($"Entrance error: XGameConfig.asset 找不到启动脚本. Type:{gameLogicTypeName}");
  62. return -5;
  63. }
  64. //var assembly = System.Reflection.Assembly.Load(config.launchAssemblyName);
  65. //assembly.GetType(gameLogicTypeName);
  66. return 0;
  67. }
  68. #endif
  69. }
  70. }