IEnumerator LoadingBytes() { while (true) { UnityWebRequest req = UnityWebRequest.Get(ClusterInfoAssetsPath); yield return(req.SendWebRequest()); byte[] allData = req.downloadHandler.data; byte[] intBytes = new byte[4]; int position = 0; System.Array.Copy(allData, position, intBytes, 0, 4); int clusterCount = IOUtils.ByteToStruct <int>(intBytes); position += 4; System.Array.Copy(allData, position, intBytes, 0, 4); int vertexCount = IOUtils.ByteToStruct <int>(intBytes); position += 4; intBytes = null; byte[] clusterByte = new byte[clusterStride]; byte[] vertexByte = new byte[vertexStride]; for (int i = 0; i < clusterCount; i++) { System.Array.Copy(allData, position, clusterByte, 0, clusterStride); ClusterInfo clusterinfo = IOUtils.ByteToStruct <ClusterInfo>(clusterByte); clusterList[i] = clusterinfo; position += clusterStride; } for (int i = 0; i < vertexCount; i++) { System.Array.Copy(allData, position, vertexByte, 0, vertexStride); VertexInfo vertexinfo = IOUtils.ByteToStruct <VertexInfo>(vertexByte); vertexList[i] = vertexinfo; position += vertexStride; } clusterByte = null; vertexByte = null; req.Dispose(); bLoadFinish = true; yield break; } }
//private static bool isHaveMission() //{ // return bakeAssetsQueue.Count > 0; //} private static void ProcessBakeAssetLoadingQueue() { MCRSceneContext mcrScenecontext = null; lock (lockObj) { if (bakeAssetsQueue.Count > 0) { mcrScenecontext = bakeAssetsQueue.Dequeue(); } } if (null == mcrScenecontext || mcrScenecontext.bDestroyed) { return; } System.IO.BinaryReader reader = new System.IO.BinaryReader(System.IO.File.OpenRead(mcrScenecontext.ClusterInfoAssetsPath)); int clusterCount = reader.ReadInt32(); int vertexCount = reader.ReadInt32(); //读取cluster for (int i = 0; i < clusterCount; i++) { byte[] bytes = reader.ReadBytes(Marshal.SizeOf <ClusterInfo>()); ClusterInfo clusterinfo = IOUtils.ByteToStruct <ClusterInfo>(bytes); if (mcrScenecontext.bDestroyed) { reader.Close(); return; } mcrScenecontext.clusterList[i] = clusterinfo; } //读取顶点 for (int i = 0; i < vertexCount; i++) { byte[] bytes = reader.ReadBytes(Marshal.SizeOf <VertexInfo>()); VertexInfo vertexinfo = IOUtils.ByteToStruct <VertexInfo>(bytes); if (mcrScenecontext.bDestroyed) { reader.Close(); return; } mcrScenecontext.vertexList[i] = vertexinfo; } if (mcrScenecontext.bDestroyed) { reader.Close(); return; } mcrScenecontext.bLoadFinish = true; reader.Close(); }