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. 13
      Assets/MsgTransmitTools/src/DataEventModel.cs

6
Assets/MsgTransmitTools/DataClass/BluetoothGateway.cs

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

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

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

13
Assets/MsgTransmitTools/src/DataEventModel.cs

@ -228,9 +228,16 @@ namespace JXSoft { @@ -228,9 +228,16 @@ namespace JXSoft {
}
#endregion
#region
public static class CanRegistMessageExtention {
#region Extention
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

Loading…
Cancel
Save