UILobbyComponentE.cs 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. using System;
  2. using Base;
  3. using UnityEngine;
  4. using UnityEngine.UI;
  5. namespace Model
  6. {
  7. [EntityEvent(EntityEventId.UILobbyComponent)]
  8. public static class UILobbyComponentE
  9. {
  10. public static void Awake(this UILobbyComponent self)
  11. {
  12. ReferenceCollector rc = self.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(()=> self.OnCreateRoom());
  16. joinRoom.GetComponent<Button>().onClick.Add(()=>self.OnJoinRoom());
  17. }
  18. private static async void OnCreateRoom(this UILobbyComponent self)
  19. {
  20. try
  21. {
  22. using (Session session = Game.Scene.GetComponent<NetOuterComponent>().Create("127.0.0.1:10001"))
  23. {
  24. R2C_Login r2CLogin = await session.Call<C2R_Login, R2C_Login>(new C2R_Login() {Account = "abcdef", Password = "111111" });
  25. Session gateSession = Game.Scene.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. }
  30. catch (Exception e)
  31. {
  32. Log.Error(e.ToString());
  33. }
  34. }
  35. private static void OnJoinRoom(this UILobbyComponent self)
  36. {
  37. }
  38. }
  39. }