NetWorkLANManager.cs 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. using SC.XR.Unity;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using UnityEngine;
  5. public class NetWorkLANManager : SingletonMono<NetWorkLANManager>
  6. {
  7. public bool isServer = false;
  8. private client client;
  9. private server server;
  10. public Queue<string> queueMsg;
  11. public Queue<string> createDesMsg;
  12. private void Start()
  13. {
  14. client = this.GetComponent<client>();
  15. server = this.GetComponent<server>();
  16. queueMsg = new Queue<string>();
  17. createDesMsg = new Queue<string>();
  18. if (isServer)
  19. server.enabled = true;
  20. else
  21. client.enabled = true;
  22. }
  23. public void SendData(string msg)
  24. {
  25. if(isServer)
  26. {
  27. server.SendData();
  28. }
  29. else
  30. {
  31. client.SendData();
  32. }
  33. }
  34. public void RecMessage()
  35. {
  36. if(isServer)
  37. {
  38. if (server.queueRecMsg.Count < 1)
  39. return;
  40. // MessageData data = JsonConvert.DeserializeObject<MessageData>(server.queueRecMsg.Dequeue());
  41. // 同步管理器
  42. // SynchronizeManager.Instance.RecMessage(data);
  43. }
  44. else
  45. {
  46. if (client.queueRecMsg.Count < 1)
  47. return;
  48. // MessageData data = JsonConvert.DeserializeObject<MessageData>(client.queueRecMsg.Dequeue());
  49. // 同步管理器
  50. // SynchronizeManager.Instance.RecMessage(data);
  51. }
  52. }
  53. public void AddMsgData(bool isSyn, string msg)
  54. {
  55. if (isSyn)
  56. {
  57. if (queueMsg.Count > 10)
  58. {
  59. queueMsg.Dequeue();
  60. }
  61. queueMsg.Enqueue(msg);
  62. }
  63. else
  64. createDesMsg.Enqueue(msg);
  65. }
  66. }