AppStart_Init.cs 2.6 KB

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