From 771e138f38f505673ab22b19aa028336f9e2da29 Mon Sep 17 00:00:00 2001 From: "DESKTOP-B25GA9E\\W35" <1733709035@qq.com> Date: Fri, 3 Mar 2023 17:25:10 +0800 Subject: [PATCH] =?UTF-8?q?=E6=A1=86=E6=9E=B6=E6=9B=B4=E6=96=B0=E7=94=A8?= =?UTF-8?q?=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../TCPClient/Script/TCPClientView.cs | 46 +++++++++---------- 1 file changed, 21 insertions(+), 25 deletions(-) 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);