一、ET框架的生命周期
在ET框架中拥有一套从出生到死亡的生命周期,在Unity中类是于Unity中的生命周期。我们在生命生命周期时候我们需要给他挂载[ObjectSystem],并且让他继承对应的方法。ET框架采用的热更新使用的是ILRiTime使用的是c#进行热更。
[ObjectSystem]
public class LandLoginComponentAwakeSystem : AwakeSystem<LandLoginComponent>
{
public override void Awake(LandLoginComponent self)
{
self.Awake();
}
}
public class LandLoginComponent : Component
{
//提示文本
public Text prompt;
public InputField account;
public InputField password;
//是否正在登陆(避免登陆请求还没相应时连续点击登陆)
public bool isLogining;
//是否正在注册中(避免登陆请求还没相应时连续点击注册)
public bool isRegistering;
public void Awake()
{
ReferenceCollector rc = this.GetParent<UI>().GameObject.GetComponent<ReferenceCollector>();
//初始化数据
account = rc.Get<GameObject>("Account").GetComponent<InputField>();
password = rc.Get<GameObject>("Password").GetComponent<InputField>();
prompt = rc.Get<GameObject>("Prompt").GetComponent<Text>();
this.isLogining = false;
this.isLogining = false;
//添加点击事件
rc.Get<GameObject>("LoginButton").GetComponent<Button>().onClick.Add(() => LoginBtnOnclick());
rc.Get<GameObject>("RegisterButton").GetComponent<Button>().onClick.Add(() => LoginBtnOnclick());
}
#region 按钮点击事件
public void LoginBtnOnclick()
{
if(this .isLogining||this.IsDisposed)
{
return;
}
this.isLogining = true;
LandHelper.Login(this.account.text , this.password.text ).Coroutine();
}
public void RegisterBtnOnClick()
{
if (this.isRegistering || this.IsDisposed)
{
return;
}
this.isRegistering = true;
LandHelper.Register(this.account.text , this.password.text ).Coroutine();
}
#endregion
}
}