diff --git a/Assets/MsgTransmitTools/ExtendLinkModel/TCPClient/Script/TCPClientView.cs b/Assets/MsgTransmitTools/ExtendLinkModel/TCPClient/Script/TCPClientView.cs index 31a3077..5d136de 100644 --- a/Assets/MsgTransmitTools/ExtendLinkModel/TCPClient/Script/TCPClientView.cs +++ b/Assets/MsgTransmitTools/ExtendLinkModel/TCPClient/Script/TCPClientView.cs @@ -43,34 +43,30 @@ namespace JXSoft { tcpPort = 20000; deviceId = 1; - this.RegisterEvent(e => { - if (e.linkState == (int)TCPLinkState.Linking) - { - Debug.Log("TCP开始链接"); - this.GetModel().linkServer(); - } - if (e.linkState == (int)TCPLinkState.LinkSucess) - { - Debug.Log("TCP链接成功"); - this.GetModel().onReceive(); - this.GetModel().sendRequest(new LinkTCPRequest(deviceId)); - onTCPLinkSuccess.Invoke(); - } - if (e.linkState == (int)TCPLinkState.LinkFaild) - { - Debug.Log("TCP连接失败,请联系设备服务管理员"); - onTCPLinkFaild.Invoke(); - } + this.RegisterLinkStateEvent((int)TCPLinkState.Linking, () => + { + Debug.Log("TCP开始链接"); + this.GetModel().linkServer(); + }); + this.RegisterLinkStateEvent((int)TCPLinkState.LinkSucess, () => + { + Debug.Log("TCP链接成功"); + this.GetModel().onReceive(); + this.GetModel().sendRequest(new LinkTCPRequest(deviceId)); + onTCPLinkSuccess.Invoke(); }); + this.RegisterLinkStateEvent((int)TCPLinkState.LinkFaild, () => + { + Debug.Log("TCP连接失败,请联系设备服务管理员"); + onTCPLinkFaild.Invoke(); + }); + - this.RegisterEvent(e => + this.RegisterMessageEvent(e => { - if (e.res.GetType() == typeof(LinkSuccessResponse)) - { - Debug.Log("Link Server success"); - this.GetModel().offReceive(); - onServerConnected.Invoke(); - } + Debug.Log("Link Server success"); + this.GetModel().offReceive(); + onServerConnected.Invoke(); }); this.GetModel().setLinkState((int)TCPLinkState.NoIp);