UILobbyComponent.cs 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. using System;
  2. using Model;
  3. using UnityEngine;
  4. using UnityEngine.UI;
  5. namespace Hotfix
  6. {
  7. [ObjectEvent(EntityEventId.UILobbyComponent)]
  8. public class UILobbyComponent: Component, IAwake
  9. {
  10. public void Awake()
  11. {
  12. ReferenceCollector rc = this.GetOwner<UI>().GameObject.GetComponent<ReferenceCollector>();
  13. GameObject createRoom = rc.Get<GameObject>("CreateRoom");
  14. GameObject joinRoom = rc.Get<GameObject>("JoinRoom");
  15. createRoom.GetComponent<Button>().onClick.Add(() => this.OnCreateRoom());
  16. joinRoom.GetComponent<Button>().onClick.Add(() => this.OnJoinRoom());
  17. }
  18. private async void OnCreateRoom()
  19. {
  20. Session session = null;
  21. try
  22. {
  23. session = Hotfix.Scene.ModelScene.GetComponent<NetOuterComponent>().Create("127.0.0.1:10001");
  24. R2C_Login r2CLogin = await session.Call<C2R_Login, R2C_Login>(new C2R_Login() { Account = "abcdef", Password = "111111" });
  25. Session gateSession = Hotfix.Scene.ModelScene.GetComponent<NetOuterComponent>().Create(r2CLogin.Address);
  26. G2C_LoginGate g2CLoginGate = await gateSession.Call<C2G_LoginGate, G2C_LoginGate>(new C2G_LoginGate(r2CLogin.Key));
  27. Log.Info("登陆gate成功!");
  28. }
  29. catch (Exception e)
  30. {
  31. Log.Error(e.ToString());
  32. }
  33. finally
  34. {
  35. session?.Dispose();
  36. }
  37. }
  38. private void OnJoinRoom()
  39. {
  40. }
  41. }
  42. }