|
|
@ -11,9 +11,8 @@ public abstract class DataEventModel : AbstractModel, ICanSendCommand, ICanRegis |
|
|
|
{ |
|
|
|
{ |
|
|
|
public IOCContainer mCommandContainer = new IOCContainer(); |
|
|
|
public IOCContainer mCommandContainer = new IOCContainer(); |
|
|
|
public UnityStringEvent onDataRecived = new UnityStringEvent(); |
|
|
|
public UnityStringEvent onDataRecived = new UnityStringEvent(); |
|
|
|
|
|
|
|
public Color printColor = Color.white; |
|
|
|
|
|
|
|
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) |
|
|
|
{ |
|
|
|
{ |
|
|
@ -22,13 +21,14 @@ public abstract class DataEventModel : AbstractModel, ICanSendCommand, ICanRegis |
|
|
|
mCommandContainer.Get<ExcuteResponseCommand<T>>().setJson(json); |
|
|
|
mCommandContainer.Get<ExcuteResponseCommand<T>>().setJson(json); |
|
|
|
this.SendCommand(mCommandContainer.Get<ExcuteResponseCommand<T>>()); |
|
|
|
this.SendCommand(mCommandContainer.Get<ExcuteResponseCommand<T>>()); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/// <summary> |
|
|
|
/// <summary> |
|
|
|
/// 开启接收指定数据 |
|
|
|
/// 开启接收指定数据 |
|
|
|
/// </summary> |
|
|
|
/// </summary> |
|
|
|
/// <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(excuteResponseCommand<T>); |
|
|
|
onDataRecived.AddListener(sendResponseCommand<T>); |
|
|
|
} |
|
|
|
} |
|
|
|
/// <summary> |
|
|
|
/// <summary> |
|
|
|
/// 关闭接收指定数据 |
|
|
|
/// 关闭接收指定数据 |
|
|
@ -36,8 +36,9 @@ public abstract class DataEventModel : AbstractModel, ICanSendCommand, ICanRegis |
|
|
|
/// <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(excuteResponseCommand<T>); |
|
|
|
onDataRecived.RemoveListener(sendResponseCommand<T>); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/// <summary> |
|
|
|
/// <summary> |
|
|
|
/// 发送数据 |
|
|
|
/// 发送数据 |
|
|
|
/// </summary> |
|
|
|
/// </summary> |
|
|
@ -63,6 +64,7 @@ public class ExcuteResponseCommand<TResponse> : AbstractCommand where TResponse |
|
|
|
{ |
|
|
|
{ |
|
|
|
public string json; |
|
|
|
public string json; |
|
|
|
private TResponse response; |
|
|
|
private TResponse response; |
|
|
|
|
|
|
|
private Color printColor = Color.white; |
|
|
|
public ExcuteResponseCommand(TResponse response) |
|
|
|
public ExcuteResponseCommand(TResponse response) |
|
|
|
{ |
|
|
|
{ |
|
|
|
if (this.response == null) |
|
|
|
if (this.response == null) |
|
|
@ -94,6 +96,7 @@ public class SendRequestCommand<TRequest> : AbstractCommand where TRequest : IRe |
|
|
|
} |
|
|
|
} |
|
|
|
protected override void OnExecute() |
|
|
|
protected override void OnExecute() |
|
|
|
{ |
|
|
|
{ |
|
|
|
|
|
|
|
//此处需要修改 |
|
|
|
this.SendEvent(new RequestMsgEvent(request)); |
|
|
|
this.SendEvent(new RequestMsgEvent(request)); |
|
|
|
} |
|
|
|
} |
|
|
|
public void setRequest(TRequest request) |
|
|
|
public void setRequest(TRequest request) |
|
|
@ -120,22 +123,6 @@ public interface IRequest |
|
|
|
{ |
|
|
|
{ |
|
|
|
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 |
|
|
@ -179,9 +166,11 @@ public struct ResponseMsgEvent |
|
|
|
res = res_; |
|
|
|
res = res_; |
|
|
|
} |
|
|
|
} |
|
|
|
}; |
|
|
|
}; |
|
|
|
public struct RequestMsgEvent { |
|
|
|
public struct RequestMsgEvent |
|
|
|
|
|
|
|
{ |
|
|
|
public IRequest req; |
|
|
|
public IRequest req; |
|
|
|
public RequestMsgEvent(IRequest req_) { |
|
|
|
public RequestMsgEvent(IRequest req_) |
|
|
|
|
|
|
|
{ |
|
|
|
req = req_; |
|
|
|
req = req_; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |