Browse Source

部分解耦

master
DESKTOP-B25GA9E\W35 2 years ago
parent
commit
48b4771fd7
  1. 5
      Assets/Plugins/Android/BTPluginAndroid.aar.meta
  2. 42
      Assets/TCPClient/Script/Source/DataEventModel.cs
  3. 22
      Assets/TCPClient/Script/Source/TCPEventModel.cs
  4. 8
      Assets/TCPClient/Script/View/TCPClientView.cs

5
Assets/Plugins/Android/BTPluginAndroid.aar.meta

@ -1,14 +1,15 @@ @@ -1,14 +1,15 @@
fileFormatVersion: 2
guid: dbd87312a872da045b50fc427851aa45
timeCreated: 1569408333
licenseType: Store
PluginImporter:
externalObjects: {}
serializedVersion: 2
iconMap: {}
executionOrder: {}
defineConstraints: []
isPreloaded: 0
isOverridable: 0
isExplicitlyReferenced: 0
validateReferences: 1
platformData:
- first:
Android: Android

42
Assets/TCPClient/Script/Source/DataEventModel.cs

@ -5,7 +5,6 @@ using QFramework; @@ -5,7 +5,6 @@ using QFramework;
using UnityEngine;
using UnityEngine.Events;
namespace TCPClientTools {
//任何通讯类围绕DataEventModel进行
public abstract class DataEventModel : AbstractModel, ICanSendCommand, ICanRegisterEvent
@ -13,7 +12,8 @@ namespace TCPClientTools { @@ -13,7 +12,8 @@ namespace TCPClientTools {
public IOCContainer mCommandContainer = new IOCContainer();
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)
{
@ -28,7 +28,7 @@ namespace TCPClientTools { @@ -28,7 +28,7 @@ namespace TCPClientTools {
/// <typeparam name="T">数据格式类型</typeparam>
public void onReceive<T>() where T : IResponse, new()
{
onDataRecived.AddListener(sendResponseCommand<T>);
onDataRecived.AddListener(excuteResponseCommand<T>);
}
/// <summary>
/// 关闭接收指定数据
@ -36,7 +36,7 @@ namespace TCPClientTools { @@ -36,7 +36,7 @@ namespace TCPClientTools {
/// <typeparam name="T">数据格式类型</typeparam>
public void offReceive<T>() where T : IResponse, new()
{
onDataRecived.RemoveListener(sendResponseCommand<T>);
onDataRecived.RemoveListener(excuteResponseCommand<T>);
}
/// <summary>
/// 发送数据
@ -94,15 +94,7 @@ namespace TCPClientTools { @@ -94,15 +94,7 @@ namespace TCPClientTools {
}
protected override void OnExecute()
{
if (this.GetUtility<TCPUtility>().isOpenTCP)
{
this.GetUtility<TCPUtility>().sendData(request.toJson());
}
else
{
Debug.LogWarning("请先开启TCP链接");
}
//throw new NotImplementedException();
this.SendEvent(new RequestMsgEvent(request));
}
public void setRequest(TRequest request)
{
@ -128,6 +120,22 @@ namespace TCPClientTools { @@ -128,6 +120,22 @@ namespace TCPClientTools {
{
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
#region AbstractClass
@ -171,10 +179,16 @@ namespace TCPClientTools { @@ -171,10 +179,16 @@ namespace TCPClientTools {
res = res_;
}
};
public struct RequestMsgEvent {
public IRequest req;
public RequestMsgEvent(IRequest req_) {
req = req_;
}
}
#endregion
[Serializable]
public class UnityStringEvent : UnityEvent<string>
{
}
}

22
Assets/TCPClient/Script/Source/TCPEventModel.cs

@ -1,21 +1,10 @@ @@ -1,21 +1,10 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Events;
using QFramework;
using System;
namespace TCPClientTools
{
public class TCPMangerArchitecture : Architecture<TCPMangerArchitecture>
{
protected override void Init()
{
this.RegisterUtility(new TCPUtility());
this.RegisterModel(new TCPEventModel());
}
}
//统筹管理TCP的命令池以及相关链接信息
public class TCPEventModel : DataEventModel, ICanSendCommand,ICanRegisterEvent
{
@ -30,6 +19,17 @@ namespace TCPClientTools @@ -30,6 +19,17 @@ namespace TCPClientTools
setTCPState(TCPLinkState.LinkTimeOut);
this.GetUtility<TCPUtility>().CloseTCPClient();
});
//注册重写发送事件
this.RegisterEvent<RequestMsgEvent>(e => {
if (this.GetUtility<TCPUtility>().isOpenTCP)
{
this.GetUtility<TCPUtility>().sendData(e.req.toJson());
}
else
{
Debug.LogWarning("请先开启TCP链接");
}
});
}
public void setTCPState(TCPLinkState state) {
this.tcpState = state;

8
Assets/TCPClient/Script/View/TCPClientView.cs

@ -6,6 +6,14 @@ using QFramework; @@ -6,6 +6,14 @@ using QFramework;
using TCPClientTools;
using System;
public class TCPMangerArchitecture : Architecture<TCPMangerArchitecture>
{
protected override void Init()
{
this.RegisterUtility(new TCPUtility());
this.RegisterModel(new TCPEventModel());
}
}
public class TCPClientView : MonoBehaviour,IController,ICanSendEvent
{
public UnityEvent onRecievedOpenDevice;

Loading…
Cancel
Save