123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687 |
- using SC.XR.Unity;
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- public class NetWorkLANManager : SingletonMono<NetWorkLANManager>
- {
- public bool isServer = false;
- private client client;
- private server server;
- public Queue<string> queueMsg;
- public Queue<string> createDesMsg;
- private void Start()
- {
- client = this.GetComponent<client>();
- server = this.GetComponent<server>();
- queueMsg = new Queue<string>();
- createDesMsg = new Queue<string>();
- if (isServer)
- server.enabled = true;
- else
- client.enabled = true;
- }
- public void SendData(string msg)
- {
- if(isServer)
- {
- server.SendData();
- }
- else
- {
- client.SendData();
- }
-
- }
- public void RecMessage()
- {
- if(isServer)
- {
- if (server.queueRecMsg.Count < 1)
- return;
- // MessageData data = JsonConvert.DeserializeObject<MessageData>(server.queueRecMsg.Dequeue());
- // 同步管理器
- // SynchronizeManager.Instance.RecMessage(data);
- }
- else
- {
- if (client.queueRecMsg.Count < 1)
- return;
- // MessageData data = JsonConvert.DeserializeObject<MessageData>(client.queueRecMsg.Dequeue());
- // 同步管理器
- // SynchronizeManager.Instance.RecMessage(data);
- }
-
- }
- public void AddMsgData(bool isSyn, string msg)
- {
- if (isSyn)
- {
- if (queueMsg.Count > 10)
- {
- queueMsg.Dequeue();
-
- }
- queueMsg.Enqueue(msg);
- }
- else
- createDesMsg.Enqueue(msg);
- }
- }
|