LSSceneChangeHelper.cs 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. namespace ET.Client
  2. {
  3. public static partial class LSSceneChangeHelper
  4. {
  5. // 场景切换协程
  6. public static async ETTask SceneChangeTo(Scene clientScene, string sceneName, long sceneInstanceId)
  7. {
  8. clientScene.RemoveComponent<Room>();
  9. Room room = clientScene.AddComponentWithId<Room>(sceneInstanceId);
  10. room.Name = sceneName;
  11. // 等待表现层订阅的事件完成
  12. await EventSystem.Instance.PublishAsync(clientScene, new EventType.LSSceneChangeStart() {Room = room});
  13. clientScene.GetComponent<SessionComponent>().Session.Send(new C2Room_ChangeSceneFinish());
  14. // 等待Room2C_EnterMap消息
  15. WaitType.Wait_Room2C_Start waitRoom2CStart = await clientScene.GetComponent<ObjectWait>().Wait<WaitType.Wait_Room2C_Start>();
  16. room.LSWorld = new LSWorld(SceneType.LockStepClient);
  17. room.Init(waitRoom2CStart.Message.UnitInfo, waitRoom2CStart.Message.StartTime);
  18. room.AddComponent<LSClientUpdater>();
  19. // 这个事件中可以订阅取消loading
  20. EventSystem.Instance.Publish(clientScene, new EventType.LSSceneInitFinish());
  21. }
  22. // 场景切换协程
  23. public static async ETTask SceneChangeToReplay(Scene clientScene, Replay replay)
  24. {
  25. clientScene.RemoveComponent<Room>();
  26. Room room = clientScene.AddComponent<Room>();
  27. room.Name = "Map1";
  28. room.IsReplay = true;
  29. room.Replay = replay;
  30. room.LSWorld = new LSWorld(SceneType.LockStepClient);
  31. room.Init(replay.UnitInfos, TimeHelper.ServerFrameTime());
  32. // 等待表现层订阅的事件完成
  33. await EventSystem.Instance.PublishAsync(clientScene, new EventType.LSSceneChangeStart() {Room = room});
  34. room.AddComponent<LSReplayUpdater>();
  35. // 这个事件中可以订阅取消loading
  36. EventSystem.Instance.Publish(clientScene, new EventType.LSSceneInitFinish());
  37. }
  38. // 场景切换协程
  39. public static async ETTask SceneChangeToReconnect(Scene clientScene, G2C_Reconnect message)
  40. {
  41. clientScene.RemoveComponent<Room>();
  42. Room room = clientScene.AddComponent<Room>();
  43. room.Name = "Map1";
  44. room.LSWorld = new LSWorld(SceneType.LockStepClient);
  45. room.Init(message.UnitInfos, message.StartTime, message.Frame);
  46. // 等待表现层订阅的事件完成
  47. await EventSystem.Instance.PublishAsync(clientScene, new EventType.LSSceneChangeStart() {Room = room});
  48. room.AddComponent<LSClientUpdater>();
  49. // 这个事件中可以订阅取消loading
  50. EventSystem.Instance.Publish(clientScene, new EventType.LSSceneInitFinish());
  51. }
  52. }
  53. }