/// <summary> /// Handles sending all data to the VR display, this includes pose data via the naviPoseconnection and touch data via the rpcConnection /// It also handles receiving any data from the VR display. Currently, it just listens for which connection should send which type of data /// </summary> void Update() { int recHostId; int connectionId; int channelId; byte[] recBuffer = new byte[1024]; int bufferSize = 1024; int dataSize; byte error; NetworkEventType recData = NetworkTransport.Receive(out recHostId, out connectionId, out channelId, recBuffer, bufferSize, out dataSize, out error); switch (recData) { case NetworkEventType.DataEvent: if (!naviPoseAssigned || !touchConnectionAssigned) { Stream stream = new MemoryStream(recBuffer); BinaryFormatter formatter = new BinaryFormatter(); string message = formatter.Deserialize(stream) as string; AssignID(connectionId, message); } break; case NetworkEventType.DisconnectEvent: OnDisconnect(connectionId); break; default: //i.e. NetworkEventType.ConnectEvent, NetworkEventType.Nothing:\ break; } if (naviPoseConnectionID > 0) { byte[] buffer = new byte[BUFFER_SIZE]; Stream stream = new MemoryStream(buffer); BinaryFormatter formatter = new BinaryFormatter(); PoseSerializer pose = new PoseSerializer(); pose.Fill(TransformManagerInterface.Instance.transform.position, TransformManagerInterface.Instance.transform.rotation); formatter.Serialize(stream, pose); NetworkTransport.Send(socketID, naviPoseConnectionID, myUnreliableChannelId, buffer, BUFFER_SIZE, out error); //send full buffer } if (touchConnectionID > 0) { BinaryFormatter formatter = new BinaryFormatter(); foreach (Touch t in Input.touches){ byte[] buffer = new byte[BUFFER_SIZE]; Stream stream = new MemoryStream(buffer); RPCSerializer rpc = new RPCSerializer(); rpc.methodName = TOUCH_METHOD_ID; rpc.args = new object[1]; TouchSerializer ts = new TouchSerializer(); ts.Fill(t); rpc.args[0] = ts; formatter.Serialize(stream, rpc); NetworkTransport.Send(socketID, touchConnectionID, myReiliableChannelId, buffer, BUFFER_SIZE, out error); } } }
/// <summary> /// Handles sending all data to the VR display, this includes pose data via the naviPoseconnection and touch data via the rpcConnection /// It also handles receiving any data from the VR display. Currently, it just listens for which connection should send which type of data /// </summary> void Update() { int recHostId; int connectionId; int channelId; byte[] recBuffer = new byte[1024]; int bufferSize = 1024; int dataSize; byte error; NetworkEventType recData = NetworkTransport.Receive(out recHostId, out connectionId, out channelId, recBuffer, bufferSize, out dataSize, out error); switch (recData) { case NetworkEventType.DataEvent: if (!naviPoseAssigned || !touchConnectionAssigned) { Stream stream = new MemoryStream(recBuffer); BinaryFormatter formatter = new BinaryFormatter(); string message = formatter.Deserialize(stream) as string; AssignID(connectionId, message); } break; case NetworkEventType.DisconnectEvent: OnDisconnect(connectionId); break; default: //i.e. NetworkEventType.ConnectEvent, NetworkEventType.Nothing:\ break; } if (naviPoseConnectionID > 0) { byte[] buffer = new byte[BUFFER_SIZE]; Stream stream = new MemoryStream(buffer); BinaryFormatter formatter = new BinaryFormatter(); PoseSerializer pose = new PoseSerializer(); pose.Fill(TransformManagerInterface.Instance.transform.position, TransformManagerInterface.Instance.transform.rotation); formatter.Serialize(stream, pose); NetworkTransport.Send(socketID, naviPoseConnectionID, myUnreliableChannelId, buffer, BUFFER_SIZE, out error); //send full buffer } if (touchConnectionID > 0) { BinaryFormatter formatter = new BinaryFormatter(); foreach (Touch t in Input.touches) { byte[] buffer = new byte[BUFFER_SIZE]; Stream stream = new MemoryStream(buffer); RPCSerializer rpc = new RPCSerializer(); rpc.methodName = TOUCH_METHOD_ID; rpc.args = new object[1]; TouchSerializer ts = new TouchSerializer(); ts.Fill(t); rpc.args[0] = ts; formatter.Serialize(stream, rpc); NetworkTransport.Send(socketID, touchConnectionID, myReiliableChannelId, buffer, BUFFER_SIZE, out error); } } }