UILobbyComponent.cs 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. using System;
  2. using ETModel;
  3. using UnityEngine;
  4. using UnityEngine.UI;
  5. namespace ETHotfix
  6. {
  7. [ObjectSystem]
  8. public class UiLobbyComponentSystem : AwakeSystem<UILobbyComponent>
  9. {
  10. public override void Awake(UILobbyComponent self)
  11. {
  12. self.Awake();
  13. }
  14. }
  15. public class UILobbyComponent : Component
  16. {
  17. private GameObject enterMap;
  18. private Text text;
  19. public void Awake()
  20. {
  21. ReferenceCollector rc = this.GetParent<UI>().GameObject.GetComponent<ReferenceCollector>();
  22. enterMap = rc.Get<GameObject>("EnterMap");
  23. enterMap.GetComponent<Button>().onClick.Add(this.EnterMap);
  24. this.text = rc.Get<GameObject>("Text").GetComponent<Text>();
  25. }
  26. private void EnterMap()
  27. {
  28. EnterMapAsync().Coroutine();
  29. }
  30. private async ETVoid EnterMapAsync()
  31. {
  32. try
  33. {
  34. // 加载Unit资源
  35. ResourcesComponent resourcesComponent = ETModel.Game.Scene.GetComponent<ResourcesComponent>();
  36. await resourcesComponent.LoadBundleAsync($"unit.unity3d");
  37. // 加载场景资源
  38. await ETModel.Game.Scene.GetComponent<ResourcesComponent>().LoadBundleAsync("map.unity3d");
  39. // 切换到map场景
  40. using (SceneChangeComponent sceneChangeComponent = ETModel.Game.Scene.AddComponent<SceneChangeComponent>())
  41. {
  42. await sceneChangeComponent.ChangeSceneAsync(SceneType.Map);
  43. }
  44. G2C_EnterMap g2CEnterMap = await ETModel.SessionComponent.Instance.Session.Call(new C2G_EnterMap()) as G2C_EnterMap;
  45. PlayerComponent.Instance.MyPlayer.UnitId = g2CEnterMap.UnitId;
  46. Game.Scene.AddComponent<OperaComponent>();
  47. Game.Scene.GetComponent<UIComponent>().Remove(UIType.UILobby);
  48. }
  49. catch (Exception e)
  50. {
  51. Log.Error(e);
  52. }
  53. }
  54. }
  55. }