AppStart_Init.cs 3.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. using System.Net;
  2. namespace ET
  3. {
  4. public class AppStart_Init: AEvent<EventType.AppStart>
  5. {
  6. protected override async ETTask Run(EventType.AppStart args)
  7. {
  8. switch (Game.Options.AppType)
  9. {
  10. case AppType.ExcelExporter:
  11. {
  12. Game.Options.Console = 1;
  13. ExcelExporter.Export();
  14. return;
  15. }
  16. case AppType.Proto2CS:
  17. {
  18. Game.Options.Console = 1;
  19. Proto2CS.Export();
  20. return;
  21. }
  22. }
  23. Game.Scene.AddComponent<ConfigComponent>();
  24. await ConfigComponent.Instance.LoadAsync();
  25. StartProcessConfig processConfig = StartProcessConfigCategory.Instance.Get(Game.Options.Process);
  26. Game.Scene.AddComponent<TimerComponent>();
  27. Game.Scene.AddComponent<OpcodeTypeComponent>();
  28. Game.Scene.AddComponent<MessageDispatcherComponent>();
  29. Game.Scene.AddComponent<CoroutineLockComponent>();
  30. // 发送普通actor消息
  31. Game.Scene.AddComponent<ActorMessageSenderComponent>();
  32. // 发送location actor消息
  33. Game.Scene.AddComponent<ActorLocationSenderComponent>();
  34. // 访问location server的组件
  35. Game.Scene.AddComponent<LocationProxyComponent>();
  36. Game.Scene.AddComponent<ActorMessageDispatcherComponent>();
  37. // 数值订阅组件
  38. Game.Scene.AddComponent<NumericWatcherComponent>();
  39. Game.Scene.AddComponent<NetThreadComponent>();
  40. switch (Game.Options.AppType)
  41. {
  42. case AppType.Server:
  43. {
  44. Game.Scene.AddComponent<NetInnerComponent, IPEndPoint>(processConfig.InnerIPPort);
  45. var processScenes = StartSceneConfigCategory.Instance.GetByProcess(Game.Options.Process);
  46. foreach (StartSceneConfig startConfig in processScenes)
  47. {
  48. await SceneFactory.Create(Game.Scene, startConfig.Id, startConfig.InstanceId, startConfig.Zone, startConfig.Name,
  49. startConfig.Type, startConfig);
  50. }
  51. break;
  52. }
  53. case AppType.Watcher:
  54. {
  55. StartMachineConfig startMachineConfig = WatcherHelper.GetThisMachineConfig();
  56. WatcherComponent watcherComponent = Game.Scene.AddComponent<WatcherComponent>();
  57. watcherComponent.Start(Game.Options.CreateScenes);
  58. Game.Scene.AddComponent<NetInnerComponent, IPEndPoint>(NetworkHelper.ToIPEndPoint($"{startMachineConfig.InnerIP}:{startMachineConfig.WatcherPort}"));
  59. break;
  60. }
  61. case AppType.GameTool:
  62. break;
  63. }
  64. if (Game.Options.Console == 1)
  65. {
  66. Game.Scene.AddComponent<ConsoleComponent>();
  67. }
  68. }
  69. }
  70. }