UILobbyComponent.cs 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  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. try
  20. {
  21. using (Session session = Game.Scene.GetComponent<NetOuterComponent>().Create("127.0.0.1:10001"))
  22. {
  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. }
  29. catch (Exception e)
  30. {
  31. Log.Error(e.ToString());
  32. }
  33. }
  34. private void OnJoinRoom()
  35. {
  36. }
  37. }
  38. }