1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889 |
- using BeinLab.Util;
- using Newtonsoft.Json;
- 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;
- TimerMgr.Instance.CreateTimer(() => { RecMessage(); }, 0.1f, -1);
- }
- 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);
- }
- }
|