|
|
@ -1,14 +1,15 @@ |
|
|
|
using System; |
|
|
|
using System; |
|
|
|
using System.Collections; |
|
|
|
using System.Collections; |
|
|
|
using System.Collections.Generic; |
|
|
|
using System.Collections.Generic; |
|
|
|
using QFramework; |
|
|
|
using QFrameworkCP; |
|
|
|
using UnityEngine; |
|
|
|
using UnityEngine; |
|
|
|
using UnityEngine.Events; |
|
|
|
using UnityEngine.Events; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//任何通讯类围绕DataEventModel进行 |
|
|
|
namespace JXSoft { |
|
|
|
public abstract class DataEventModel : AbstractModel, ICanSendCommand, ICanRegisterEvent |
|
|
|
//任何通讯类围绕DataEventModel进行 |
|
|
|
{ |
|
|
|
public abstract class DataEventModel : AbstractModel |
|
|
|
|
|
|
|
{ |
|
|
|
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 Color printColor = Color.white; |
|
|
@ -55,15 +56,15 @@ public abstract class DataEventModel : AbstractModel, ICanSendCommand, ICanRegis |
|
|
|
mCommandContainer.Get<SendRequestCommand<T>>().setRequest(request); |
|
|
|
mCommandContainer.Get<SendRequestCommand<T>>().setRequest(request); |
|
|
|
this.SendCommand(mCommandContainer.Get<SendRequestCommand<T>>()); |
|
|
|
this.SendCommand(mCommandContainer.Get<SendRequestCommand<T>>()); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
#region Command |
|
|
|
#region Command |
|
|
|
/// <summary> |
|
|
|
/// <summary> |
|
|
|
/// 处理响应数据,添加对应的Command进行处理,需要提前生成命令池 |
|
|
|
/// 处理响应数据,添加对应的Command进行处理,需要提前生成命令池 |
|
|
|
/// </summary> |
|
|
|
/// </summary> |
|
|
|
/// <typeparam name="TResponse">响应数据格式</typeparam> |
|
|
|
/// <typeparam name="TResponse">响应数据格式</typeparam> |
|
|
|
public class ExcuteResponseCommand<TResponse> : AbstractCommand where TResponse : IResponse |
|
|
|
public class ExcuteResponseCommand<TResponse> : AbstractCommand where TResponse : IResponse |
|
|
|
{ |
|
|
|
{ |
|
|
|
public string json; |
|
|
|
public string json; |
|
|
|
private TResponse response; |
|
|
|
private TResponse response; |
|
|
|
private Color printColor = Color.white; |
|
|
|
private Color printColor = Color.white; |
|
|
@ -87,14 +88,14 @@ public class ExcuteResponseCommand<TResponse> : AbstractCommand where TResponse |
|
|
|
{ |
|
|
|
{ |
|
|
|
this.json = json; |
|
|
|
this.json = json; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/// <summary> |
|
|
|
/// <summary> |
|
|
|
/// 发送数据 |
|
|
|
/// 发送数据 |
|
|
|
/// </summary> |
|
|
|
/// </summary> |
|
|
|
/// <typeparam name="TRequest">发送数据格式</typeparam> |
|
|
|
/// <typeparam name="TRequest">发送数据格式</typeparam> |
|
|
|
public class SendRequestCommand<TRequest> : AbstractCommand where TRequest : IRequest |
|
|
|
public class SendRequestCommand<TRequest> : AbstractCommand where TRequest : IRequest |
|
|
|
{ |
|
|
|
{ |
|
|
|
public TRequest request; |
|
|
|
public TRequest request; |
|
|
|
public SendRequestCommand(TRequest request) |
|
|
|
public SendRequestCommand(TRequest request) |
|
|
|
{ |
|
|
|
{ |
|
|
@ -108,12 +109,12 @@ public class SendRequestCommand<TRequest> : AbstractCommand where TRequest : IRe |
|
|
|
{ |
|
|
|
{ |
|
|
|
this.request = request; |
|
|
|
this.request = request; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
#endregion |
|
|
|
#endregion |
|
|
|
|
|
|
|
|
|
|
|
#region interface |
|
|
|
#region interface |
|
|
|
public interface IResponse |
|
|
|
public interface IResponse |
|
|
|
{ |
|
|
|
{ |
|
|
|
string toJson(); |
|
|
|
string toJson(); |
|
|
|
/// <summary> |
|
|
|
/// <summary> |
|
|
|
/// 尝试填充数据,如果json不合法,则返回false,忽略该条数据响应 |
|
|
|
/// 尝试填充数据,如果json不合法,则返回false,忽略该条数据响应 |
|
|
@ -122,21 +123,21 @@ public interface IResponse |
|
|
|
/// <returns></returns> |
|
|
|
/// <returns></returns> |
|
|
|
bool trySetData(string json); |
|
|
|
bool trySetData(string json); |
|
|
|
string getException(); |
|
|
|
string getException(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public interface IRequest |
|
|
|
public interface IRequest |
|
|
|
{ |
|
|
|
{ |
|
|
|
string toJson(); |
|
|
|
string toJson(); |
|
|
|
} |
|
|
|
} |
|
|
|
#endregion |
|
|
|
#endregion |
|
|
|
|
|
|
|
|
|
|
|
#region AbstractClass |
|
|
|
#region AbstractClass |
|
|
|
/// <summary> |
|
|
|
/// <summary> |
|
|
|
/// 使用抽象类时,必须满足可序列化 |
|
|
|
/// 使用抽象类时,必须满足可序列化 |
|
|
|
/// </summary> |
|
|
|
/// </summary> |
|
|
|
[Serializable] |
|
|
|
[Serializable] |
|
|
|
public abstract class AbstractResponse : IResponse |
|
|
|
public abstract class AbstractResponse : IResponse |
|
|
|
{ |
|
|
|
{ |
|
|
|
private string exceptionMsg; |
|
|
|
private string exceptionMsg; |
|
|
|
public virtual string toJson() |
|
|
|
public virtual string toJson() |
|
|
|
{ |
|
|
|
{ |
|
|
@ -159,30 +160,31 @@ public abstract class AbstractResponse : IResponse |
|
|
|
{ |
|
|
|
{ |
|
|
|
return exceptionMsg; |
|
|
|
return exceptionMsg; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
#endregion |
|
|
|
#endregion |
|
|
|
|
|
|
|
|
|
|
|
#region event |
|
|
|
#region event |
|
|
|
public struct ResponseMsgEvent |
|
|
|
public struct ResponseMsgEvent |
|
|
|
{ |
|
|
|
{ |
|
|
|
public IResponse res; |
|
|
|
public IResponse res; |
|
|
|
public ResponseMsgEvent(IResponse res_) |
|
|
|
public ResponseMsgEvent(IResponse res_) |
|
|
|
{ |
|
|
|
{ |
|
|
|
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_; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
#endregion |
|
|
|
#endregion |
|
|
|
|
|
|
|
|
|
|
|
[Serializable] |
|
|
|
[Serializable] |
|
|
|
public class UnityStringEvent : UnityEvent<string> |
|
|
|
public class UnityStringEvent : UnityEvent<string> |
|
|
|
{ |
|
|
|
{ |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |