UILobbyComponent.cs 1.2 KB

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