NetDistribute.cs 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using CScript.Utilities;
  5. using System;
  6. using CScript.Entity;
  7. using System.Text;
  8. using OpenCVForUnity.CoreModule;
  9. namespace CScript.Net
  10. {
  11. public class NetDistribute : Singleton<NetDistribute>
  12. {
  13. public Action<NetMeshData,Mat,int,float,int> drawMeshAction;
  14. public Action<int, int, MeshData> loadingPercentAction;
  15. public Action<bool, string> OnConnectAction;
  16. public Action<int,string> OnDisconnectAction;
  17. public void OnConnect(bool isSuccessful, string reason)
  18. {
  19. NetGlobal.Instance.AddAction(() =>
  20. {
  21. OnConnectAction(isSuccessful, reason);
  22. });
  23. }
  24. public void OnDisconnect(int errcode, string reason)
  25. {
  26. NetGlobal.Instance.AddAction(() =>
  27. {
  28. if (OnDisconnectAction != null)
  29. {
  30. OnDisconnectAction(errcode, reason);
  31. }
  32. });
  33. }
  34. public void Parsing(NetMeshData netMeshData,Mat rgbMat,int totalByteCount,float decodeTime,int lostCount)
  35. {
  36. if (netMeshData != null)
  37. {
  38. NetGlobal.Instance.AddAction(() =>
  39. {
  40. //NetMeshData meshData = JsonUtility.FromJson<NetMeshData>(Encoding.UTF8.GetString(meshDatas));
  41. //NetMeshData meshData = AppUtil.ParseBinary(meshDatas);
  42. // drawMeshAction(new MeshData(netMeshData), i);
  43. drawMeshAction(netMeshData, rgbMat, totalByteCount, decodeTime, lostCount);
  44. //GC.Collect();
  45. });
  46. //NetGlobal.Instance.AddActionDream(() =>
  47. //{
  48. // drawMeshAction(netMeshData, rgbMat, totalByteCount, decodeTime, lostCount);
  49. //});
  50. }
  51. }
  52. public void Parsing(byte[] byteData, int i)
  53. {
  54. if (byteData != null)
  55. {
  56. NetGlobal.Instance.AddAction(() =>
  57. {
  58. Debug.LogError(byteData.Length);
  59. Debug.LogError(lz4.Decompress(byteData).Length);
  60. //NetMessage netMessage = AppUtil.UnpackMessage(byteData);
  61. //NetMeshData meshData = JsonUtility.FromJson<NetMeshData>(Encoding.UTF8.GetString(byteData));
  62. //NetMeshData meshData = AppUtil.ParseBinary(lz4.Decompress(byteData));
  63. //NetMeshData meshData = new NetMeshData();
  64. //drawMeshAction(new MeshData(meshData), i);
  65. //drawMeshAction(null, i);
  66. });
  67. }
  68. }
  69. public void ParsData(int curr, int max, MeshData meshData)
  70. {
  71. NetGlobal.Instance.AddAction(() =>
  72. {
  73. Net.NetDistribute.Instance.loadingPercentAction(curr, max, meshData);
  74. });
  75. }
  76. }
  77. }