/// <summary> /// sends chunk of bytes for texture /// </summary> /// <returns></returns> public IEnumerator SendBytes() { yield return(null); if (currentIndex < byteImage.Length - 1) { yield return(new WaitForSeconds(.5f)); int remaining = byteImage.Length - (int)currentIndex; if (remaining < bufferSize) { bufferSize = (uint)remaining; } TextureMessage mb = new TextureMessage(); mb.texture = new byte[bufferSize]; System.Array.Copy(byteImage, currentIndex, mb.texture, 0, bufferSize); mb.index = currentIndex; myClient.Send(TextureMsgType.Texture, mb); currentIndex += bufferSize; miniindex++; } else { TextureMessage complete = new TextureMessage(); complete.index = (uint)byteImage.Length; myClient.Send(TextureMsgType.Complete, complete); } yield return(null); }
/// <summary> /// Once messased, starts loading image /// </summary> /// <param name="netMsg"></param> public void OnMessage(NetworkMessage netMsg) { TextureMessage msg = netMsg.ReadMessage <TextureMessage>(); savedData[msg.index] = msg.texture; Debug.Log("Packet Recieved, Asking for more"); TextureMessage empty = new TextureMessage(); NetworkServer.SendToAll(TextureMsgType.AnothaOne, empty); }
/// <summary> /// once all parts are sent, builds texture and shows it off on plane /// </summary> /// <param name="netMsg"></param> public void OnComplete(NetworkMessage netMsg) { TextureMessage msg = netMsg.ReadMessage <TextureMessage>(); Texture2D t = new Texture2D(2048, 2048, TextureFormat.RGB24, false); byte[] finalBytes = new byte[msg.index]; foreach (var chunk in savedData) { System.Array.Copy(chunk.Value, 0, finalBytes, chunk.Key, chunk.Value.Length); } Debug.Log("OnCompleteReached"); new Thread(() => { UnityMainThreadDispatcher.Instance().Enqueue(() => { t.LoadRawTextureData(finalBytes); t.Apply(); planeObj.GetComponent <MeshRenderer>().material.mainTexture = t; }); }).Start(); }