AppStart_Init.cs 3.0 KB

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