/// <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[MAX_RECIEVE_SIZE]; int bufferSize = MAX_RECIEVE_SIZE; int dataSize; byte error; NetworkEventType recData = NetworkTransport.Receive(out recHostId, out connectionId, out channelId, recBuffer, bufferSize, out dataSize, out error); Array.Resize <byte> (ref recBuffer, dataSize); //resize to how much data was received switch (recData) { case NetworkEventType.ConnectEvent: break; case NetworkEventType.DataEvent: if (channelId == myReiliableChannelId) { HandleRPC(recBuffer); } else if (channelId == myReliableFramentedChannelId) { HandleBigRPC(recBuffer); } break; case NetworkEventType.DisconnectEvent: OnDisconnect(connectionId); break; default: //i.e. NetworkEventType.ConnectEvent, NetworkEventType.Nothing:\ break; } if (naviConnectionID > 0) //we are connected to a device { byte[] buffer = new byte[BUFFER_SIZE]; Stream stream = new MemoryStream(buffer); BinaryFormatter formatter = new BinaryFormatter(); PoseSerializerWithAcceleration pose = new PoseSerializerWithAcceleration(); pose.Fill(TransformManagerInterface.Instance.transform.position, TransformManagerInterface.Instance.transform.rotation, Input.acceleration); formatter.Serialize(stream, pose); NetworkTransport.Send(socketID, naviConnectionID, myUnreliableChannelId, buffer, BUFFER_SIZE, out error); //send full buffer foreach (Touch t in Input.touches) { buffer = new byte[BUFFER_SIZE]; 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, naviConnectionID, myReiliableChannelId, buffer, BUFFER_SIZE, out error); } SendKeyboardText(); if (Screen.orientation != prevOrientation) { SendCurrentSize(); prevOrientation = Screen.orientation; } } }
/// <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[MAX_RECIEVE_SIZE]; int bufferSize = MAX_RECIEVE_SIZE; int dataSize; byte error; NetworkEventType recData = NetworkTransport.Receive(out recHostId, out connectionId, out channelId, recBuffer, bufferSize, out dataSize, out error); Array.Resize<byte> (ref recBuffer, dataSize); //resize to how much data was received switch (recData) { case NetworkEventType.ConnectEvent: break; case NetworkEventType.DataEvent: if (channelId == myReiliableChannelId) { HandleRPC (recBuffer); } else if (channelId == myReliableFramentedChannelId) { HandleBigRPC (recBuffer); } break; case NetworkEventType.DisconnectEvent: OnDisconnect(connectionId); break; default: //i.e. NetworkEventType.ConnectEvent, NetworkEventType.Nothing:\ break; } if (naviConnectionID > 0) { //we are connected to a device byte[] buffer = new byte[BUFFER_SIZE]; Stream stream = new MemoryStream (buffer); BinaryFormatter formatter = new BinaryFormatter (); PoseSerializerWithAcceleration pose = new PoseSerializerWithAcceleration (); pose.Fill (TransformManagerInterface.Instance.transform.position, TransformManagerInterface.Instance.transform.rotation, Input.acceleration); formatter.Serialize (stream, pose); NetworkTransport.Send (socketID, naviConnectionID, myUnreliableChannelId, buffer, BUFFER_SIZE, out error); //send full buffer foreach (Touch t in Input.touches) { buffer = new byte[BUFFER_SIZE]; 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, naviConnectionID, myReiliableChannelId, buffer, BUFFER_SIZE, out error); } SendKeyboardText (); if (Screen.orientation != prevOrientation) { SendCurrentSize (); prevOrientation = Screen.orientation; } } }
/// <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); } } }