UILobbyComponent.cs 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  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(OnCreateRoom);
  16. joinRoom.GetComponent<Button>().onClick.Add(OnJoinRoom);
  17. }
  18. private static 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<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<G2C_LoginGate>(new C2G_LoginGate(r2CLogin.Key));
  27. Log.Debug($"{JsonHelper.ToJson(g2CLoginGate)}");
  28. Log.Info("登陆gate成功!");
  29. // 发送一个actor消息
  30. //gateSession.Send(new Actor_Test() { Info = "message client->gate->map->gate->client" });
  31. ActorRpc_TestResponse response = await gateSession.Call<ActorRpc_TestResponse>(new ActorRpc_TestRequest() { request = "request actor test rpc" });
  32. Log.Info($"recv response: {JsonHelper.ToJson(response)}");
  33. }
  34. catch (Exception e)
  35. {
  36. Log.Error(e.ToStr());
  37. }
  38. finally
  39. {
  40. session?.Dispose();
  41. }
  42. }
  43. private static void OnJoinRoom()
  44. {
  45. }
  46. }
  47. }