|
|
@ -5,7 +5,6 @@ using QFramework; |
|
|
|
using UnityEngine; |
|
|
|
using UnityEngine; |
|
|
|
using UnityEngine.Events; |
|
|
|
using UnityEngine.Events; |
|
|
|
|
|
|
|
|
|
|
|
namespace TCPClientTools { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//任何通讯类围绕DataEventModel进行 |
|
|
|
//任何通讯类围绕DataEventModel进行 |
|
|
|
public abstract class DataEventModel : AbstractModel, ICanSendCommand, ICanRegisterEvent |
|
|
|
public abstract class DataEventModel : AbstractModel, ICanSendCommand, ICanRegisterEvent |
|
|
@ -13,7 +12,8 @@ namespace TCPClientTools { |
|
|
|
public IOCContainer mCommandContainer = new IOCContainer(); |
|
|
|
public IOCContainer mCommandContainer = new IOCContainer(); |
|
|
|
public UnityStringEvent onDataRecived = new UnityStringEvent(); |
|
|
|
public UnityStringEvent onDataRecived = new UnityStringEvent(); |
|
|
|
|
|
|
|
|
|
|
|
public void sendResponseCommand<T>(string json) where T : IResponse, new() |
|
|
|
|
|
|
|
|
|
|
|
public void excuteResponseCommand<T>(string json) where T : IResponse, new() |
|
|
|
{ |
|
|
|
{ |
|
|
|
if (mCommandContainer.Get<ExcuteResponseCommand<T>>() == null) |
|
|
|
if (mCommandContainer.Get<ExcuteResponseCommand<T>>() == null) |
|
|
|
{ |
|
|
|
{ |
|
|
@ -28,7 +28,7 @@ namespace TCPClientTools { |
|
|
|
/// <typeparam name="T">数据格式类型</typeparam> |
|
|
|
/// <typeparam name="T">数据格式类型</typeparam> |
|
|
|
public void onReceive<T>() where T : IResponse, new() |
|
|
|
public void onReceive<T>() where T : IResponse, new() |
|
|
|
{ |
|
|
|
{ |
|
|
|
onDataRecived.AddListener(sendResponseCommand<T>); |
|
|
|
onDataRecived.AddListener(excuteResponseCommand<T>); |
|
|
|
} |
|
|
|
} |
|
|
|
/// <summary> |
|
|
|
/// <summary> |
|
|
|
/// 关闭接收指定数据 |
|
|
|
/// 关闭接收指定数据 |
|
|
@ -36,7 +36,7 @@ namespace TCPClientTools { |
|
|
|
/// <typeparam name="T">数据格式类型</typeparam> |
|
|
|
/// <typeparam name="T">数据格式类型</typeparam> |
|
|
|
public void offReceive<T>() where T : IResponse, new() |
|
|
|
public void offReceive<T>() where T : IResponse, new() |
|
|
|
{ |
|
|
|
{ |
|
|
|
onDataRecived.RemoveListener(sendResponseCommand<T>); |
|
|
|
onDataRecived.RemoveListener(excuteResponseCommand<T>); |
|
|
|
} |
|
|
|
} |
|
|
|
/// <summary> |
|
|
|
/// <summary> |
|
|
|
/// 发送数据 |
|
|
|
/// 发送数据 |
|
|
@ -94,15 +94,7 @@ namespace TCPClientTools { |
|
|
|
} |
|
|
|
} |
|
|
|
protected override void OnExecute() |
|
|
|
protected override void OnExecute() |
|
|
|
{ |
|
|
|
{ |
|
|
|
if (this.GetUtility<TCPUtility>().isOpenTCP) |
|
|
|
this.SendEvent(new RequestMsgEvent(request)); |
|
|
|
{ |
|
|
|
|
|
|
|
this.GetUtility<TCPUtility>().sendData(request.toJson()); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
else |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
Debug.LogWarning("请先开启TCP链接"); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
//throw new NotImplementedException(); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
public void setRequest(TRequest request) |
|
|
|
public void setRequest(TRequest request) |
|
|
|
{ |
|
|
|
{ |
|
|
@ -128,6 +120,22 @@ namespace TCPClientTools { |
|
|
|
{ |
|
|
|
{ |
|
|
|
string toJson(); |
|
|
|
string toJson(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//用于标准化通讯方案(具体链接管理,由外部类决定,本接口只提供开启链接跟关闭链接) |
|
|
|
|
|
|
|
public interface IProtocol { |
|
|
|
|
|
|
|
void linkServer(); |
|
|
|
|
|
|
|
void closeServer(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
#endregion |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#region Extention |
|
|
|
|
|
|
|
/* |
|
|
|
|
|
|
|
public static class CanGetStateExtention { |
|
|
|
|
|
|
|
public static void GetState<TLinkStatus>(this IProtocol self) { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
*/ |
|
|
|
#endregion |
|
|
|
#endregion |
|
|
|
|
|
|
|
|
|
|
|
#region AbstractClass |
|
|
|
#region AbstractClass |
|
|
@ -171,10 +179,16 @@ namespace TCPClientTools { |
|
|
|
res = res_; |
|
|
|
res = res_; |
|
|
|
} |
|
|
|
} |
|
|
|
}; |
|
|
|
}; |
|
|
|
|
|
|
|
public struct RequestMsgEvent { |
|
|
|
|
|
|
|
public IRequest req; |
|
|
|
|
|
|
|
public RequestMsgEvent(IRequest req_) { |
|
|
|
|
|
|
|
req = req_; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
#endregion |
|
|
|
#endregion |
|
|
|
|
|
|
|
|
|
|
|
[Serializable] |
|
|
|
[Serializable] |
|
|
|
public class UnityStringEvent : UnityEvent<string> |
|
|
|
public class UnityStringEvent : UnityEvent<string> |
|
|
|
{ |
|
|
|
{ |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|