From ef93cedfad6dcfe37d2ffd0fda5e92d02a04f45a Mon Sep 17 00:00:00 2001 From: "DESKTOP-B25GA9E\\W35" <1733709035@qq.com> Date: Mon, 30 Jan 2023 16:31:16 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=94=B9QFrame=E7=9A=84nameSpace?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../TCPClient/Script/Source/TCPEventModel.cs | 6 +- .../TCPClient/Script/Source/TCPUtility.cs | 4 +- .../TCPClient/Script/View/TCPClientView.cs | 183 ++++++------ .../TCPClient/Script/View/TCPPrinter.cs | 6 +- .../UDPClient/UDPClientView.cs | 172 +++++------ .../UDPClient/UDPEventModel.cs | 7 +- .../MsgTransmitTools/UDPClient/UDPPrinter.cs | 81 +++-- .../MsgTransmitTools/UDPClient/UDPUtility.cs | 2 +- Assets/MsgTransmitTools/src/DataEventModel.cs | 280 +++++++++--------- Assets/MsgTransmitTools/src/QFrameCopy.cs | 6 +- 10 files changed, 377 insertions(+), 370 deletions(-) diff --git a/Assets/MsgTransmitTools/TCPClient/Script/Source/TCPEventModel.cs b/Assets/MsgTransmitTools/TCPClient/Script/Source/TCPEventModel.cs index 5cb5327..4e84dd7 100644 --- a/Assets/MsgTransmitTools/TCPClient/Script/Source/TCPEventModel.cs +++ b/Assets/MsgTransmitTools/TCPClient/Script/Source/TCPEventModel.cs @@ -1,12 +1,12 @@ using System.Collections; using System.Collections.Generic; using UnityEngine; -using QFramework; +using QFrameworkCP; -namespace TCPClientTools +namespace JXSoft { //统筹管理TCP的命令池以及相关链接信息 - public class TCPEventModel : DataEventModel, ICanSendCommand,ICanRegisterEvent + public class TCPEventModel : DataEventModel { private TCPLinkState tcpState = TCPLinkState.NoIp; private string tcpAddress = ""; diff --git a/Assets/MsgTransmitTools/TCPClient/Script/Source/TCPUtility.cs b/Assets/MsgTransmitTools/TCPClient/Script/Source/TCPUtility.cs index 6244718..c2f6c11 100644 --- a/Assets/MsgTransmitTools/TCPClient/Script/Source/TCPUtility.cs +++ b/Assets/MsgTransmitTools/TCPClient/Script/Source/TCPUtility.cs @@ -1,4 +1,4 @@ -using QFramework; +using QFrameworkCP; using UnityEngine; using System; using System.Text; @@ -8,7 +8,7 @@ using System.Threading.Tasks; using System.Threading; using System.Net.NetworkInformation; -namespace TCPClientTools +namespace JXSoft { public class TCPUtility : IUtility { diff --git a/Assets/MsgTransmitTools/TCPClient/Script/View/TCPClientView.cs b/Assets/MsgTransmitTools/TCPClient/Script/View/TCPClientView.cs index df8e9f8..055ac48 100644 --- a/Assets/MsgTransmitTools/TCPClient/Script/View/TCPClientView.cs +++ b/Assets/MsgTransmitTools/TCPClient/Script/View/TCPClientView.cs @@ -2,111 +2,114 @@ using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.Events; -using QFramework; -using TCPClientTools; +using QFrameworkCP; +using JXSoft; using System; -public class TCPMangerArchitecture : Architecture -{ - protected override void Init() - { - this.RegisterUtility(new TCPUtility()); - this.RegisterModel(new TCPEventModel()); - } -} -public class TCPClientView : MonoBehaviour,IController,ICanSendEvent -{ - public UnityEvent onRecievedOpenDevice; - public UnityEvent onTCPLinkSuccess; - public UnityEvent onTCPLinkFaild; - public UnityEvent onServerConnected; - public UnityEvent onTCPReLink; - private string tcpAddress; - private int tcpPort; - private int deviceId; - // Start is called before the first frame update - void Awake() +namespace JXSoft { + public class TCPMangerArchitecture : Architecture { - initTCPService(); - DontDestroyOnLoad(this); + protected override void Init() + { + this.RegisterUtility(new TCPUtility()); + this.RegisterModel(new TCPEventModel()); + } } + public class TCPClientView : MonoBehaviour,IController + { + public UnityEvent onRecievedOpenDevice; + public UnityEvent onTCPLinkSuccess; + public UnityEvent onTCPLinkFaild; + public UnityEvent onServerConnected; + public UnityEvent onTCPReLink; - public void initTCPService() { - tcpAddress = "127.0.0.1"; - tcpPort = 20000; - deviceId = 1; + private string tcpAddress; + private int tcpPort; + private int deviceId; + // Start is called before the first frame update + void Awake() + { + initTCPService(); + DontDestroyOnLoad(this); + } - GetArchitecture().RegisterEvent(e => { - if (e.state == TCPLinkState.Linking) - { - Debug.Log("TCPʼ"); - this.GetModel().linkServer(); - } - if (e.state == TCPLinkState.LinkSucess) - { - Debug.Log("TCPӳɹ"); - this.GetModel().onReceive(); - this.GetModel().sendRequestCommand(new LinkTCPRequest(deviceId)); - onTCPLinkSuccess.Invoke(); - } - if (e.state == TCPLinkState.LinkFaild) - { - Debug.Log("TCPʧܣϵ豸Ա"); - onTCPLinkFaild.Invoke(); - } - }); + public void initTCPService() { + tcpAddress = "127.0.0.1"; + tcpPort = 20000; + deviceId = 1; - GetArchitecture().RegisterEvent(e => - { - if (e.res.GetType() == typeof(LinkSuccessResponse)) + GetArchitecture().RegisterEvent(e => { + if (e.state == TCPLinkState.Linking) + { + Debug.Log("TCPʼ"); + this.GetModel().linkServer(); + } + if (e.state == TCPLinkState.LinkSucess) + { + Debug.Log("TCPӳɹ"); + this.GetModel().onReceive(); + this.GetModel().sendRequestCommand(new LinkTCPRequest(deviceId)); + onTCPLinkSuccess.Invoke(); + } + if (e.state == TCPLinkState.LinkFaild) + { + Debug.Log("TCPʧܣϵ豸Ա"); + onTCPLinkFaild.Invoke(); + } + }); + + GetArchitecture().RegisterEvent(e => { - Debug.Log("Link Server success"); - this.GetModel().offReceive(); - onServerConnected.Invoke(); - } - }); + if (e.res.GetType() == typeof(LinkSuccessResponse)) + { + Debug.Log("Link Server success"); + this.GetModel().offReceive(); + onServerConnected.Invoke(); + } + }); - this.GetModel().setTCPState(TCPLinkState.NoIp); - this.GetModel().setIP(tcpAddress, tcpPort); - } + this.GetModel().setTCPState(TCPLinkState.NoIp); + this.GetModel().setIP(tcpAddress, tcpPort); + } - public void restartTCPService() { - onTCPReLink.Invoke(); - this.GetModel().closeServer(); - StartCoroutine(waitTwoSecond()); - } - public IEnumerator waitTwoSecond() { - yield return new WaitForSeconds(2.0f); - this.GetModel().setTCPState(TCPLinkState.Linking); + public void restartTCPService() { + onTCPReLink.Invoke(); + this.GetModel().closeServer(); + StartCoroutine(waitTwoSecond()); + } + public IEnumerator waitTwoSecond() { + yield return new WaitForSeconds(2.0f); + this.GetModel().setTCPState(TCPLinkState.Linking); + } + public IArchitecture GetArchitecture() + { + return TCPMangerArchitecture.Interface; + } } - public IArchitecture GetArchitecture() + public class LinkSuccessResponse : AbstractResponse { - return TCPMangerArchitecture.Interface; - } -} -public class LinkSuccessResponse : AbstractResponse -{ - public string code; - public string data; - public string msg; - public LinkSuccessResponse() { - this.code = ""; - this.data = ""; - this.msg = ""; + public string code; + public string data; + public string msg; + public LinkSuccessResponse() { + this.code = ""; + this.data = ""; + this.msg = ""; + } } -} -public class LinkTCPRequest :IRequest{ - public string id; - public int type; - public LinkTCPRequest(int id) { - this.id = id.ToString(); - this.type = 1; - } - public string toJson() - { - return JsonUtility.ToJson(this); + public class LinkTCPRequest :IRequest{ + public string id; + public int type; + public LinkTCPRequest(int id) { + this.id = id.ToString(); + this.type = 1; + } + public string toJson() + { + return JsonUtility.ToJson(this); + } } } diff --git a/Assets/MsgTransmitTools/TCPClient/Script/View/TCPPrinter.cs b/Assets/MsgTransmitTools/TCPClient/Script/View/TCPPrinter.cs index 31831cb..7a81128 100644 --- a/Assets/MsgTransmitTools/TCPClient/Script/View/TCPPrinter.cs +++ b/Assets/MsgTransmitTools/TCPClient/Script/View/TCPPrinter.cs @@ -3,12 +3,12 @@ using System.Collections.Generic; using UnityEngine; using UnityEngine.Events; using UnityEngine.UI; -using QFramework; +using QFrameworkCP; using System.Threading; -namespace TCPClientTools +namespace JXSoft { - public class TCPPrinter : MonoBehaviour,IController,ICanSendEvent + public class TCPPrinter : MonoBehaviour,IController { private TCPUtility tcpUtil; public Transform tcpMsgContent; diff --git a/Assets/MsgTransmitTools/UDPClient/UDPClientView.cs b/Assets/MsgTransmitTools/UDPClient/UDPClientView.cs index fdbb57a..3524716 100644 --- a/Assets/MsgTransmitTools/UDPClient/UDPClientView.cs +++ b/Assets/MsgTransmitTools/UDPClient/UDPClientView.cs @@ -2,105 +2,107 @@ using System.Collections.Generic; using UnityEngine; using UnityEngine.Events; -using QFramework; +using QFrameworkCP; using System; -public class UDPMangerArchitecture : Architecture -{ - protected override void Init() +namespace JXSoft { + public class UDPMangerArchitecture : Architecture { - this.RegisterUtility(new UDPUtility()); - this.RegisterModel(new UDPEventModel()); - } -} -public class UDPClientView : MonoBehaviour, IController, ICanSendEvent -{ - public UnityEvent onRecievedOpenDevice; - public UnityEvent onUDPLinkSuccess; - public UnityEvent onUDPLinkFaild; - public UnityEvent onServerConnected; - public UnityEvent onUDPReLink; - - private string UDPAddress; - private int UDPPort; - private int deviceId; - // Start is called before the first frame update - void Awake() - { - initUDPService(); - DontDestroyOnLoad(this); + protected override void Init() + { + this.RegisterUtility(new UDPUtility()); + this.RegisterModel(new UDPEventModel()); + } } - - public void initUDPService() + public class UDPClientView : MonoBehaviour, IController { - UDPAddress = "127.0.0.1"; - UDPPort = 20000; - deviceId = 1; + public UnityEvent onRecievedOpenDevice; + public UnityEvent onUDPLinkSuccess; + public UnityEvent onUDPLinkFaild; + public UnityEvent onServerConnected; + public UnityEvent onUDPReLink; - GetArchitecture().RegisterEvent(e => { - if (e.state == UDPLinkState.Linking) - { - Debug.Log("UDP开始链接"); - this.GetModel().linkServer(); - } - if (e.state == UDPLinkState.LinkSucess) - { - Debug.Log("UDP链接成功"); - this.GetModel().onReceive(); - this.GetModel().sendRequestCommand(new LinkUDPRequest(deviceId)); - onUDPLinkSuccess.Invoke(); - } - if (e.state == UDPLinkState.LinkFaild) - { - Debug.Log("UDP连接失败,请联系设备服务管理员"); - onUDPLinkFaild.Invoke(); - } - }); + private string UDPAddress; + private int UDPPort; + private int deviceId; + // Start is called before the first frame update + void Awake() + { + initUDPService(); + DontDestroyOnLoad(this); + } - GetArchitecture().RegisterEvent(e => + public void initUDPService() { - if (e.res.GetType() == typeof(LinkSuccessResponse)) + UDPAddress = "127.0.0.1"; + UDPPort = 20000; + deviceId = 1; + + GetArchitecture().RegisterEvent(e => { + if (e.state == UDPLinkState.Linking) + { + Debug.Log("UDP开始链接"); + this.GetModel().linkServer(); + } + if (e.state == UDPLinkState.LinkSucess) + { + Debug.Log("UDP链接成功"); + this.GetModel().onReceive(); + this.GetModel().sendRequestCommand(new LinkUDPRequest(deviceId)); + onUDPLinkSuccess.Invoke(); + } + if (e.state == UDPLinkState.LinkFaild) + { + Debug.Log("UDP连接失败,请联系设备服务管理员"); + onUDPLinkFaild.Invoke(); + } + }); + + GetArchitecture().RegisterEvent(e => { - Debug.Log("Link Server success"); - this.GetModel().offReceive(); - onServerConnected.Invoke(); - } - }); + if (e.res.GetType() == typeof(LinkSuccessResponse)) + { + Debug.Log("Link Server success"); + this.GetModel().offReceive(); + onServerConnected.Invoke(); + } + }); - this.GetModel().setUDPState(UDPLinkState.NoIp); - this.GetModel().setIP(UDPAddress, UDPPort); - } + this.GetModel().setUDPState(UDPLinkState.NoIp); + this.GetModel().setIP(UDPAddress, UDPPort); + } - public void restartUDPService() - { - onUDPReLink.Invoke(); - this.GetModel().closeServer(); - StartCoroutine(waitTwoSecond()); - } - public IEnumerator waitTwoSecond() - { - yield return new WaitForSeconds(2.0f); - this.GetModel().setUDPState(UDPLinkState.Linking); - } - public IArchitecture GetArchitecture() - { - return UDPMangerArchitecture.Interface; + public void restartUDPService() + { + onUDPReLink.Invoke(); + this.GetModel().closeServer(); + StartCoroutine(waitTwoSecond()); + } + public IEnumerator waitTwoSecond() + { + yield return new WaitForSeconds(2.0f); + this.GetModel().setUDPState(UDPLinkState.Linking); + } + public IArchitecture GetArchitecture() + { + return UDPMangerArchitecture.Interface; + } } -} -public class LinkUDPRequest : IRequest -{ - public string id; - public int type; - public LinkUDPRequest(int id) - { - this.id = id.ToString(); - this.type = 1; - } - public string toJson() + public class LinkUDPRequest : IRequest { - return JsonUtility.ToJson(this); + public string id; + public int type; + public LinkUDPRequest(int id) + { + this.id = id.ToString(); + this.type = 1; + } + public string toJson() + { + return JsonUtility.ToJson(this); + } } -} +} \ No newline at end of file diff --git a/Assets/MsgTransmitTools/UDPClient/UDPEventModel.cs b/Assets/MsgTransmitTools/UDPClient/UDPEventModel.cs index 92be64e..4928e47 100644 --- a/Assets/MsgTransmitTools/UDPClient/UDPEventModel.cs +++ b/Assets/MsgTransmitTools/UDPClient/UDPEventModel.cs @@ -1,8 +1,9 @@ using System.Collections; using System.Collections.Generic; using UnityEngine; -using QFramework; +using QFrameworkCP; +namespace JXSoft { public class UDPEventModel : DataEventModel { private UDPLinkState udpState = UDPLinkState.NoIp; @@ -114,4 +115,6 @@ using QFramework; exceptionMsg = exceptionMsg_; } } - #endregion \ No newline at end of file + #endregion + +} \ No newline at end of file diff --git a/Assets/MsgTransmitTools/UDPClient/UDPPrinter.cs b/Assets/MsgTransmitTools/UDPClient/UDPPrinter.cs index 6d86e9b..9aec51d 100644 --- a/Assets/MsgTransmitTools/UDPClient/UDPPrinter.cs +++ b/Assets/MsgTransmitTools/UDPClient/UDPPrinter.cs @@ -1,57 +1,54 @@ -using System; -using System.Collections; -using System.Collections.Generic; -using System.Net; -using System.Net.Sockets; -using System.Text; -using System.Threading; +using System.Threading; using UnityEngine; using UnityEngine.UI; -using QFramework; +using QFrameworkCP; -public class UDPPrinter : MonoBehaviour, IController, ICanSendEvent, ICanGetUtility -{ - private UDPUtility udpUtil; - public Transform udpMsgContent; - public GameObject udpMsgItem; - public InputField InputSendMsg; - private bool isUDPInit; - // Start is called before the first frame update - void Start() +namespace JXSoft { + public class UDPPrinter : MonoBehaviour, IController { - udpUtil = GetArchitecture().GetUtility(); - } + private UDPUtility udpUtil; + public Transform udpMsgContent; + public GameObject udpMsgItem; - // Update is called once per frame - void Update() - { - if (udpUtil != null && !"".Equals(udpUtil.getReceivedValue())) + public InputField InputSendMsg; + private bool isUDPInit; + // Start is called before the first frame update + void Start() { - GameObject item = Instantiate(udpMsgItem, udpMsgContent); - item.GetComponentInChildren().text = udpUtil.receivedData; - this.GetModel().onDataRecived.Invoke(udpUtil.receivedData); + udpUtil = GetArchitecture().GetUtility(); } - if (udpUtil.getTimeOutState() && udpUtil.isOpenUDP) + // Update is called once per frame + void Update() { - this.SendEvent(new onUDPLinkException(udpUtil.exceptionData)); - udpUtil.isOpenUDP = false; + if (udpUtil != null && !"".Equals(udpUtil.getReceivedValue())) + { + GameObject item = Instantiate(udpMsgItem, udpMsgContent); + item.GetComponentInChildren().text = udpUtil.receivedData; + this.GetModel().onDataRecived.Invoke(udpUtil.receivedData); + } + + if (udpUtil.getTimeOutState() && udpUtil.isOpenUDP) + { + this.SendEvent(new onUDPLinkException(udpUtil.exceptionData)); + udpUtil.isOpenUDP = false; + } } - } - private void OnDestroy() - { - if (udpUtil.reciveT != null && udpUtil.reciveT.ThreadState == ThreadState.Running) + private void OnDestroy() { - udpUtil.reciveT.Abort(); + if (udpUtil.reciveT != null && udpUtil.reciveT.ThreadState == ThreadState.Running) + { + udpUtil.reciveT.Abort(); + } + } + public void sendMsg() + { + this.GetUtility().sendData(InputSendMsg.text); + } + public IArchitecture GetArchitecture() + { + return UDPMangerArchitecture.Interface; } - } - public void sendMsg() - { - this.GetUtility().sendData(InputSendMsg.text); - } - public IArchitecture GetArchitecture() - { - return UDPMangerArchitecture.Interface; } } \ No newline at end of file diff --git a/Assets/MsgTransmitTools/UDPClient/UDPUtility.cs b/Assets/MsgTransmitTools/UDPClient/UDPUtility.cs index 6878dba..cd610f3 100644 --- a/Assets/MsgTransmitTools/UDPClient/UDPUtility.cs +++ b/Assets/MsgTransmitTools/UDPClient/UDPUtility.cs @@ -1,5 +1,5 @@ using UnityEngine; -using QFramework; +using QFrameworkCP; using System; using System.Text; using System.Net.Sockets; diff --git a/Assets/MsgTransmitTools/src/DataEventModel.cs b/Assets/MsgTransmitTools/src/DataEventModel.cs index 37f5c35..f353f55 100644 --- a/Assets/MsgTransmitTools/src/DataEventModel.cs +++ b/Assets/MsgTransmitTools/src/DataEventModel.cs @@ -1,188 +1,190 @@ using System; using System.Collections; using System.Collections.Generic; -using QFramework; +using QFrameworkCP; using UnityEngine; using UnityEngine.Events; -//任何通讯类围绕DataEventModel进行 -public abstract class DataEventModel : AbstractModel, ICanSendCommand, ICanRegisterEvent -{ - public IOCContainer mCommandContainer = new IOCContainer(); - public UnityStringEvent onDataRecived = new UnityStringEvent(); - public Color printColor = Color.white; - public void sendResponseCommand(string json) where T : IResponse, new() +namespace JXSoft { + //任何通讯类围绕DataEventModel进行 + public abstract class DataEventModel : AbstractModel { - //如果找不到对应命令,则添加命令 - if (mCommandContainer.Get>() == null) + public IOCContainer mCommandContainer = new IOCContainer(); + public UnityStringEvent onDataRecived = new UnityStringEvent(); + public Color printColor = Color.white; + public void sendResponseCommand(string json) where T : IResponse, new() { - mCommandContainer.Register(new ExcuteResponseCommand(new T())); + //如果找不到对应命令,则添加命令 + if (mCommandContainer.Get>() == null) + { + mCommandContainer.Register(new ExcuteResponseCommand(new T())); + } + //找到命令后添加命令 + mCommandContainer.Get>().setJson(json); + this.SendCommand(mCommandContainer.Get>()); } - //找到命令后添加命令 - mCommandContainer.Get>().setJson(json); - this.SendCommand(mCommandContainer.Get>()); - } - /// - /// 开启接收指定数据 - /// - /// 数据格式类型 - public void onReceive() where T : IResponse, new() - { - onDataRecived.AddListener(sendResponseCommand); + /// + /// 开启接收指定数据 + /// + /// 数据格式类型 + public void onReceive() where T : IResponse, new() + { + onDataRecived.AddListener(sendResponseCommand); + } + /// + /// 关闭接收指定数据 + /// + /// 数据格式类型 + public void offReceive() where T : IResponse, new() + { + onDataRecived.RemoveListener(sendResponseCommand); + } + + /// + /// 发送数据 + /// + /// 数据类型 + /// 请求数据 + public void sendRequestCommand(T request) where T : IRequest + { + if (mCommandContainer.Get>() == null) + { + mCommandContainer.Register(new SendRequestCommand(request)); + } + mCommandContainer.Get>().setRequest(request); + this.SendCommand(mCommandContainer.Get>()); + } } + + #region Command /// - /// 关闭接收指定数据 + /// 处理响应数据,添加对应的Command进行处理,需要提前生成命令池 /// - /// 数据格式类型 - public void offReceive() where T : IResponse, new() + /// 响应数据格式 + public class ExcuteResponseCommand : AbstractCommand where TResponse : IResponse { - onDataRecived.RemoveListener(sendResponseCommand); + public string json; + private TResponse response; + private Color printColor = Color.white; + public ExcuteResponseCommand(TResponse response) + { + if (this.response == null) + { + this.response = response; + } + } + protected override void OnExecute() + { + bool isSet = response.trySetData(json); + if (isSet) + { + Debug.Log("Received:" + response.toJson() + response.GetType()); + this.SendEvent(new ResponseMsgEvent(response)); + } + } + public void setJson(string json) + { + this.json = json; + } } /// /// 发送数据 /// - /// 数据类型 - /// 请求数据 - public void sendRequestCommand(T request) where T : IRequest + /// 发送数据格式 + public class SendRequestCommand : AbstractCommand where TRequest : IRequest { - if (mCommandContainer.Get>() == null) + public TRequest request; + public SendRequestCommand(TRequest request) { - mCommandContainer.Register(new SendRequestCommand(request)); + this.request = request; } - mCommandContainer.Get>().setRequest(request); - this.SendCommand(mCommandContainer.Get>()); - } -} - -#region Command -/// -/// 处理响应数据,添加对应的Command进行处理,需要提前生成命令池 -/// -/// 响应数据格式 -public class ExcuteResponseCommand : AbstractCommand where TResponse : IResponse -{ - public string json; - private TResponse response; - private Color printColor = Color.white; - public ExcuteResponseCommand(TResponse response) - { - if (this.response == null) + protected override void OnExecute() { - this.response = response; + this.SendEvent(new RequestMsgEvent(request)); } - } - protected override void OnExecute() - { - bool isSet = response.trySetData(json); - if (isSet) + public void setRequest(TRequest request) { - Debug.Log("Received:" + response.toJson() + response.GetType()); - this.SendEvent(new ResponseMsgEvent(response)); + this.request = request; } } - public void setJson(string json) - { - this.json = json; - } -} + #endregion -/// -/// 发送数据 -/// -/// 发送数据格式 -public class SendRequestCommand : AbstractCommand where TRequest : IRequest -{ - public TRequest request; - public SendRequestCommand(TRequest request) + #region interface + public interface IResponse { - this.request = request; + string toJson(); + /// + /// 尝试填充数据,如果json不合法,则返回false,忽略该条数据响应 + /// + /// + /// + bool trySetData(string json); + string getException(); } - protected override void OnExecute() - { - this.SendEvent(new RequestMsgEvent(request)); - } - public void setRequest(TRequest request) + + public interface IRequest { - this.request = request; + string toJson(); } -} -#endregion + #endregion -#region interface -public interface IResponse -{ - string toJson(); + #region AbstractClass /// - /// 尝试填充数据,如果json不合法,则返回false,忽略该条数据响应 + /// 使用抽象类时,必须满足可序列化 /// - /// - /// - bool trySetData(string json); - string getException(); -} - -public interface IRequest -{ - string toJson(); -} -#endregion - -#region AbstractClass -/// -/// 使用抽象类时,必须满足可序列化 -/// -[Serializable] -public abstract class AbstractResponse : IResponse -{ - private string exceptionMsg; - public virtual string toJson() + [Serializable] + public abstract class AbstractResponse : IResponse { - return JsonUtility.ToJson(this, true); - } - public virtual bool trySetData(string json) - { - try + private string exceptionMsg; + public virtual string toJson() { - JsonUtility.FromJsonOverwrite(json, this); - return true; + return JsonUtility.ToJson(this, true); } - catch (Exception e) + public virtual bool trySetData(string json) { - exceptionMsg = e.ToString(); - return false; + try + { + JsonUtility.FromJsonOverwrite(json, this); + return true; + } + catch (Exception e) + { + exceptionMsg = e.ToString(); + return false; + } + } + public string getException() + { + return exceptionMsg; } } - public string getException() - { - return exceptionMsg; - } -} -#endregion + #endregion -#region event -public struct ResponseMsgEvent -{ - public IResponse res; - public ResponseMsgEvent(IResponse res_) + #region event + public struct ResponseMsgEvent { - res = res_; - } -}; -public struct RequestMsgEvent -{ - public IRequest req; - public RequestMsgEvent(IRequest req_) + public IResponse res; + public ResponseMsgEvent(IResponse res_) + { + res = res_; + } + }; + public struct RequestMsgEvent { - req = req_; + public IRequest req; + public RequestMsgEvent(IRequest req_) + { + req = req_; + } } -} -#endregion + #endregion -[Serializable] -public class UnityStringEvent : UnityEvent -{ + [Serializable] + public class UnityStringEvent : UnityEvent + { + } } \ No newline at end of file diff --git a/Assets/MsgTransmitTools/src/QFrameCopy.cs b/Assets/MsgTransmitTools/src/QFrameCopy.cs index 6aef7de..3ea293d 100644 --- a/Assets/MsgTransmitTools/src/QFrameCopy.cs +++ b/Assets/MsgTransmitTools/src/QFrameCopy.cs @@ -25,7 +25,7 @@ using System; using System.Collections.Generic; using UnityEngine; -namespace QFramework +namespace QFrameworkCP { #region Architecture @@ -205,7 +205,7 @@ namespace QFramework #region Controller public interface IController : IBelongToArchitecture, ICanSendCommand, ICanGetModel, - ICanRegisterEvent, ICanSendQuery, ICanSendEvent + ICanRegisterEvent, ICanSendQuery, ICanSendEvent, ICanGetUtility { } @@ -213,7 +213,7 @@ namespace QFramework #region Model - public interface IModel : IBelongToArchitecture, ICanSetArchitecture, ICanGetUtility, ICanSendEvent + public interface IModel : IBelongToArchitecture, ICanSetArchitecture, ICanGetUtility, ICanSendEvent, ICanSendCommand, ICanRegisterEvent { void Init(); }