Browse Source

更改QFrame的nameSpace

master
DESKTOP-B25GA9E\W35 2 years ago
parent
commit
ef93cedfad
  1. 6
      Assets/MsgTransmitTools/TCPClient/Script/Source/TCPEventModel.cs
  2. 4
      Assets/MsgTransmitTools/TCPClient/Script/Source/TCPUtility.cs
  3. 183
      Assets/MsgTransmitTools/TCPClient/Script/View/TCPClientView.cs
  4. 6
      Assets/MsgTransmitTools/TCPClient/Script/View/TCPPrinter.cs
  5. 172
      Assets/MsgTransmitTools/UDPClient/UDPClientView.cs
  6. 7
      Assets/MsgTransmitTools/UDPClient/UDPEventModel.cs
  7. 81
      Assets/MsgTransmitTools/UDPClient/UDPPrinter.cs
  8. 2
      Assets/MsgTransmitTools/UDPClient/UDPUtility.cs
  9. 280
      Assets/MsgTransmitTools/src/DataEventModel.cs
  10. 6
      Assets/MsgTransmitTools/src/QFrameCopy.cs

6
Assets/MsgTransmitTools/TCPClient/Script/Source/TCPEventModel.cs

@ -1,12 +1,12 @@ @@ -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 = "";

4
Assets/MsgTransmitTools/TCPClient/Script/Source/TCPUtility.cs

@ -1,4 +1,4 @@ @@ -1,4 +1,4 @@
using QFramework;
using QFrameworkCP;
using UnityEngine;
using System;
using System.Text;
@ -8,7 +8,7 @@ using System.Threading.Tasks; @@ -8,7 +8,7 @@ using System.Threading.Tasks;
using System.Threading;
using System.Net.NetworkInformation;
namespace TCPClientTools
namespace JXSoft
{
public class TCPUtility : IUtility
{

183
Assets/MsgTransmitTools/TCPClient/Script/View/TCPClientView.cs

@ -2,111 +2,114 @@ using System.Collections; @@ -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<TCPMangerArchitecture>
{
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<TCPMangerArchitecture>
{
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<TCPStateChangedEvent>(e => {
if (e.state == TCPLinkState.Linking)
{
Debug.Log("TCP开始链接");
this.GetModel<TCPEventModel>().linkServer();
}
if (e.state == TCPLinkState.LinkSucess)
{
Debug.Log("TCP链接成功");
this.GetModel<TCPEventModel>().onReceive<LinkSuccessResponse>();
this.GetModel<TCPEventModel>().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<ResponseMsgEvent>(e =>
{
if (e.res.GetType() == typeof(LinkSuccessResponse))
GetArchitecture().RegisterEvent<TCPStateChangedEvent>(e => {
if (e.state == TCPLinkState.Linking)
{
Debug.Log("TCP开始链接");
this.GetModel<TCPEventModel>().linkServer();
}
if (e.state == TCPLinkState.LinkSucess)
{
Debug.Log("TCP链接成功");
this.GetModel<TCPEventModel>().onReceive<LinkSuccessResponse>();
this.GetModel<TCPEventModel>().sendRequestCommand(new LinkTCPRequest(deviceId));
onTCPLinkSuccess.Invoke();
}
if (e.state == TCPLinkState.LinkFaild)
{
Debug.Log("TCP连接失败,请联系设备服务管理员");
onTCPLinkFaild.Invoke();
}
});
GetArchitecture().RegisterEvent<ResponseMsgEvent>(e =>
{
Debug.Log("Link Server success");
this.GetModel<TCPEventModel>().offReceive<LinkSuccessResponse>();
onServerConnected.Invoke();
}
});
if (e.res.GetType() == typeof(LinkSuccessResponse))
{
Debug.Log("Link Server success");
this.GetModel<TCPEventModel>().offReceive<LinkSuccessResponse>();
onServerConnected.Invoke();
}
});
this.GetModel<TCPEventModel>().setTCPState(TCPLinkState.NoIp);
this.GetModel<TCPEventModel>().setIP(tcpAddress, tcpPort);
}
this.GetModel<TCPEventModel>().setTCPState(TCPLinkState.NoIp);
this.GetModel<TCPEventModel>().setIP(tcpAddress, tcpPort);
}
public void restartTCPService() {
onTCPReLink.Invoke();
this.GetModel<TCPEventModel>().closeServer();
StartCoroutine(waitTwoSecond());
}
public IEnumerator waitTwoSecond() {
yield return new WaitForSeconds(2.0f);
this.GetModel<TCPEventModel>().setTCPState(TCPLinkState.Linking);
public void restartTCPService() {
onTCPReLink.Invoke();
this.GetModel<TCPEventModel>().closeServer();
StartCoroutine(waitTwoSecond());
}
public IEnumerator waitTwoSecond() {
yield return new WaitForSeconds(2.0f);
this.GetModel<TCPEventModel>().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);
}
}
}

6
Assets/MsgTransmitTools/TCPClient/Script/View/TCPPrinter.cs

@ -3,12 +3,12 @@ using System.Collections.Generic; @@ -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;

172
Assets/MsgTransmitTools/UDPClient/UDPClientView.cs

@ -2,105 +2,107 @@ @@ -2,105 +2,107 @@
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Events;
using QFramework;
using QFrameworkCP;
using System;
public class UDPMangerArchitecture : Architecture<UDPMangerArchitecture>
{
protected override void Init()
namespace JXSoft {
public class UDPMangerArchitecture : Architecture<UDPMangerArchitecture>
{
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<UDPStateChangedEvent>(e => {
if (e.state == UDPLinkState.Linking)
{
Debug.Log("UDP开始链接");
this.GetModel<UDPEventModel>().linkServer();
}
if (e.state == UDPLinkState.LinkSucess)
{
Debug.Log("UDP链接成功");
this.GetModel<UDPEventModel>().onReceive<LinkSuccessResponse>();
this.GetModel<UDPEventModel>().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<ResponseMsgEvent>(e =>
public void initUDPService()
{
if (e.res.GetType() == typeof(LinkSuccessResponse))
UDPAddress = "127.0.0.1";
UDPPort = 20000;
deviceId = 1;
GetArchitecture().RegisterEvent<UDPStateChangedEvent>(e => {
if (e.state == UDPLinkState.Linking)
{
Debug.Log("UDP开始链接");
this.GetModel<UDPEventModel>().linkServer();
}
if (e.state == UDPLinkState.LinkSucess)
{
Debug.Log("UDP链接成功");
this.GetModel<UDPEventModel>().onReceive<LinkSuccessResponse>();
this.GetModel<UDPEventModel>().sendRequestCommand(new LinkUDPRequest(deviceId));
onUDPLinkSuccess.Invoke();
}
if (e.state == UDPLinkState.LinkFaild)
{
Debug.Log("UDP连接失败,请联系设备服务管理员");
onUDPLinkFaild.Invoke();
}
});
GetArchitecture().RegisterEvent<ResponseMsgEvent>(e =>
{
Debug.Log("Link Server success");
this.GetModel<UDPEventModel>().offReceive<LinkSuccessResponse>();
onServerConnected.Invoke();
}
});
if (e.res.GetType() == typeof(LinkSuccessResponse))
{
Debug.Log("Link Server success");
this.GetModel<UDPEventModel>().offReceive<LinkSuccessResponse>();
onServerConnected.Invoke();
}
});
this.GetModel<UDPEventModel>().setUDPState(UDPLinkState.NoIp);
this.GetModel<UDPEventModel>().setIP(UDPAddress, UDPPort);
}
this.GetModel<UDPEventModel>().setUDPState(UDPLinkState.NoIp);
this.GetModel<UDPEventModel>().setIP(UDPAddress, UDPPort);
}
public void restartUDPService()
{
onUDPReLink.Invoke();
this.GetModel<UDPEventModel>().closeServer();
StartCoroutine(waitTwoSecond());
}
public IEnumerator waitTwoSecond()
{
yield return new WaitForSeconds(2.0f);
this.GetModel<UDPEventModel>().setUDPState(UDPLinkState.Linking);
}
public IArchitecture GetArchitecture()
{
return UDPMangerArchitecture.Interface;
public void restartUDPService()
{
onUDPReLink.Invoke();
this.GetModel<UDPEventModel>().closeServer();
StartCoroutine(waitTwoSecond());
}
public IEnumerator waitTwoSecond()
{
yield return new WaitForSeconds(2.0f);
this.GetModel<UDPEventModel>().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);
}
}
}
}

7
Assets/MsgTransmitTools/UDPClient/UDPEventModel.cs

@ -1,8 +1,9 @@ @@ -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; @@ -114,4 +115,6 @@ using QFramework;
exceptionMsg = exceptionMsg_;
}
}
#endregion
#endregion
}

81
Assets/MsgTransmitTools/UDPClient/UDPPrinter.cs

@ -1,57 +1,54 @@ @@ -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<UDPUtility>();
}
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>().text = udpUtil.receivedData;
this.GetModel<UDPEventModel>().onDataRecived.Invoke(udpUtil.receivedData);
udpUtil = GetArchitecture().GetUtility<UDPUtility>();
}
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>().text = udpUtil.receivedData;
this.GetModel<UDPEventModel>().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<UDPUtility>().sendData(InputSendMsg.text);
}
public IArchitecture GetArchitecture()
{
return UDPMangerArchitecture.Interface;
}
}
public void sendMsg()
{
this.GetUtility<UDPUtility>().sendData(InputSendMsg.text);
}
public IArchitecture GetArchitecture()
{
return UDPMangerArchitecture.Interface;
}
}

2
Assets/MsgTransmitTools/UDPClient/UDPUtility.cs

@ -1,5 +1,5 @@ @@ -1,5 +1,5 @@
using UnityEngine;
using QFramework;
using QFrameworkCP;
using System;
using System.Text;
using System.Net.Sockets;

280
Assets/MsgTransmitTools/src/DataEventModel.cs

@ -1,188 +1,190 @@ @@ -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<T>(string json) where T : IResponse, new()
namespace JXSoft {
//任何通讯类围绕DataEventModel进行
public abstract class DataEventModel : AbstractModel
{
//如果找不到对应命令,则添加命令
if (mCommandContainer.Get<ExcuteResponseCommand<T>>() == null)
public IOCContainer mCommandContainer = new IOCContainer();
public UnityStringEvent onDataRecived = new UnityStringEvent();
public Color printColor = Color.white;
public void sendResponseCommand<T>(string json) where T : IResponse, new()
{
mCommandContainer.Register(new ExcuteResponseCommand<T>(new T()));
//如果找不到对应命令,则添加命令
if (mCommandContainer.Get<ExcuteResponseCommand<T>>() == null)
{
mCommandContainer.Register(new ExcuteResponseCommand<T>(new T()));
}
//找到命令后添加命令
mCommandContainer.Get<ExcuteResponseCommand<T>>().setJson(json);
this.SendCommand(mCommandContainer.Get<ExcuteResponseCommand<T>>());
}
//找到命令后添加命令
mCommandContainer.Get<ExcuteResponseCommand<T>>().setJson(json);
this.SendCommand(mCommandContainer.Get<ExcuteResponseCommand<T>>());
}
/// <summary>
/// 开启接收指定数据
/// </summary>
/// <typeparam name="T">数据格式类型</typeparam>
public void onReceive<T>() where T : IResponse, new()
{
onDataRecived.AddListener(sendResponseCommand<T>);
/// <summary>
/// 开启接收指定数据
/// </summary>
/// <typeparam name="T">数据格式类型</typeparam>
public void onReceive<T>() where T : IResponse, new()
{
onDataRecived.AddListener(sendResponseCommand<T>);
}
/// <summary>
/// 关闭接收指定数据
/// </summary>
/// <typeparam name="T">数据格式类型</typeparam>
public void offReceive<T>() where T : IResponse, new()
{
onDataRecived.RemoveListener(sendResponseCommand<T>);
}
/// <summary>
/// 发送数据
/// </summary>
/// <typeparam name="T">数据类型</typeparam>
/// <param name="request">请求数据</param>
public void sendRequestCommand<T>(T request) where T : IRequest
{
if (mCommandContainer.Get<SendRequestCommand<T>>() == null)
{
mCommandContainer.Register(new SendRequestCommand<T>(request));
}
mCommandContainer.Get<SendRequestCommand<T>>().setRequest(request);
this.SendCommand(mCommandContainer.Get<SendRequestCommand<T>>());
}
}
#region Command
/// <summary>
/// 关闭接收指定数据
/// 处理响应数据,添加对应的Command进行处理,需要提前生成命令池
/// </summary>
/// <typeparam name="T">数据格式类型</typeparam>
public void offReceive<T>() where T : IResponse, new()
/// <typeparam name="TResponse">响应数据格式</typeparam>
public class ExcuteResponseCommand<TResponse> : AbstractCommand where TResponse : IResponse
{
onDataRecived.RemoveListener(sendResponseCommand<T>);
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;
}
}
/// <summary>
/// 发送数据
/// </summary>
/// <typeparam name="T">数据类型</typeparam>
/// <param name="request">请求数据</param>
public void sendRequestCommand<T>(T request) where T : IRequest
/// <typeparam name="TRequest">发送数据格式</typeparam>
public class SendRequestCommand<TRequest> : AbstractCommand where TRequest : IRequest
{
if (mCommandContainer.Get<SendRequestCommand<T>>() == null)
public TRequest request;
public SendRequestCommand(TRequest request)
{
mCommandContainer.Register(new SendRequestCommand<T>(request));
this.request = request;
}
mCommandContainer.Get<SendRequestCommand<T>>().setRequest(request);
this.SendCommand(mCommandContainer.Get<SendRequestCommand<T>>());
}
}
#region Command
/// <summary>
/// 处理响应数据,添加对应的Command进行处理,需要提前生成命令池
/// </summary>
/// <typeparam name="TResponse">响应数据格式</typeparam>
public class ExcuteResponseCommand<TResponse> : 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
/// <summary>
/// 发送数据
/// </summary>
/// <typeparam name="TRequest">发送数据格式</typeparam>
public class SendRequestCommand<TRequest> : AbstractCommand where TRequest : IRequest
{
public TRequest request;
public SendRequestCommand(TRequest request)
#region interface
public interface IResponse
{
this.request = request;
string toJson();
/// <summary>
/// 尝试填充数据,如果json不合法,则返回false,忽略该条数据响应
/// </summary>
/// <param name="json"></param>
/// <returns></returns>
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
/// <summary>
/// 尝试填充数据,如果json不合法,则返回false,忽略该条数据响应
/// 使用抽象类时,必须满足可序列化
/// </summary>
/// <param name="json"></param>
/// <returns></returns>
bool trySetData(string json);
string getException();
}
public interface IRequest
{
string toJson();
}
#endregion
#region AbstractClass
/// <summary>
/// 使用抽象类时,必须满足可序列化
/// </summary>
[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<string>
{
[Serializable]
public class UnityStringEvent : UnityEvent<string>
{
}
}

6
Assets/MsgTransmitTools/src/QFrameCopy.cs

@ -25,7 +25,7 @@ using System; @@ -25,7 +25,7 @@ using System;
using System.Collections.Generic;
using UnityEngine;
namespace QFramework
namespace QFrameworkCP
{
#region Architecture
@ -205,7 +205,7 @@ namespace QFramework @@ -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 @@ -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();
}

Loading…
Cancel
Save