| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778 |
- using System;
- using System.Net;
- using ETModel;
- using UnityEngine;
- using UnityEngine.UI;
- namespace ETHotfix
- {
- [ObjectSystem]
- public class UiLoginComponentSystem : AwakeSystem<UILoginComponent>
- {
- public override void Awake(UILoginComponent self)
- {
- self.Awake();
- }
- }
-
- public class UILoginComponent: Component
- {
- private GameObject account;
- private GameObject loginBtn;
- public void Awake()
- {
- ReferenceCollector rc = this.GetParent<UI>().GameObject.GetComponent<ReferenceCollector>();
- loginBtn = rc.Get<GameObject>("LoginBtn");
- loginBtn.GetComponent<Button>().onClick.Add(OnLogin);
- this.account = rc.Get<GameObject>("Account");
- }
- public void OnLogin()
- {
- OnLoginAsync().Coroutine();
- }
- public async ETVoid OnLoginAsync()
- {
- try
- {
- string text = this.account.GetComponent<InputField>().text;
- // 创建一个ETModel层的Session
- ETModel.Session session = ETModel.Game.Scene.GetComponent<NetOuterComponent>().Create(GlobalConfigComponent.Instance.GlobalProto.Address);
-
- // 创建一个ETHotfix层的Session, ETHotfix的Session会通过ETModel层的Session发送消息
- Session realmSession = ComponentFactory.Create<Session, ETModel.Session>(session);
- R2C_Login r2CLogin = (R2C_Login) await realmSession.Call(new C2R_Login() { Account = text, Password = "111111" });
- realmSession.Dispose();
- // 创建一个ETModel层的Session,并且保存到ETModel.SessionComponent中
- ETModel.Session gateSession = ETModel.Game.Scene.GetComponent<NetOuterComponent>().Create(r2CLogin.Address);
- ETModel.Game.Scene.AddComponent<ETModel.SessionComponent>().Session = gateSession;
-
- // 创建一个ETHotfix层的Session, 并且保存到ETHotfix.SessionComponent中
- Game.Scene.AddComponent<SessionComponent>().Session = ComponentFactory.Create<Session, ETModel.Session>(gateSession);
-
- G2C_LoginGate g2CLoginGate = (G2C_LoginGate)await SessionComponent.Instance.Session.Call(new C2G_LoginGate() { Key = r2CLogin.Key });
- Log.Info("登陆gate成功!");
- // 创建Player
- Player player = ETModel.ComponentFactory.CreateWithId<Player>(g2CLoginGate.PlayerId);
- PlayerComponent playerComponent = ETModel.Game.Scene.GetComponent<PlayerComponent>();
- playerComponent.MyPlayer = player;
- Game.Scene.GetComponent<UIComponent>().Create(UIType.UILobby);
- Game.Scene.GetComponent<UIComponent>().Remove(UIType.UILogin);
- // 测试消息有成员是class类型
- G2C_PlayerInfo g2CPlayerInfo = (G2C_PlayerInfo) await SessionComponent.Instance.Session.Call(new C2G_PlayerInfo());
- }
- catch (Exception e)
- {
- Log.Error(e);
- }
- }
- }
- }
|