Browse Source

增加扩展方法,减少信息注册时的if判断使用

master
DESKTOP-B25GA9E\W35 2 years ago
parent
commit
abe5db6e24
  1. 6
      Assets/MsgTransmitTools/DataClass/BluetoothGateway.cs
  2. 6
      Assets/MsgTransmitTools/ExtendLinkModel/HttpServer/HttpServerView.cs
  3. 11
      Assets/MsgTransmitTools/src/DataEventModel.cs

6
Assets/MsgTransmitTools/DataClass/BluetoothGateway.cs

@ -5,7 +5,7 @@ using LitJson;
using System; using System;
namespace JXSoft { namespace JXSoft {
public class BluetoothGateway:IResponse public struct BluetoothGateway:IResponse
{ {
/// <summary> /// <summary>
/// ///
@ -34,10 +34,6 @@ namespace JXSoft {
private string exceptionMsg; private string exceptionMsg;
public BluetoothGateway() {
}
public string findDataByMac(string mac) { public string findDataByMac(string mac) {
foreach (List<object> deviceMsg in devices) { foreach (List<object> deviceMsg in devices) {

6
Assets/MsgTransmitTools/ExtendLinkModel/HttpServer/HttpServerView.cs

@ -24,10 +24,8 @@ namespace JXSoft {
void Start() void Start()
{ {
this.httpServer = this.GetUtility<HttpServerUtility>(); this.httpServer = this.GetUtility<HttpServerUtility>();
this.RegisterEvent<ResponseMsgEvent>(e => { this.RegisterMessageEvent<BluetoothGateway>(e => {
if (e.res.GetType() == typeof(BluetoothGateway)) { Debug.Log("收到消息:"+e.ip);
//
}
}).UnRegisterWhenGameObjectDestroyed(gameObject); }).UnRegisterWhenGameObjectDestroyed(gameObject);
this.GetModel<HttpServerModel>().onReceive<BluetoothGateway>(); this.GetModel<HttpServerModel>().onReceive<BluetoothGateway>();
} }

11
Assets/MsgTransmitTools/src/DataEventModel.cs

@ -228,9 +228,16 @@ namespace JXSoft {
} }
#endregion #endregion
#region #region Extention
public static class CanRegistMessageExtention { public static class CanRegistMessageExtention {
public static IUnRegister RegisterMessageEvent<TResponse>(this ICanRegisterEvent self, Action<TResponse> onEvent)
{
return self.GetArchitecture().RegisterEvent<ResponseMsgEvent>(e=> {
if (e.res.GetType() == typeof(TResponse)) {
onEvent.Invoke((TResponse)e.res);
}
});
}
} }
#endregion #endregion

Loading…
Cancel
Save