private IEnumerator SendTextureToClient_Internal(int ConnectionId, short TextureId, Texture2D Texture) { Debug.Log("Sending texture to client " + ConnectionId.ToString()); // Send metadata TextureMetaMsg metaMsg = new TextureMetaMsg(); metaMsg.TextureId = TextureId; metaMsg.Width = Texture.width; metaMsg.Height = Texture.height; metaMsg.ChunkSz = ChunkSize; metaMsg.Format = Texture.format; metaMsg.MipCount = Texture.mipmapCount; NetworkServer.SendToClient(ConnectionId, JigsawNetworkMsg.TextureMeta, metaMsg); // Send bytes, one chunk at a time byte[] rawData = Texture.GetRawTextureData(); int lastChunk = (rawData.Length / ChunkSize); for (int i = 0; i < lastChunk; ++i) { TextureChunkMsg msg = new TextureChunkMsg(); msg.TextureId = TextureId; msg.StartByte = i * ChunkSize; msg.NumBytes = ChunkSize; msg.TotalBytes = rawData.Length; msg.Bytes = new byte[ChunkSize]; for (int j = 0; j < ChunkSize; ++j) { msg.Bytes[j] = rawData[msg.StartByte + j]; } NetworkServer.SendToClient(ConnectionId, JigsawNetworkMsg.TextureChunk, msg); Debug.Log("Server sent chunk " + i.ToString() + "/" + lastChunk.ToString()); yield return(null); } if (lastChunk * ChunkSize < rawData.Length) { TextureChunkMsg finalMsg = new TextureChunkMsg(); finalMsg.TextureId = TextureId; finalMsg.StartByte = lastChunk * ChunkSize; finalMsg.NumBytes = rawData.Length - finalMsg.StartByte; finalMsg.TotalBytes = rawData.Length; finalMsg.Bytes = new byte[finalMsg.NumBytes]; for (int j = 0; j < finalMsg.NumBytes; ++j) { finalMsg.Bytes[j] = rawData[finalMsg.StartByte + j]; } NetworkServer.SendToClient(ConnectionId, JigsawNetworkMsg.TextureChunk, finalMsg); Debug.Log("Server sent chunk " + lastChunk.ToString() + "/" + lastChunk.ToString()); } }
public void OnClientReceiveTexMeta(NetworkMessage Msg) { TextureMetaMsg metaMsg = Msg.ReadMessage <TextureMetaMsg>(); TextureMetadata texData; if (ClientTextureBuffers.ContainsKey(metaMsg.TextureId)) { texData = ClientTextureBuffers[metaMsg.TextureId]; } else { texData = new TextureMetadata(); } texData.Width = metaMsg.Width; texData.Height = metaMsg.Height; texData.ChunkSz = metaMsg.ChunkSz; texData.Format = metaMsg.Format; texData.MipCount = metaMsg.MipCount; Debug.Log("Client received metadata for texture " + metaMsg.TextureId.ToString()); ClientTextureBuffers[metaMsg.TextureId] = texData; }