This commit is contained in:
王志勋 2024-02-28 09:08:12 +08:00
commit 4e927017dc
4 changed files with 3 additions and 73 deletions

View File

@ -11,10 +11,6 @@ using Newtonsoft.Json.Linq;
public class LoadManage : MonoBehaviour public class LoadManage : MonoBehaviour
{ {
public static LoadManage Instance; public static LoadManage Instance;
/// <summary>
/// 房间域 "Room"
/// </summary>
[DisplayOnly] [DisplayOnly]
public string currentRoomArea; public string currentRoomArea;
[DisplayOnly] [DisplayOnly]
@ -52,9 +48,6 @@ public class LoadManage : MonoBehaviour
SceneManager.LoadScene("SampleScene"); SceneManager.LoadScene("SampleScene");
} }
/// <summary>
/// 创建与roomServer通信的客户端
/// </summary>
public void CreateRoomServerClient(string roomServerSubIP, string roomServerPubIP) public void CreateRoomServerClient(string roomServerSubIP, string roomServerPubIP)
{ {
if (RSclient == null) if (RSclient == null)
@ -78,10 +71,6 @@ public class LoadManage : MonoBehaviour
} }
} }
/// <summary>
/// RoomServermono
/// </summary>
/// <param name="stS"></param>
private void ReciveFromRoomServerInThread(st_Motions stS) private void ReciveFromRoomServerInThread(st_Motions stS)
{ {
RSclient._netMqListener.AddToMono(stS); RSclient._netMqListener.AddToMono(stS);

View File

@ -38,10 +38,6 @@ public class MyNetMQClient : MonoBehaviour
instance = this; instance = this;
} }
/// <summary>
/// 初始化Netmq
/// </summary>
/// <param name="reciveInMono">接收函数</param>
public void Init(string ServerSubIP,string ServerPubIP, NetMqListener.ReciveMessageInThread reciveInthread, NetMqListener.ReceiceMessageInMono reciveInMono,string typename) public void Init(string ServerSubIP,string ServerPubIP, NetMqListener.ReciveMessageInThread reciveInthread, NetMqListener.ReceiceMessageInMono reciveInMono,string typename)
{ {
SubIP = ServerSubIP; SubIP = ServerSubIP;
@ -104,15 +100,6 @@ public class st_Motions
public byte[] m_sOperaData; public byte[] m_sOperaData;
} }
/// <summary>
/// 演习状态
/// </summary>
public enum ProgramState
{
,
}
public class DisplayOnly : PropertyAttribute public class DisplayOnly : PropertyAttribute
{ {

View File

@ -8,40 +8,18 @@ using System.Text;
using System.Threading; using System.Threading;
using UnityEngine; using UnityEngine;
/// <summary>
/// 订阅模块
/// </summary>
public class NetMqListener public class NetMqListener
{ {
private string serverSubIP; private string serverSubIP;
private Thread _listenerWorker; private Thread _listenerWorker;
public bool _listenerCancelled; public bool _listenerCancelled;
/// <summary>
/// 自定义名称
/// </summary>
public string typeName; public string typeName;
/// <summary>
/// 处理函数委托
/// </summary>
/// <param name="st"></param>
public delegate void ReceiceMessageInMono(st_Motions st); public delegate void ReceiceMessageInMono(st_Motions st);
public delegate void ReciveMessageInThread(st_Motions st); public delegate void ReciveMessageInThread(st_Motions st);
/// <summary>
/// mono里处理消息
/// </summary>
private readonly ReceiceMessageInMono _reciveMessageInMono; private readonly ReceiceMessageInMono _reciveMessageInMono;
/// <summary>
/// 线程里处理模型
/// </summary>
private readonly ReciveMessageInThread _reciveMessageInThread; private readonly ReciveMessageInThread _reciveMessageInThread;
private readonly List<st_Motions> _messageReciveStmotion = new List<st_Motions>(); private readonly List<st_Motions> _messageReciveStmotion = new List<st_Motions>();
/// <summary>
/// 注册委托函数
/// </summary>
public NetMqListener(string subIP , ReciveMessageInThread _reciveInThread, ReceiceMessageInMono reciveInMono) public NetMqListener(string subIP , ReciveMessageInThread _reciveInThread, ReceiceMessageInMono reciveInMono)
{ {
serverSubIP = subIP; serverSubIP = subIP;
@ -49,9 +27,7 @@ public class NetMqListener
_reciveMessageInMono += reciveInMono; _reciveMessageInMono += reciveInMono;
StartListen(); StartListen();
} }
/// <summary>
/// 开始监听
/// </summary>
public void StartListen() public void StartListen()
{ {
_listenerCancelled = false; _listenerCancelled = false;
@ -59,9 +35,7 @@ public class NetMqListener
_listenerWorker.IsBackground = true; _listenerWorker.IsBackground = true;
_listenerWorker.Start(); _listenerWorker.Start();
} }
/// <summary>
/// 停止监听
/// </summary>
public void StopListen() public void StopListen()
{ {
_listenerCancelled = true; _listenerCancelled = true;
@ -69,9 +43,6 @@ public class NetMqListener
} }
public SubscriberSocket subSocket; public SubscriberSocket subSocket;
/// <summary>
/// 接收线程
/// </summary>
private void ByteListenerWork() private void ByteListenerWork()
{ {
AsyncIO.ForceDotNet.Force(); AsyncIO.ForceDotNet.Force();
@ -87,7 +58,6 @@ public class NetMqListener
//{ //{
List<byte[]> frameByte = new List<byte[]>(); List<byte[]> frameByte = new List<byte[]>();
if (!subSocket.TryReceiveMultipartBytes(ref frameByte)) continue; if (!subSocket.TryReceiveMultipartBytes(ref frameByte)) continue;
//UnityEngine.Debug.Log("线程收到一条");
st_Motions stS = new st_Motions(); st_Motions stS = new st_Motions();
string tmp = Encoding.UTF8.GetString(frameByte[0]); string tmp = Encoding.UTF8.GetString(frameByte[0]);
stS.m_iOperaType = BitConverter.ToInt32(frameByte[1], 0); stS.m_iOperaType = BitConverter.ToInt32(frameByte[1], 0);

View File

@ -16,15 +16,9 @@ public class NetMqPublisher
private Thread _listenerWorker; private Thread _listenerWorker;
public bool _listenerCancelled; public bool _listenerCancelled;
/// <summary>
/// 自定义名称
/// </summary>
public string typeName; public string typeName;
public delegate void MessageDelegateByte(st_Motions st); public delegate void MessageDelegateByte(st_Motions st);
private readonly MessageDelegateByte _messageDelegateByte; private readonly MessageDelegateByte _messageDelegateByte;
/// <summary>
/// 发送队列
/// </summary>
private readonly ConcurrentQueue<st_Motions> _messageQueueData = new ConcurrentQueue<st_Motions>(); private readonly ConcurrentQueue<st_Motions> _messageQueueData = new ConcurrentQueue<st_Motions>();
@ -33,10 +27,6 @@ public class NetMqPublisher
serverPubIP = pubIP; serverPubIP = pubIP;
StartListen(); StartListen();
} }
/// <summary>
/// 开始监听
/// </summary>
public void StartListen() public void StartListen()
{ {
_listenerCancelled = false; _listenerCancelled = false;
@ -44,17 +34,12 @@ public class NetMqPublisher
_listenerWorker.IsBackground = true; _listenerWorker.IsBackground = true;
_listenerWorker.Start(); _listenerWorker.Start();
} }
/// <summary>
/// 停止监听
/// </summary>
public void StopListen() public void StopListen()
{ {
_listenerCancelled = true; _listenerCancelled = true;
//_listenerWorker.Join(); //_listenerWorker.Join();
} }
/// <summary>
/// 发送线程
/// </summary>
private void ByteListenerWork() private void ByteListenerWork()
{ {
AsyncIO.ForceDotNet.Force(); AsyncIO.ForceDotNet.Force();
@ -78,7 +63,6 @@ public class NetMqPublisher
Array.Copy(BitConverter.GetBytes(sendData.m_iOperaType), 0, tmpbytes, 0, 4); Array.Copy(BitConverter.GetBytes(sendData.m_iOperaType), 0, tmpbytes, 0, 4);
Array.Copy(sendData.m_sOperaData, 0, tmpbytes, 4, sendData.m_sOperaData.Length); Array.Copy(sendData.m_sOperaData, 0, tmpbytes, 4, sendData.m_sOperaData.Length);
if (!_listenerCancelled && !publishSocket.SendMoreFrame(sendData.area).TrySendFrame(tmpbytes)) continue; if (!_listenerCancelled && !publishSocket.SendMoreFrame(sendData.area).TrySendFrame(tmpbytes)) continue;
UnityEngine.Debug.Log("发送一个消息:" + sendData.area + "," + sendData.m_iOperaType);
} }
} }
} }