Browse Source

更新文档,新增相关TCPClient方法接口

master
DESKTOP-B25GA9E\W35 2 years ago
parent
commit
c27250123c
  1. 0
      Assets/DataClass.meta
  2. 0
      Assets/DataClass/BluetoothGateway.cs
  3. 0
      Assets/DataClass/BluetoothGateway.cs.meta
  4. 333
      Assets/MsgTransmitTools/Example/Scenes/TCPLinkExample.unity
  5. 64
      Assets/MsgTransmitTools/Example/Script/TCPClientExample.cs
  6. 11
      Assets/MsgTransmitTools/Example/Script/TCPClientExample.cs.meta
  7. 4
      Assets/MsgTransmitTools/ExtendLinkModel/TCPClient/Prefeb/TCPClientInstance.prefab
  8. 0
      Assets/MsgTransmitTools/ExtendLinkModel/TCPClient/Prefeb/TCPClientInstance.prefab.meta
  9. 59
      Assets/MsgTransmitTools/ExtendLinkModel/TCPClient/Script/TCPClientView.cs
  10. 11
      Assets/MsgTransmitTools/ExtendLinkModel/UDPClient/UDPClientView.cs
  11. 23
      Assets/MsgTransmitTools/src/DataEventModel.cs
  12. 115
      README.md
  13. BIN
      UserManual/ReadMe_01.JPG
  14. BIN
      UserManual/ReadMe_02.JPG
  15. BIN
      UserManual/ReadMe_03.JPG

0
Assets/MsgTransmitTools/DataClass.meta → Assets/DataClass.meta

0
Assets/MsgTransmitTools/DataClass/BluetoothGateway.cs → Assets/DataClass/BluetoothGateway.cs

0
Assets/MsgTransmitTools/DataClass/BluetoothGateway.cs.meta → Assets/DataClass/BluetoothGateway.cs.meta

333
Assets/MsgTransmitTools/Example/Scenes/TCPLinkExample.unity

@ -121,6 +121,151 @@ NavMeshSettings: @@ -121,6 +121,151 @@ NavMeshSettings:
debug:
m_Flags: 0
m_NavMeshData: {fileID: 0}
--- !u!1001 &97579247
PrefabInstance:
m_ObjectHideFlags: 0
serializedVersion: 2
m_Modification:
m_TransformParent: {fileID: 1205360335}
m_Modifications:
- target: {fileID: 1515527918816451327, guid: 27bf485803eb75f4598b17afdfac3cfa,
type: 3}
propertyPath: m_AnchorMax.x
value: 0
objectReference: {fileID: 0}
- target: {fileID: 1515527918816451327, guid: 27bf485803eb75f4598b17afdfac3cfa,
type: 3}
propertyPath: m_AnchorMax.y
value: 0
objectReference: {fileID: 0}
- target: {fileID: 1515527919082889016, guid: 27bf485803eb75f4598b17afdfac3cfa,
type: 3}
propertyPath: m_Name
value: TCPClientInstance
objectReference: {fileID: 0}
- target: {fileID: 1515527919082889017, guid: 27bf485803eb75f4598b17afdfac3cfa,
type: 3}
propertyPath: m_Pivot.x
value: 0.5
objectReference: {fileID: 0}
- target: {fileID: 1515527919082889017, guid: 27bf485803eb75f4598b17afdfac3cfa,
type: 3}
propertyPath: m_Pivot.y
value: 0.5
objectReference: {fileID: 0}
- target: {fileID: 1515527919082889017, guid: 27bf485803eb75f4598b17afdfac3cfa,
type: 3}
propertyPath: m_RootOrder
value: 0
objectReference: {fileID: 0}
- target: {fileID: 1515527919082889017, guid: 27bf485803eb75f4598b17afdfac3cfa,
type: 3}
propertyPath: m_AnchorMax.x
value: 0.5
objectReference: {fileID: 0}
- target: {fileID: 1515527919082889017, guid: 27bf485803eb75f4598b17afdfac3cfa,
type: 3}
propertyPath: m_AnchorMax.y
value: 0.5
objectReference: {fileID: 0}
- target: {fileID: 1515527919082889017, guid: 27bf485803eb75f4598b17afdfac3cfa,
type: 3}
propertyPath: m_AnchorMin.x
value: 0.5
objectReference: {fileID: 0}
- target: {fileID: 1515527919082889017, guid: 27bf485803eb75f4598b17afdfac3cfa,
type: 3}
propertyPath: m_AnchorMin.y
value: 0.5
objectReference: {fileID: 0}
- target: {fileID: 1515527919082889017, guid: 27bf485803eb75f4598b17afdfac3cfa,
type: 3}
propertyPath: m_SizeDelta.x
value: 1280
objectReference: {fileID: 0}
- target: {fileID: 1515527919082889017, guid: 27bf485803eb75f4598b17afdfac3cfa,
type: 3}
propertyPath: m_SizeDelta.y
value: 720
objectReference: {fileID: 0}
- target: {fileID: 1515527919082889017, guid: 27bf485803eb75f4598b17afdfac3cfa,
type: 3}
propertyPath: m_LocalPosition.x
value: 0
objectReference: {fileID: 0}
- target: {fileID: 1515527919082889017, guid: 27bf485803eb75f4598b17afdfac3cfa,
type: 3}
propertyPath: m_LocalPosition.y
value: 0
objectReference: {fileID: 0}
- target: {fileID: 1515527919082889017, guid: 27bf485803eb75f4598b17afdfac3cfa,
type: 3}
propertyPath: m_LocalPosition.z
value: 0
objectReference: {fileID: 0}
- target: {fileID: 1515527919082889017, guid: 27bf485803eb75f4598b17afdfac3cfa,
type: 3}
propertyPath: m_LocalRotation.w
value: 1
objectReference: {fileID: 0}
- target: {fileID: 1515527919082889017, guid: 27bf485803eb75f4598b17afdfac3cfa,
type: 3}
propertyPath: m_LocalRotation.x
value: 0
objectReference: {fileID: 0}
- target: {fileID: 1515527919082889017, guid: 27bf485803eb75f4598b17afdfac3cfa,
type: 3}
propertyPath: m_LocalRotation.y
value: 0
objectReference: {fileID: 0}
- target: {fileID: 1515527919082889017, guid: 27bf485803eb75f4598b17afdfac3cfa,
type: 3}
propertyPath: m_LocalRotation.z
value: 0
objectReference: {fileID: 0}
- target: {fileID: 1515527919082889017, guid: 27bf485803eb75f4598b17afdfac3cfa,
type: 3}
propertyPath: m_AnchoredPosition.x
value: 0
objectReference: {fileID: 0}
- target: {fileID: 1515527919082889017, guid: 27bf485803eb75f4598b17afdfac3cfa,
type: 3}
propertyPath: m_AnchoredPosition.y
value: 0
objectReference: {fileID: 0}
- target: {fileID: 1515527919082889017, guid: 27bf485803eb75f4598b17afdfac3cfa,
type: 3}
propertyPath: m_LocalEulerAnglesHint.x
value: 0
objectReference: {fileID: 0}
- target: {fileID: 1515527919082889017, guid: 27bf485803eb75f4598b17afdfac3cfa,
type: 3}
propertyPath: m_LocalEulerAnglesHint.y
value: 0
objectReference: {fileID: 0}
- target: {fileID: 1515527919082889017, guid: 27bf485803eb75f4598b17afdfac3cfa,
type: 3}
propertyPath: m_LocalEulerAnglesHint.z
value: 0
objectReference: {fileID: 0}
- target: {fileID: 1515527919516098611, guid: 27bf485803eb75f4598b17afdfac3cfa,
type: 3}
propertyPath: m_AnchorMax.x
value: 0
objectReference: {fileID: 0}
- target: {fileID: 1515527919516098611, guid: 27bf485803eb75f4598b17afdfac3cfa,
type: 3}
propertyPath: m_AnchorMax.y
value: 0
objectReference: {fileID: 0}
m_RemovedComponents: []
m_SourcePrefab: {fileID: 100100000, guid: 27bf485803eb75f4598b17afdfac3cfa, type: 3}
--- !u!224 &97579248 stripped
RectTransform:
m_CorrespondingSourceObject: {fileID: 1515527919082889017, guid: 27bf485803eb75f4598b17afdfac3cfa,
type: 3}
m_PrefabInstance: {fileID: 97579247}
m_PrefabAsset: {fileID: 0}
--- !u!1 &540781454
GameObject:
m_ObjectHideFlags: 0
@ -421,7 +566,7 @@ RectTransform: @@ -421,7 +566,7 @@ RectTransform:
m_LocalPosition: {x: 0, y: 0, z: 0}
m_LocalScale: {x: 0, y: 0, z: 0}
m_Children:
- {fileID: 1287989911}
- {fileID: 97579248}
- {fileID: 540781455}
m_Father: {fileID: 0}
m_RootOrder: 2
@ -431,12 +576,49 @@ RectTransform: @@ -431,12 +576,49 @@ RectTransform:
m_AnchoredPosition: {x: 0, y: 0}
m_SizeDelta: {x: 0, y: 0}
m_Pivot: {x: 0, y: 0}
--- !u!224 &1287989911 stripped
RectTransform:
m_CorrespondingSourceObject: {fileID: 1515527919082889017, guid: 27bf485803eb75f4598b17afdfac3cfa,
type: 3}
m_PrefabInstance: {fileID: 1515527918222734766}
--- !u!1 &1807137817
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 1807137818}
- component: {fileID: 1807137819}
m_Layer: 0
m_Name: ExampleScript
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!4 &1807137818
Transform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1807137817}
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 0, y: 3, z: 0}
m_LocalScale: {x: 1, y: 1, z: 1}
m_Children: []
m_Father: {fileID: 0}
m_RootOrder: 4
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!114 &1807137819
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1807137817}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: e7f61d2a9b60fd442b9f4fce73155c70, type: 3}
m_Name:
m_EditorClassIdentifier:
--- !u!1 &2006740781
GameObject:
m_ObjectHideFlags: 0
@ -503,142 +685,3 @@ Transform: @@ -503,142 +685,3 @@ Transform:
m_Father: {fileID: 0}
m_RootOrder: 3
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!1001 &1515527918222734766
PrefabInstance:
m_ObjectHideFlags: 0
serializedVersion: 2
m_Modification:
m_TransformParent: {fileID: 1205360335}
m_Modifications:
- target: {fileID: 1515527918816451327, guid: 27bf485803eb75f4598b17afdfac3cfa,
type: 3}
propertyPath: m_AnchorMax.x
value: 0
objectReference: {fileID: 0}
- target: {fileID: 1515527918816451327, guid: 27bf485803eb75f4598b17afdfac3cfa,
type: 3}
propertyPath: m_AnchorMax.y
value: 0
objectReference: {fileID: 0}
- target: {fileID: 1515527919082889016, guid: 27bf485803eb75f4598b17afdfac3cfa,
type: 3}
propertyPath: m_Name
value: TCPPrinter
objectReference: {fileID: 0}
- target: {fileID: 1515527919082889017, guid: 27bf485803eb75f4598b17afdfac3cfa,
type: 3}
propertyPath: m_Pivot.x
value: 0.5
objectReference: {fileID: 0}
- target: {fileID: 1515527919082889017, guid: 27bf485803eb75f4598b17afdfac3cfa,
type: 3}
propertyPath: m_Pivot.y
value: 0.5
objectReference: {fileID: 0}
- target: {fileID: 1515527919082889017, guid: 27bf485803eb75f4598b17afdfac3cfa,
type: 3}
propertyPath: m_RootOrder
value: 0
objectReference: {fileID: 0}
- target: {fileID: 1515527919082889017, guid: 27bf485803eb75f4598b17afdfac3cfa,
type: 3}
propertyPath: m_AnchorMax.x
value: 0.5
objectReference: {fileID: 0}
- target: {fileID: 1515527919082889017, guid: 27bf485803eb75f4598b17afdfac3cfa,
type: 3}
propertyPath: m_AnchorMax.y
value: 0.5
objectReference: {fileID: 0}
- target: {fileID: 1515527919082889017, guid: 27bf485803eb75f4598b17afdfac3cfa,
type: 3}
propertyPath: m_AnchorMin.x
value: 0.5
objectReference: {fileID: 0}
- target: {fileID: 1515527919082889017, guid: 27bf485803eb75f4598b17afdfac3cfa,
type: 3}
propertyPath: m_AnchorMin.y
value: 0.5
objectReference: {fileID: 0}
- target: {fileID: 1515527919082889017, guid: 27bf485803eb75f4598b17afdfac3cfa,
type: 3}
propertyPath: m_SizeDelta.x
value: 1280
objectReference: {fileID: 0}
- target: {fileID: 1515527919082889017, guid: 27bf485803eb75f4598b17afdfac3cfa,
type: 3}
propertyPath: m_SizeDelta.y
value: 720
objectReference: {fileID: 0}
- target: {fileID: 1515527919082889017, guid: 27bf485803eb75f4598b17afdfac3cfa,
type: 3}
propertyPath: m_LocalPosition.x
value: 0
objectReference: {fileID: 0}
- target: {fileID: 1515527919082889017, guid: 27bf485803eb75f4598b17afdfac3cfa,
type: 3}
propertyPath: m_LocalPosition.y
value: 0
objectReference: {fileID: 0}
- target: {fileID: 1515527919082889017, guid: 27bf485803eb75f4598b17afdfac3cfa,
type: 3}
propertyPath: m_LocalPosition.z
value: 0
objectReference: {fileID: 0}
- target: {fileID: 1515527919082889017, guid: 27bf485803eb75f4598b17afdfac3cfa,
type: 3}
propertyPath: m_LocalRotation.w
value: 1
objectReference: {fileID: 0}
- target: {fileID: 1515527919082889017, guid: 27bf485803eb75f4598b17afdfac3cfa,
type: 3}
propertyPath: m_LocalRotation.x
value: -0
objectReference: {fileID: 0}
- target: {fileID: 1515527919082889017, guid: 27bf485803eb75f4598b17afdfac3cfa,
type: 3}
propertyPath: m_LocalRotation.y
value: -0
objectReference: {fileID: 0}
- target: {fileID: 1515527919082889017, guid: 27bf485803eb75f4598b17afdfac3cfa,
type: 3}
propertyPath: m_LocalRotation.z
value: -0
objectReference: {fileID: 0}
- target: {fileID: 1515527919082889017, guid: 27bf485803eb75f4598b17afdfac3cfa,
type: 3}
propertyPath: m_AnchoredPosition.x
value: 0
objectReference: {fileID: 0}
- target: {fileID: 1515527919082889017, guid: 27bf485803eb75f4598b17afdfac3cfa,
type: 3}
propertyPath: m_AnchoredPosition.y
value: 0
objectReference: {fileID: 0}
- target: {fileID: 1515527919082889017, guid: 27bf485803eb75f4598b17afdfac3cfa,
type: 3}
propertyPath: m_LocalEulerAnglesHint.x
value: 0
objectReference: {fileID: 0}
- target: {fileID: 1515527919082889017, guid: 27bf485803eb75f4598b17afdfac3cfa,
type: 3}
propertyPath: m_LocalEulerAnglesHint.y
value: 0
objectReference: {fileID: 0}
- target: {fileID: 1515527919082889017, guid: 27bf485803eb75f4598b17afdfac3cfa,
type: 3}
propertyPath: m_LocalEulerAnglesHint.z
value: 0
objectReference: {fileID: 0}
- target: {fileID: 1515527919516098611, guid: 27bf485803eb75f4598b17afdfac3cfa,
type: 3}
propertyPath: m_AnchorMax.x
value: 0
objectReference: {fileID: 0}
- target: {fileID: 1515527919516098611, guid: 27bf485803eb75f4598b17afdfac3cfa,
type: 3}
propertyPath: m_AnchorMax.y
value: 0
objectReference: {fileID: 0}
m_RemovedComponents: []
m_SourcePrefab: {fileID: 100100000, guid: 27bf485803eb75f4598b17afdfac3cfa, type: 3}

64
Assets/MsgTransmitTools/Example/Script/TCPClientExample.cs

@ -0,0 +1,64 @@ @@ -0,0 +1,64 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using JXSoft;
public class TCPClientExample : MonoBehaviour,ITCPClient
{
// Start is called before the first frame update
void Start()
{
//注册接收到数据类型事件监听
this.RegisterMessageEvent<YourResponse>(e => {
Debug.Log("TestGetMsg:"+e.msg);
//应答
this.sendRequest(new StringRequest("Received!"));
//取消接收该数据
this.offReceive<YourResponse>();
});
//开启开数据类型接收
this.onReceive<YourResponse>();
}
}
#region ResReqData
public class YourResponse : AbstractJsonResponse
{
public string msg;
public YourResponse()
{
this.msg = "";
}
}
public struct YourNumberFilterResponse : IResponse
{
public string code;
private int codeNum;
private string exceptionMsg;
public string toProtocolData()
{
return "你想要打印的调试信息,无需打印返回空字符串即可";
}
public bool trySetData(string protocolData)
{
bool isNumber = int.TryParse(code, out codeNum);
if (!isNumber)
{
exceptionMsg = "这不是数字";
}
return isNumber;
}
public string getException()
{
return exceptionMsg;
}
}
public class YourRequest:IRequest {
public string toProtocolData()
{
return "要发的请求内容";
}
}
#endregion

11
Assets/MsgTransmitTools/Example/Script/TCPClientExample.cs.meta

@ -0,0 +1,11 @@ @@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: e7f61d2a9b60fd442b9f4fce73155c70
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

4
Assets/MsgTransmitTools/ExtendLinkModel/TCPClient/Prefeb/TCPPrinter.prefab → Assets/MsgTransmitTools/ExtendLinkModel/TCPClient/Prefeb/TCPClientInstance.prefab

@ -786,7 +786,7 @@ GameObject: @@ -786,7 +786,7 @@ GameObject:
- component: {fileID: 1515527919082889017}
- component: {fileID: 1515527919082889015}
m_Layer: 5
m_Name: TCPPrinter
m_Name: TCPClientInstance
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
@ -825,6 +825,8 @@ MonoBehaviour: @@ -825,6 +825,8 @@ MonoBehaviour:
m_Script: {fileID: 11500000, guid: 558c5409545c2634d92e208d8852c9ea, type: 3}
m_Name:
m_EditorClassIdentifier:
tcpAddress: 127.0.0.1
tcpPort: 20000
tcpMsgContent: {fileID: 1515527919033040842}
tcpMsgItem: {fileID: 1515527918183730452}
onRecievedOpenDevice:

0
Assets/MsgTransmitTools/ExtendLinkModel/TCPClient/Prefeb/TCPPrinter.prefab.meta → Assets/MsgTransmitTools/ExtendLinkModel/TCPClient/Prefeb/TCPClientInstance.prefab.meta

59
Assets/MsgTransmitTools/ExtendLinkModel/TCPClient/Script/TCPClientView.cs

@ -4,6 +4,7 @@ using UnityEngine.Events; @@ -4,6 +4,7 @@ using UnityEngine.Events;
using QFrameworkCP;
using System.Threading;
using UnityEngine.UI;
using System;
namespace JXSoft {
public class TCPMangerArchitecture : Architecture<TCPMangerArchitecture>
@ -16,6 +17,8 @@ namespace JXSoft { @@ -16,6 +17,8 @@ namespace JXSoft {
}
public class TCPClientView : MonoBehaviour,IController,ICanRegisterEvent
{
public string tcpAddress;
public int tcpPort;
//Printer&MsgGetter
private TCPClientUtility tcpUtil;
public Transform tcpMsgContent;
@ -27,8 +30,7 @@ namespace JXSoft { @@ -27,8 +30,7 @@ namespace JXSoft {
public UnityEvent onServerConnected;
public UnityEvent onTCPReLink;
private string tcpAddress;
private int tcpPort;
private int deviceId;
// Start is called before the first frame update
void Awake()
@ -39,8 +41,6 @@ namespace JXSoft { @@ -39,8 +41,6 @@ namespace JXSoft {
}
public void initTCPService() {
tcpAddress = "127.0.0.1";
tcpPort = 20000;
deviceId = 1;
this.RegisterLinkStateEvent((int)TCPLinkState.Linking, () =>
@ -51,8 +51,6 @@ namespace JXSoft { @@ -51,8 +51,6 @@ namespace JXSoft {
this.RegisterLinkStateEvent((int)TCPLinkState.LinkSucess, () =>
{
Debug.Log("TCPÁ´½Ó³É¹¦");
this.GetModel<TCPClientModel>().onReceive<LinkSuccessResponse>();
this.GetModel<TCPClientModel>().sendRequest(new LinkTCPRequest(deviceId));
onTCPLinkSuccess.Invoke();
});
this.RegisterLinkStateEvent((int)TCPLinkState.LinkFaild, () =>
@ -61,14 +59,6 @@ namespace JXSoft { @@ -61,14 +59,6 @@ namespace JXSoft {
onTCPLinkFaild.Invoke();
});
this.RegisterMessageEvent<LinkSuccessResponse>(e =>
{
Debug.Log("Link Server success");
this.GetModel<TCPClientModel>().offReceive<LinkSuccessResponse>();
onServerConnected.Invoke();
});
this.GetModel<TCPClientModel>().setLinkState((int)TCPLinkState.NoIp);
this.GetModel<TCPClientModel>().setIP(tcpAddress, tcpPort);
}
@ -112,28 +102,33 @@ namespace JXSoft { @@ -112,28 +102,33 @@ namespace JXSoft {
return TCPMangerArchitecture.Interface;
}
}
public class LinkSuccessResponse : AbstractResponse
public interface ITCPClient
{
public string code;
public string data;
public string msg;
public LinkSuccessResponse() {
this.code = "";
this.data = "";
this.msg = "";
}
}
public class LinkTCPRequest :IRequest{
public string id;
public int type;
public LinkTCPRequest(int id) {
this.id = id.ToString();
this.type = 1;
}
public static class TCPClientExtention
{
public static IUnRegister RegisterMessageEvent<TResponse>(this ITCPClient self, Action<TResponse> onEvent) where TResponse : IResponse
{
return TCPMangerArchitecture.Interface.RegisterEvent<ResponseMsgEvent>(e => {
if (e.res.GetType() == typeof(TResponse))
{
onEvent.Invoke((TResponse)e.res);
}
});
}
public static void onReceive<TResponse>(this ITCPClient self) where TResponse : IResponse, new()
{
TCPMangerArchitecture.Interface.GetModel<TCPClientModel>().onReceive<TResponse>();
}
public static void offReceive<TResponse>(this ITCPClient self) where TResponse : IResponse, new()
{
TCPMangerArchitecture.Interface.GetModel<TCPClientModel>().offReceive<TResponse>();
}
public string toProtocolData()
public static void sendRequest<TRequest>(this ITCPClient self ,TRequest request) where TRequest : IRequest, new()
{
return JsonUtility.ToJson(this);
TCPMangerArchitecture.Interface.GetModel<TCPClientModel>().sendRequest(request);
}
}
}

11
Assets/MsgTransmitTools/ExtendLinkModel/UDPClient/UDPClientView.cs

@ -47,7 +47,6 @@ namespace JXSoft { @@ -47,7 +47,6 @@ namespace JXSoft {
if (e.state == UDPLinkState.LinkSucess)
{
Debug.Log("UDP链接成功");
this.GetModel<UDPClientModel>().onReceive<LinkSuccessResponse>();
this.GetModel<UDPClientModel>().sendRequest(new LinkUDPRequest(deviceId));
onUDPLinkSuccess.Invoke();
}
@ -58,16 +57,6 @@ namespace JXSoft { @@ -58,16 +57,6 @@ namespace JXSoft {
}
});
GetArchitecture().RegisterEvent<ResponseMsgEvent>(e =>
{
if (e.res.GetType() == typeof(LinkSuccessResponse))
{
Debug.Log("Link Server success");
this.GetModel<UDPClientModel>().offReceive<LinkSuccessResponse>();
onServerConnected.Invoke();
}
});
this.GetModel<UDPClientModel>().setLinkState((int)UDPLinkState.NoIp);
this.GetModel<UDPClientModel>().setIP(UDPAddress, UDPPort);
}

23
Assets/MsgTransmitTools/src/DataEventModel.cs

@ -178,7 +178,7 @@ namespace JXSoft { @@ -178,7 +178,7 @@ namespace JXSoft {
/// 使用抽象类时,必须满足可序列化
/// </summary>
[Serializable]
public abstract class AbstractResponse : IResponse
public abstract class AbstractJsonResponse : IResponse
{
private string exceptionMsg;
public virtual string toProtocolData()
@ -203,6 +203,27 @@ namespace JXSoft { @@ -203,6 +203,27 @@ namespace JXSoft {
return exceptionMsg;
}
}
public abstract class AbstractJsonRequest : IRequest{
public string toProtocolData()
{
return JsonUtility.ToJson(this, true);
}
}
public class StringRequest : IRequest
{
public string requestStr;
public StringRequest() {
requestStr = "No message";
}
public StringRequest(string str) {
requestStr = str;
}
public string toProtocolData()
{
return requestStr;
}
}
#endregion
#region Extention

115
README.md

@ -10,10 +10,119 @@ JXsoft是由github作者jkpete编写的一款基于Qframework实现的Unity信 @@ -10,10 +10,119 @@ JXsoft是由github作者jkpete编写的一款基于Qframework实现的Unity信
QFramework链接:[GitHub - liangxiegame/QFramework: Unity3D System Design Architecture](https://github.com/liangxiegame/QFramework)
最新日志:增加了HttpServer,可以使用Unity搭建Http服务器了。
近更新:增加了HttpServer,可以使用Unity搭建Http服务器了。
# 消息转换工具MsgTransmitTools
目前支持的通讯方式一览,后续会增加更多的通讯方式
# 消息转换工具MsgTransmitTools
| Client | Server |
| ------ | ------ |
| TCP | TCP |
| UDP | UDP |
| | Http |
对应的接口命名为 I + Name + Type (e.g. ITCPClient,ITCPServer)
# 使用方法
## 1.定义响应&请求消息结构
使用模板创建消息结构(好处是省去具体消息筛选规则,也可以覆写对应的接口方法来重构消息筛选规则)
```cs
//此时筛选{"msg":"message test"}格式的json信息
public class YourResponse: AbstractJsonResponse
{
public string msg;
public YourResponse() {
this.msg = "";
}
}
```
使用接口创建消息结构(可以自行定义消息筛选规则,可以用类或者结构体,下面例子筛选数字信息)
```cs
public struct YourNumberFilterResponse : IResponse
{
public string code;
private int codeNum;
private string exceptionMsg;
public string toProtocolData()
{
return "你想要打印的调试信息,无需打印返回空字符串即可";
}
public bool trySetData(string protocolData)
{
bool isNumber = int.TryParse(code, out codeNum);
if (!isNumber)
{
exceptionMsg = "这不是数字";
}
return isNumber;
}
public string getException()
{
return exceptionMsg;
}
}
```
请求消息结构更为简单
```cs
public class YourRequest:IRequest {
public string toProtocolData()
{
return "要发的请求内容";
}
}
```
## 2.注册消息事件,以TCPClient为例
引用包JXSoft,实现接口ITCPClient
```cs
using UnityEngine;
using JXSoft;
public class TCPClientExample : MonoBehaviour,ITCPClient
{
// Start is called before the first frame update
void Start()
{
//注册接收到数据类型事件监听
this.RegisterMessageEvent<YourResponse>(e => {
Debug.Log("TestGetMsg:"+e.msg);
//发送数据
this.sendRequest(new StringRequest("Received!"));
//取消接收该数据
this.offReceive<YourResponse>();
});
//开启开数据类型接收
this.onReceive<YourResponse>();
}
}
```
## 3.配置场景
把MsgTransmitTools -> ExtendLinkModel-> TCPClient -> Preferb目录下的TCPClientInstance拖拽至场景中的Canvas下面
![](./UserManual/ReadMe_01.JPG)
填写好要链接的IP地址,端口号,程序运行前服务必须是开启状态
![](./UserManual/ReadMe_02.JPG)
运行前先使用SSCOM,或者其他TCP调试助手,开启为127.0.0.1:20000的本机TCP服务
发送{"msg":"Ok"}即可
![](./UserManual/ReadMe_03.JPG)
## 使用方法以TCPClient为例
此时第二次发送同类数据已经不会再返回收到信息也不会打印对应数据,因为我们在第一次收到的时候已经关闭了该类数据的接收。如果想继续响应该数据的接收,仅需重新调用一次onReceive<对应的数据类型>即可

BIN
UserManual/ReadMe_01.JPG

Binary file not shown.

After

Width:  |  Height:  |  Size: 10 KiB

BIN
UserManual/ReadMe_02.JPG

Binary file not shown.

After

Width:  |  Height:  |  Size: 13 KiB

BIN
UserManual/ReadMe_03.JPG

Binary file not shown.

After

Width:  |  Height:  |  Size: 137 KiB

Loading…
Cancel
Save