AppStart_Init.cs 3.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  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<SessionStreamDispatcher>();
  30. Game.Scene.AddComponent<CoroutineLockComponent>();
  31. // 发送普通actor消息
  32. Game.Scene.AddComponent<ActorMessageSenderComponent>();
  33. // 发送location actor消息
  34. Game.Scene.AddComponent<ActorLocationSenderComponent>();
  35. // 访问location server的组件
  36. Game.Scene.AddComponent<LocationProxyComponent>();
  37. Game.Scene.AddComponent<ActorMessageDispatcherComponent>();
  38. // 数值订阅组件
  39. Game.Scene.AddComponent<NumericWatcherComponent>();
  40. Game.Scene.AddComponent<NetThreadComponent>();
  41. switch (Game.Options.AppType)
  42. {
  43. case AppType.Server:
  44. {
  45. Game.Scene.AddComponent<NetInnerComponent, IPEndPoint, int>(processConfig.InnerIPPort, SessionStreamDispatcherType.SessionStreamDispatcherServerInner);
  46. var processScenes = StartSceneConfigCategory.Instance.GetByProcess(Game.Options.Process);
  47. foreach (StartSceneConfig startConfig in processScenes)
  48. {
  49. await SceneFactory.Create(Game.Scene, startConfig.Id, startConfig.InstanceId, startConfig.Zone, startConfig.Name,
  50. startConfig.Type, startConfig);
  51. }
  52. break;
  53. }
  54. case AppType.Watcher:
  55. {
  56. StartMachineConfig startMachineConfig = WatcherHelper.GetThisMachineConfig();
  57. WatcherComponent watcherComponent = Game.Scene.AddComponent<WatcherComponent>();
  58. watcherComponent.Start(Game.Options.CreateScenes);
  59. Game.Scene.AddComponent<NetInnerComponent, IPEndPoint, int>(NetworkHelper.ToIPEndPoint($"{startMachineConfig.InnerIP}:{startMachineConfig.WatcherPort}"), SessionStreamDispatcherType.SessionStreamDispatcherServerInner);
  60. break;
  61. }
  62. case AppType.GameTool:
  63. break;
  64. }
  65. if (Game.Options.Console == 1)
  66. {
  67. Game.Scene.AddComponent<ConsoleComponent>();
  68. }
  69. }
  70. }
  71. }