// Update is called once per frame. void Update() { // If we have a connected client, presumably the client wants to send some meshes. if (ClientConnected) { // Get the clients stream. NetworkStream stream = networkClient.GetStream(); // Make sure there is data in the stream. if (stream.DataAvailable) { // The first 4 bytes will be the size of the data containing the mesh(es). int datasize = ReadInt(stream); // Allocate a buffer to hold the data. byte[] dataBuffer = new byte[datasize]; // Read the data. // The data can come in chunks. int readsize = 0; while (readsize != datasize) { readsize += stream.Read(dataBuffer, readsize, datasize - readsize); } if (readsize != datasize) { Debug.Log("reading mesh failed: " + readsize + " != " + datasize); } // Pass the data to the mesh serializer. List <Mesh> meshes = new List <Mesh>(SimpleMeshSerializer.Deserialize(dataBuffer)); // For each mesh, create a GameObject to render it. for (int index = 0; index < meshes.Count; index++) { GameObject surface = AddSurfaceObject(meshes[index], string.Format("Beamed-{0}", surfaceObjects.Count), transform); surface.transform.parent = SpatialMappingManager.Instance.transform; if (SpatialMappingManager.Instance.DrawVisualMeshes == false) { surface.GetComponent <MeshRenderer>().enabled = false; } if (SpatialMappingManager.Instance.CastShadows == false) { surface.GetComponent <MeshRenderer>().shadowCastingMode = UnityEngine.Rendering.ShadowCastingMode.Off; } } // Finally disconnect. ClientConnected = false; networkClient.Close(); // And wait for the next connection. AsyncCallback callback = new AsyncCallback(OnClientConnect); networkListener.BeginAcceptTcpClient(callback, this); } } }