public void gotMessage(object sender, WebSocketSharp.MessageEventArgs msg) { if (msg.Type == WebSocketSharp.Opcode.Binary) { lock (updateLock) { updateMsg.ClearVrmsg(); updateMsg.MergeFrom(new Google.Protobuf.CodedInputStream(msg.RawData)); Google.Protobuf.VRCom.Update.VrmsgOneofCase msgType = updateMsg.VrmsgCase; switch (msgType) { case Google.Protobuf.VRCom.Update.VrmsgOneofCase.Mocap: mocapMsg = updateMsg; break; case Google.Protobuf.VRCom.Update.VrmsgOneofCase.Hydra: hydraMsg = updateMsg; break; case Google.Protobuf.VRCom.Update.VrmsgOneofCase.Wiimote: wiimoteMsgs.Enqueue(updateMsg.Clone()); break; default: Debug.Log("Received an unknown or empty message"); break; } } } else { //jmsg = JsonUtility.FromJson (msg.Data); Debug.Log(msg.Data); } }
void handleHydra(Google.Protobuf.VRCom.Update msg) { if (msg.Hydra.CtrlNum == 0) { newrot.Set(msg.Hydra.Rot.X, msg.Hydra.Rot.Y, -msg.Hydra.Rot.Z, -msg.Hydra.Rot.W); newpos.Set(msg.Hydra.Pos.X / 1000, msg.Hydra.Pos.Y / 1000, -msg.Hydra.Pos.Z / 1000); } }
void handleWii(Google.Protobuf.VRCom.Update msg) { if ((msg.Wiimote.ButtonsPressed & ControllerButtons.WIIMOTE_BUTTON_DOWN) != 0) { wordmakerScript.makeword("no", 0.1f, wordpos, transform.rotation, wordclips ["no"]); } else if ((msg.Wiimote.ButtonsPressed & ControllerButtons.WIIMOTE_BUTTON_UP) != 0) { wordmakerScript.makeword("yes", 0.1f, wordpos, transform.rotation, wordclips ["yes"]); } }
void handleWiimote(Google.Protobuf.VRCom.Update msg) { Google.Protobuf.VRCom.Wiimote wmsg = msg.Wiimote; Debug.Log(wmsg.ToString()); if (wmsg.ButtonsPressed != 0) { Debug.Log("a button was pressed " + wmsg.ButtonsPressed); } if (wmsg.ButtonsReleased != 0) { Debug.Log("a button was released " + wmsg.ButtonsReleased); } }
// Use this for initialization IEnumerator Start() { yield return(StartCoroutine(ConnectWebsocket())); w.Send("{ \"username\":\"" + SystemInfo.deviceUniqueIdentifier + "\"}"); while (socketError == null) { lock (updateLock) { if (mocapMsg != null) { if (OnMocapMsg != null) { OnMocapMsg(mocapMsg); } Google.Protobuf.Collections.MapField <string, Google.Protobuf.VRCom.MocapSubject> subjects = mocapMsg.Mocap.Subjects; foreach (KeyValuePair <string, MocapHandler> pair in mocapHandlers) { if (subjects.ContainsKey(pair.Key)) { mocapHandlers [pair.Key] (subjects [pair.Key]); } } mocapMsg = null; } if (hydraMsg != null) { if (OnHydraMsg != null) { OnHydraMsg(hydraMsg); } hydraMsg = null; } while (wiimoteMsgs.Count != 0) { currMsg = wiimoteMsgs.Dequeue(); if (OnWiimoteMsg != null) { OnWiimoteMsg(currMsg); } } } yield return(0); } Debug.LogError("Error: " + socketError); w.Close(); }
void handleHydra(Google.Protobuf.VRCom.Update msg) { if (msg.Hydra.CtrlNum == 0) { wandpos.Set(msg.Hydra.Pos.X / 1000, msg.Hydra.Pos.Y / 1000, msg.Hydra.Pos.Z / 1000); wandrot.Set(msg.Hydra.Rot.X, msg.Hydra.Rot.Y, -msg.Hydra.Rot.Z, -msg.Hydra.Rot.W); transform.localPosition = wandpos; transform.localRotation = wandrot; if ((msg.Hydra.Buttons & ControllerButtons.SIXENSE_BUTTON_1) != 0) { if (!makeword1) { makeword1 = true; } } else if (makeword1) { makeword1 = false; wordpos = transform.position + transform.forward * .30f; wordmakerScript.makeword("yes", 0.1f, wordpos, transform.rotation, wordclips["yes"]); } } }