MapHelper.cs 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. using System;
  2. using ETModel;
  3. namespace ETHotfix
  4. {
  5. public static class MapHelper
  6. {
  7. public static async ETVoid EnterMapAsync()
  8. {
  9. try
  10. {
  11. // 加载Unit资源
  12. ResourcesComponent resourcesComponent = ETModel.Game.Scene.GetComponent<ResourcesComponent>();
  13. await resourcesComponent.LoadBundleAsync($"unit.unity3d");
  14. // 加载场景资源
  15. await ETModel.Game.Scene.GetComponent<ResourcesComponent>().LoadBundleAsync("map.unity3d");
  16. // 切换到map场景
  17. using (SceneChangeComponent sceneChangeComponent = ETModel.Game.Scene.AddComponent<SceneChangeComponent>())
  18. {
  19. await sceneChangeComponent.ChangeSceneAsync(SceneType.Map);
  20. }
  21. G2C_EnterMap g2CEnterMap = await ETModel.SessionComponent.Instance.Session.Call(new C2G_EnterMap()) as G2C_EnterMap;
  22. PlayerComponent.Instance.MyPlayer.UnitId = g2CEnterMap.UnitId;
  23. Game.Scene.AddComponent<OperaComponent>();
  24. Game.EventSystem.Run(EventIdType.EnterMapFinish);
  25. }
  26. catch (Exception e)
  27. {
  28. Log.Error(e);
  29. }
  30. }
  31. }
  32. }