using System.Collections; using System.Collections.Generic; using UnityEngine; using CScript.Utilities; using System; using CScript.Entity; using System.Text; using OpenCVForUnity.CoreModule; namespace CScript.Net { public class NetDistribute : Singleton { public Action drawMeshAction; public Action loadingPercentAction; public Action OnConnectAction; public Action OnDisconnectAction; public void OnConnect(bool isSuccessful, string reason) { NetGlobal.Instance.AddAction(() => { OnConnectAction(isSuccessful, reason); }); } public void OnDisconnect(int errcode, string reason) { NetGlobal.Instance.AddAction(() => { if (OnDisconnectAction != null) { OnDisconnectAction(errcode, reason); } }); } public void Parsing(NetMeshData netMeshData,Mat rgbMat,int totalByteCount,float decodeTime,int lostCount) { if (netMeshData != null) { NetGlobal.Instance.AddAction(() => { //NetMeshData meshData = JsonUtility.FromJson(Encoding.UTF8.GetString(meshDatas)); //NetMeshData meshData = AppUtil.ParseBinary(meshDatas); // drawMeshAction(new MeshData(netMeshData), i); drawMeshAction(netMeshData, rgbMat, totalByteCount, decodeTime, lostCount); //GC.Collect(); }); //NetGlobal.Instance.AddActionDream(() => //{ // drawMeshAction(netMeshData, rgbMat, totalByteCount, decodeTime, lostCount); //}); } } public void Parsing(byte[] byteData, int i) { if (byteData != null) { NetGlobal.Instance.AddAction(() => { Debug.LogError(byteData.Length); Debug.LogError(lz4.Decompress(byteData).Length); //NetMessage netMessage = AppUtil.UnpackMessage(byteData); //NetMeshData meshData = JsonUtility.FromJson(Encoding.UTF8.GetString(byteData)); //NetMeshData meshData = AppUtil.ParseBinary(lz4.Decompress(byteData)); //NetMeshData meshData = new NetMeshData(); //drawMeshAction(new MeshData(meshData), i); //drawMeshAction(null, i); }); } } public void ParsData(int curr, int max, MeshData meshData) { NetGlobal.Instance.AddAction(() => { Net.NetDistribute.Instance.loadingPercentAction(curr, max, meshData); }); } } }