void ScaleZ(string furniture) { Vector3 minValues = Vector3.zero; Vector3 maxValues = Vector3.zero; float zBack = transform.localScale.z; float zFront = transform.localScale.z; MinMaxValues(furniture, out minValues, out maxValues); NunchuckData data = DataWii(); if (data.stick[1] - 130 > 10) { zBack += (maxValues.z - minValues.z) / steps; } else if (data.stick[1] - 130 < -10) { zFront -= (maxValues.z - minValues.z) / steps; } if (zBack != transform.localScale.z) { zBack = Mathf.Clamp(zBack, minValues.z, maxValues.z); transform.localScale = new Vector3(transform.localScale.x, transform.localScale.y, zBack); } else if (zFront != transform.localScale.z) { zFront = Mathf.Clamp(zFront, minValues.z, maxValues.z); transform.localScale = new Vector3(transform.localScale.x, transform.localScale.y, zFront); } }
/// <summary> /// Controls for the Wiimotes and Nunchuck /// </summary> void UseWiimote() { do { wiimoteData = wiimote.ReadWiimoteData(); //Movements with the nunuchuck if (wiimote.current_ext == ExtensionController.NUNCHUCK) { nunchuck = wiimote.Nunchuck; float[] stick = nunchuck.GetStick01(); speed = 2.0f; //Right & left if (Math.Abs(stick[0]) > 0.8f) { controller.Move(myTransform.TransformDirection(Vector3.right * Time.deltaTime * speed)); } else if (Math.Abs(stick[0]) < 0.2f) { controller.Move(myTransform.TransformDirection(Vector3.left * Time.deltaTime * speed)); } //Top & Bottom if (Math.Abs(stick[1]) > 0.8f) { controller.Move(myTransform.TransformDirection(Vector3.forward * Time.deltaTime * speed)); } else if (Math.Abs(stick[1]) < 0.2f) { controller.Move(myTransform.TransformDirection(Vector3.back * Time.deltaTime * speed)); } } } while (wiimoteData > 0); }
void ScaleY(string furniture) { Vector3 minValues = Vector3.zero; Vector3 maxValues = Vector3.zero; float yUp = transform.localScale.y; float yDown = transform.localScale.y; MinMaxValues(furniture, out minValues, out maxValues); NunchuckData data = DataWii(); Vector3 acc = GetAccelVector(); if (acc.y >= -0.2f) { yUp += (maxValues.y - minValues.y) / steps; } else if (acc.y <= -0.7f) { yDown -= (maxValues.y - minValues.y) / steps; } if (yUp != transform.localScale.y) { yUp = Mathf.Clamp(yUp, minValues.y, maxValues.y); transform.localScale = new Vector3(transform.localScale.x, yUp, transform.localScale.z); } else if (yDown != transform.localScale.y) { yDown = Mathf.Clamp(yDown, minValues.y, maxValues.y); transform.localScale = new Vector3(transform.localScale.x, yDown, transform.localScale.z); } }
// --------------------------------------------------------------------------------------------- #region Nunchuck /// <summary> /// Returns a value from -1.0f to 1.0f, representing the joystick's position in the given axis /// </summary> /// <param name="axis">The axis the check for, either "Horizontal" or "Vertical"</param> public float GetNunchuckAxis(string axis) { if (wiimote.current_ext != ExtensionController.NUNCHUCK) { throw new System.Exception("Nunchuck not detected"); } NunchuckData data = wiimote.Nunchuck; int value = 0; switch (axis) { case "Horizontal": value = data.stick[0]; // General range is 35-228 break; case "Vertical": value = data.stick[1]; // General range is 27-220 break; default: throw new System.ArgumentException("Invalid argument: " + axis + ", expected \"Horizontal\" or \"Vertical\""); } // Check if input mode not setup if (value == 0) { wiimote.SendDataReportMode(InputDataType.REPORT_BUTTONS_ACCEL_EXT16); wiimote.SetupIRCamera(IRDataType.BASIC); return(0f); } // Center is around 128 if (value > 112 && value < 144) { return(0f); } // Set horizontal to similar range as vertical if (axis == "Horizontal") { value -= 8; } // Check for upper/lower bounds if (value > 200) { return(1f); } else if (value < 47) { return(-1f); } // Return normalized value float normalizedValue = (value - 128f) / 128f; return(Mathf.Clamp(normalizedValue, -1f, 1f)); }
// Update is called once per frame void Update() { controlWii = GetComponent <CollisionHands>().controlWii; if (collision.TouchingFurniture() && collision.isGrabbed && controlWii != null) { int ret; do { ret = controlWii.ReadWiimoteData(); if (ret > 0 && controlWii.current_ext == ExtensionController.MOTIONPLUS) { Vector3 offset = new Vector3(-controlWii.MotionPlus.PitchSpeed, controlWii.MotionPlus.YawSpeed, controlWii.MotionPlus.RollSpeed) / 95f; // Divide by 95Hz (average updates per second from wiimote) //wmpOffset += offset; //model.rot.Rotate(offset, Space.Self); } } while (ret > 0); NunchuckData data = controlWii.Nunchuck; if (data.c && !data.z) { transform.parent = GameObject.FindGameObjectWithTag("vista").transform; Vector3 acc = GetAccelVector(); transform.position = new Vector3(transform.parent.position.x, transform.parent.position.y, transform.parent.position.z); transform.localScale = scale.actualScale / 3; if (acc.y >= -0.2f) { transform.Rotate(new Vector3(0, 0, 10)); } else if (acc.y <= -0.7f) { transform.Rotate(new Vector3(0, 0, -10)); } else if (data.stick[0] - 125 > 10) { transform.Rotate(0, 10, 0); } else if (data.stick[0] - 125 < -10) { transform.Rotate(0, -10, 0); } else if (data.stick[1] - 130 > 10) { transform.Rotate(10, 0, 0); } else if (data.stick[1] - 130 < -10) { transform.Rotate(-10, 0, 0); } else { transform.localScale = scale.actualScale; } } } }
void MainMenu() { WiimoteManager.FindWiimotes(); controlWii = WiimoteManager.Wiimotes[0]; //controlWii = transform.parent.GetComponent<MoveCamera>().controlWii; controlWii.SetupIRCamera(IRDataType.BASIC); if (controlWii != null) { int ret; do { ret = controlWii.ReadWiimoteData(); if (ret > 0 && controlWii.current_ext == ExtensionController.MOTIONPLUS) { Vector3 offset = new Vector3(-controlWii.MotionPlus.PitchSpeed, controlWii.MotionPlus.YawSpeed, controlWii.MotionPlus.RollSpeed) / 95f; // Divide by 95Hz (average updates per second from wiimote) //wmpOffset += offset; //model.rot.Rotate(offset, Space.Self); } } while (ret > 0); NunchuckData data = controlWii.Nunchuck; if (data.c && data.z && created == false) { menu.transform.parent.GetComponent <MoveCamera>().enabled = false; CreateMenu(); created = true; } else if (data.z && !data.c && created == true) { DestroyMenu(); Destroy(GameObject.FindGameObjectWithTag("selection")); menu.transform.parent.GetComponent <MoveCamera>().enabled = true; created = false; controlWii = null; } if (created == true) { int i = 0; while (i < opts.Length) { if (opts[i].tag == "active") { activeOpt = opts[i]; } i++; } } } }
// Update is called once per frame void Update() { controlWii = GetComponent <CollisionHands>().controlWii; data = DataWii(); if (collisionHands.TouchingFurniture() && controlWii != null && data.z) { switch (transform.tag) { case "chair": ScaleX("chair"); ScaleY("chair"); ScaleZ("chair"); break; case "sofa": ScaleX("sofa"); ScaleY("sofa"); ScaleZ("sofa"); break; case "bookcase": ScaleX("bookcase"); ScaleY("bookcase"); ScaleZ("bookcase"); break; case "vase": ScaleX("vase"); ScaleY("vase"); ScaleZ("vase"); break; case "tv": ScaleX("tv"); ScaleY("tv"); ScaleZ("tv"); break; case "bed": ScaleX("bed"); ScaleY("bed"); ScaleZ("bed"); break; case "table": ScaleX("table"); ScaleY("table"); ScaleZ("table"); break; } } }
void SelectFurniture() { NunchuckData data = controlWii.Nunchuck; int nameFurniture; if (menu.transform.childCount > 0) { int.TryParse(GameObject.FindGameObjectWithTag("active").name, out nameFurniture); if (data.c && !data.z) { GameObject furniture = null; switch (nameFurniture) { case 0: furniture = Resources.Load <GameObject>("Chair") as GameObject; break; case 1: furniture = Resources.Load <GameObject>("Vase_1") as GameObject; break; case 2: furniture = Resources.Load <GameObject>("Sofa") as GameObject; break; case 3: furniture = Resources.Load <GameObject>("Table") as GameObject; break; case 4: furniture = Resources.Load <GameObject>("TV") as GameObject; break; case 5: furniture = Resources.Load <GameObject>("Bed") as GameObject; break; case 6: furniture = Resources.Load <GameObject>("BookCase_1") as GameObject; break; } GameObject vista = GameObject.FindGameObjectWithTag("vista"); Instantiate(furniture, new Vector3(vista.transform.position.x, vista.transform.position.y - 0.5f, vista.transform.position.z + 0.5f), transform.rotation * Quaternion.Euler(270f, 0f, 0f)); actualScale = furniture.transform.localScale; menu.transform.parent.GetComponent <MoveCamera>().enabled = true; Destroy(GameObject.FindGameObjectWithTag("selection")); DestroyMenu(); controlWii = null; } } }
void OnGUI() { GUILayout.Label("Wiimote Found: " + WiimoteManager.HasWiimote()); if (GUILayout.Button("Find Wiimote")) { WiimoteManager.FindWiimotes(); } if (GUILayout.Button("Cleanup")) { WiimoteManager.Cleanup(wiimote); WiimoteStatus.WiiEnabled = false; wiimote = null; } if (wiimote == null) { return; } if (GUILayout.Button("Basic", GUILayout.Width(100))) { nunnormalizer = 123f; wiimote.SetupIRCamera(IRDataType.BASIC); } if (wiimote != null && wiimote.current_ext != ExtensionController.NONE) { WiimoteStatus.WiiEnabled = true; GUIStyle bold = new GUIStyle(GUI.skin.button); bold.fontStyle = FontStyle.Bold; if (wiimote.current_ext == ExtensionController.NUNCHUCK) { GUILayout.Label("Wiimote X:" + pointer0); GUILayout.Label("Wiimote Y:" + pointer1); GUILayout.Label("Nunchuck:", bold); NunchuckData data = wiimote.Nunchuck; GUILayout.Label("Stick X: " + data.stick[0] + ", Stick Y " + data.stick[1]); WiimoteStatus.nunchuckX = data.stick[0] - nunnormalizer; WiimoteStatus.nunchuckY = data.stick[1]; WiimoteStatus.buttonZ = data.z; GUILayout.Label("C: " + data.c); GUILayout.Label("Z: " + data.z); } } }
void FixedUpdate() { if (wiimote == null && setupCompleted) { return; } //Speler bewegings controls float speed = 0; if (isWalking) { speed = walkSpeed; } if (isRunning) { speed = runSpeed; } if (wiimote != null && wiimote.current_ext != ExtensionController.NONE) { if (wiimote.current_ext == ExtensionController.NUNCHUCK) { nunchuckData = wiimote.Nunchuck; Vector3 desiredDirection = playerCam.transform.right * NunchuckMovement(nunchuckData.stick[0]) + playerCam.transform.forward * NunchuckMovement(nunchuckData.stick[1]); moveDirection.x = desiredDirection.x * speed; moveDirection.z = desiredDirection.z * speed; if (characterController.isGrounded) { moveDirection.y = -downForce; if (jump) { moveDirection.y = jumpSpeed; jump = false; isJumping = true; } } else { moveDirection += Physics.gravity * 2f * Time.fixedDeltaTime; } characterController.Move(moveDirection * Time.fixedDeltaTime); } } }
private NunchuckData DataWii() { int ret; do { ret = controlWii.ReadWiimoteData(); if (ret > 0 && controlWii.current_ext == ExtensionController.MOTIONPLUS) { Vector3 offset = new Vector3(-controlWii.MotionPlus.PitchSpeed, controlWii.MotionPlus.YawSpeed, controlWii.MotionPlus.RollSpeed) / 95f; // Divide by 95Hz (average updates per second from wiimote) //wmpOffset += offset; //model.rot.Rotate(offset, Space.Self); } } while (ret > 0); NunchuckData data = controlWii.Nunchuck; return(data); }
private bool GetNunchuckButton(Button button) { if (wiimote.current_ext != ExtensionController.NUNCHUCK) { //Debug.LogError("Nunchuck not detected"); return(false); } NunchuckData data = wiimote.Nunchuck; if (button == Button.Z) { return(data.z); } else if (button == Button.C) { return(data.c); } else { return(false); } }
// Update is called once per frame void Update() { int ret; do { ret = controlWii.ReadWiimoteData(); } while (ret > 0); controlWii.SetupIRCamera(IRDataType.BASIC); if (controlWii.current_ext == ExtensionController.NUNCHUCK) { NunchuckData data = controlWii.Nunchuck; if (NunDir != 0) { if (data.stick[1] - 130 < -90 && !data.c && !data.z) { NunAct = -1; } else if (data.stick[1] - 130 > 90 && !data.c && !data.z) { NunAct = 1; } else { NunAct = 0; } } NunDir = 0; if (data.stick[1] - 130 < -90 && !data.c && !data.z) { NunDir = -1; } else if (data.stick[1] - 130 > 90 && !data.c && !data.z) { NunDir = 1; } if (NunAct == 0) { if (NunDir == -1 && !data.c && !data.z && index < cantOpts) { index++; actualButton.tag = "Untagged"; actualButton.GetComponent <Image>().color = Color.white; //=== if (index == 4) { index = cantOpts - 1; } actualButton = botones.transform.GetChild(index).GetComponent <Button>(); actualButton.tag = "select"; actualButton.GetComponent <Image>().color = Color.gray; actualButton.OnSelect(null); } else if (NunDir == 1 && !data.c && !data.z && index >= 0) { index--; actualButton.tag = "Untagged"; actualButton.GetComponent <Image>().color = Color.white; //=== if (index == -1) { index = 0; } actualButton = botones.transform.GetChild(index).GetComponent <Button>(); actualButton.tag = "select"; actualButton.GetComponent <Image>().color = Color.gray; actualButton.OnSelect(null); } } if (data.c) { switch (index) { case 0: rooms.GetComponent <RoomsMgr>().LoadRoom("Habitacion3"); break; case 1: rooms.GetComponent <RoomsMgr>().LoadRoom("Habitacion2"); break; case 2: rooms.GetComponent <RoomsMgr>().LoadRoom("Habitacion1"); break; case 3: rooms.GetComponent <RoomsMgr>().ExitSimulator(); break; } } } }
void OnGUI() { GUI.Box(new Rect(0, 0, 320, Screen.height), ""); GUILayout.BeginVertical(GUILayout.Width(300)); GUILayout.Label("Wiimote Found: " + WiimoteManager.HasWiimote()); if (GUILayout.Button("Find Wiimote")) { WiimoteManager.FindWiimotes(); } if (GUILayout.Button("Cleanup")) { WiimoteManager.Cleanup(wiimote); wiimote = null; } if (wiimote == null) { return; } GUILayout.Label("Extension: " + wiimote.current_ext.ToString()); GUILayout.Label("LED Test:"); GUILayout.BeginHorizontal(); for (int x = 0; x < 4; x++) { if (GUILayout.Button("" + x, GUILayout.Width(300 / 4))) { wiimote.SendPlayerLED(x == 0, x == 1, x == 2, x == 3); } } GUILayout.EndHorizontal(); GUILayout.Label("Set Report:"); GUILayout.BeginHorizontal(); if (GUILayout.Button("But/Acc", GUILayout.Width(300 / 4))) { wiimote.SendDataReportMode(InputDataType.REPORT_BUTTONS_ACCEL); } if (GUILayout.Button("But/Ext8", GUILayout.Width(300 / 4))) { wiimote.SendDataReportMode(InputDataType.REPORT_BUTTONS_EXT8); } if (GUILayout.Button("B/A/Ext16", GUILayout.Width(300 / 4))) { wiimote.SendDataReportMode(InputDataType.REPORT_BUTTONS_ACCEL_EXT16); } if (GUILayout.Button("Ext21", GUILayout.Width(300 / 4))) { wiimote.SendDataReportMode(InputDataType.REPORT_EXT21); } GUILayout.EndHorizontal(); if (GUILayout.Button("Request Status Report")) { wiimote.SendStatusInfoRequest(); } GUILayout.Label("IR Setup Sequence:"); GUILayout.BeginHorizontal(); if (GUILayout.Button("Basic", GUILayout.Width(100))) { wiimote.SetupIRCamera(IRDataType.BASIC); } if (GUILayout.Button("Extended", GUILayout.Width(100))) { wiimote.SetupIRCamera(IRDataType.EXTENDED); } if (GUILayout.Button("Full", GUILayout.Width(100))) { wiimote.SetupIRCamera(IRDataType.FULL); } GUILayout.EndHorizontal(); GUILayout.Label("WMP Attached: " + wiimote.wmp_attached); if (GUILayout.Button("Request Identify WMP")) { wiimote.RequestIdentifyWiiMotionPlus(); } if ((wiimote.wmp_attached || wiimote.Type == WiimoteType.PROCONTROLLER) && GUILayout.Button("Activate WMP")) { wiimote.ActivateWiiMotionPlus(); } if ((wiimote.current_ext == ExtensionController.MOTIONPLUS || wiimote.current_ext == ExtensionController.MOTIONPLUS_CLASSIC || wiimote.current_ext == ExtensionController.MOTIONPLUS_NUNCHUCK) && GUILayout.Button("Deactivate WMP")) { wiimote.DeactivateWiiMotionPlus(); } GUILayout.Label("Calibrate Accelerometer"); GUILayout.BeginHorizontal(); for (int x = 0; x < 3; x++) { AccelCalibrationStep step = (AccelCalibrationStep)x; if (GUILayout.Button(step.ToString(), GUILayout.Width(100))) { wiimote.Accel.CalibrateAccel(step); } } GUILayout.EndHorizontal(); if (GUILayout.Button("Print Calibration Data")) { StringBuilder str = new StringBuilder(); for (int x = 0; x < 3; x++) { for (int y = 0; y < 3; y++) { str.Append(wiimote.Accel.accel_calib[y, x]).Append(" "); } str.Append("\n"); } Debug.Log(str.ToString()); } if (wiimote != null && wiimote.current_ext != ExtensionController.NONE) { scrollPosition = GUILayout.BeginScrollView(scrollPosition); GUIStyle bold = new GUIStyle(GUI.skin.button); bold.fontStyle = FontStyle.Bold; if (wiimote.current_ext == ExtensionController.NUNCHUCK) { GUILayout.Label("Nunchuck:", bold); NunchuckData data = wiimote.Nunchuck; GUILayout.Label("Stick: " + data.stick[0] + ", " + data.stick[1]); GUILayout.Label("C: " + data.c); GUILayout.Label("Z: " + data.z); } else if (wiimote.current_ext == ExtensionController.CLASSIC) { GUILayout.Label("Classic Controller:", bold); ClassicControllerData data = wiimote.ClassicController; GUILayout.Label("Stick Left: " + data.lstick[0] + ", " + data.lstick[1]); GUILayout.Label("Stick Right: " + data.rstick[0] + ", " + data.rstick[1]); GUILayout.Label("Trigger Left: " + data.ltrigger_range); GUILayout.Label("Trigger Right: " + data.rtrigger_range); GUILayout.Label("Trigger Left Button: " + data.ltrigger_switch); GUILayout.Label("Trigger Right Button: " + data.rtrigger_switch); GUILayout.Label("A: " + data.a); GUILayout.Label("B: " + data.b); GUILayout.Label("X: " + data.x); GUILayout.Label("Y: " + data.y); GUILayout.Label("Plus: " + data.plus); GUILayout.Label("Minus: " + data.minus); GUILayout.Label("Home: " + data.home); GUILayout.Label("ZL: " + data.zl); GUILayout.Label("ZR: " + data.zr); GUILayout.Label("D-Up: " + data.dpad_up); GUILayout.Label("D-Down: " + data.dpad_down); GUILayout.Label("D-Left: " + data.dpad_left); GUILayout.Label("D-Right: " + data.dpad_right); } else if (wiimote.current_ext == ExtensionController.MOTIONPLUS) { GUILayout.Label("Wii Motion Plus:", bold); MotionPlusData data = wiimote.MotionPlus; GUILayout.Label("Pitch Speed: " + data.PitchSpeed); GUILayout.Label("Yaw Speed: " + data.YawSpeed); GUILayout.Label("Roll Speed: " + data.RollSpeed); GUILayout.Label("Pitch Slow: " + data.PitchSlow); GUILayout.Label("Yaw Slow: " + data.YawSlow); GUILayout.Label("Roll Slow: " + data.RollSlow); if (GUILayout.Button("Zero Out WMP")) { data.SetZeroValues(); model.rot.rotation = Quaternion.FromToRotation(model.rot.rotation * GetAccelVector(), Vector3.up) * model.rot.rotation; model.rot.rotation = Quaternion.FromToRotation(model.rot.forward, Vector3.forward) * model.rot.rotation; } if (GUILayout.Button("Reset Offset")) { wmpOffset = Vector3.zero; } GUILayout.Label("Offset: " + wmpOffset.ToString()); } else if (wiimote.current_ext == ExtensionController.WIIU_PRO) { GUILayout.Label("Wii U Pro Controller:", bold); WiiUProData data = wiimote.WiiUPro; GUILayout.Label("Stick Left: " + data.lstick[0] + ", " + data.lstick[1]); GUILayout.Label("Stick Right: " + data.rstick[0] + ", " + data.rstick[1]); GUILayout.Label("A: " + data.a); GUILayout.Label("B: " + data.b); GUILayout.Label("X: " + data.x); GUILayout.Label("Y: " + data.y); GUILayout.Label("D-Up: " + data.dpad_up); GUILayout.Label("D-Down: " + data.dpad_down); GUILayout.Label("D-Left: " + data.dpad_left); GUILayout.Label("D-Right: " + data.dpad_right); GUILayout.Label("Plus: " + data.plus); GUILayout.Label("Minus: " + data.minus); GUILayout.Label("Home: " + data.home); GUILayout.Label("L: " + data.l); GUILayout.Label("R: " + data.r); GUILayout.Label("ZL: " + data.zl); GUILayout.Label("ZR: " + data.zr); } GUILayout.EndScrollView(); } else { scrollPosition = Vector2.zero; } GUILayout.EndVertical(); }
void InputControl() { if (controlWii != null) { int ret; do { ret = controlWii.ReadWiimoteData(); if (ret > 0 && controlWii.current_ext == ExtensionController.MOTIONPLUS) { Vector3 offset = new Vector3(-controlWii.MotionPlus.PitchSpeed, controlWii.MotionPlus.YawSpeed, controlWii.MotionPlus.RollSpeed) / 95f; // Divide by 95Hz (average updates per second from wiimote) //wmpOffset += offset; //model.rot.Rotate(offset, Space.Self); } } while (ret > 0); NunchuckData data = controlWii.Nunchuck; //Debug.Log("Stick: " + data.stick[0] + ", " + data.stick[1]); if (NunDir != 0) { if (data.stick[0] - 125 < -90 && !data.c && !data.z) { NunAct = -1; } else if (data.stick[0] - 125 > 90 && !data.c && !data.z) { NunAct = 1; } else { NunAct = 0; } } NunDir = 0; if (data.stick[0] - 125 < -90 && !data.c && !data.z) { NunDir = -1; } else if (data.stick[0] - 125 > 90 && !data.c && !data.z) { NunDir = 1; } if (NunAct == 0) { if (NunDir == -1 && !data.c && !data.z) { RightOption(ref activeOpt); } else if (NunDir == 1 && !data.c && !data.z) { LeftOption(ref activeOpt); } if (data.c) { SelectFurniture(); } } } }
/// <summary> /// Gets the IR values of the current detected Wiimote /// </summary> void Update() { if (!WiimoteManager.HasWiimote()) { WiimoteManager.FindWiimotes(); return; } else { wiimote = WiimoteManager.Wiimotes[0]; wiimote.SetupIRCamera(IRDataType.BASIC); wiimote.SendPlayerLED(true, false, false, false); dataNunchuk = wiimote.Nunchuck; } int ret; do { ret = wiimote.ReadWiimoteData(); } while (ret > 0); ir2 = wiimote.Ir.GetPointingPosition(); if (wiimote.Button.b) { if (isB) { isBDown = false; } else { isBDown = true; } isB = true; } else { isB = false; isBDown = false; } if (wiimote.Button.a) { if (isA) { isADown = false; } else { isADown = true; } isA = true; } else { isA = false; isADown = false; } if (dataNunchuk != null && dataNunchuk.z) { if (isZ) { isZDown = false; } else { isZDown = true; } isZ = true; } else { isZ = false; isZDown = false; } }
void OnGUI() { GUI.Box(new Rect(0, 0, 320, Screen.height), ""); GUILayout.BeginVertical(GUILayout.Width(300)); GUILayout.Label("Wiimote Found: " + WiimoteManager.HasWiimote()); if (GUILayout.Button("Find Wiimote")) { WiimoteManager.FindWiimotes(); } if (GUILayout.Button("Cleanup")) { UnityEngine.Debug.Log("Reseteo"); WiimoteManager.Cleanup(wiimote); wiimote = null; } if (wiimote == null) { return; } GUILayout.Label("Extension: " + wiimote.current_ext.ToString()); GUILayout.Label("LED Test:"); GUILayout.BeginHorizontal(); for (int x = 0; x < 4; x++) { if (GUILayout.Button("" + x, GUILayout.Width(300 / 4))) { wiimote.SendPlayerLED(x == 0, x == 1, x == 2, x == 3); } } GUILayout.EndHorizontal(); GUILayout.Label("Set Report:"); GUILayout.BeginHorizontal(); if (GUILayout.Button("But/Acc", GUILayout.Width(300 / 4))) { wiimote.SendDataReportMode(InputDataType.REPORT_BUTTONS_ACCEL); } if (GUILayout.Button("But/Ext8", GUILayout.Width(300 / 4))) { wiimote.SendDataReportMode(InputDataType.REPORT_BUTTONS_EXT8); } if (GUILayout.Button("B/A/Ext16", GUILayout.Width(300 / 4))) { wiimote.SendDataReportMode(InputDataType.REPORT_BUTTONS_ACCEL_EXT16); } if (GUILayout.Button("Ext21", GUILayout.Width(300 / 4))) { wiimote.SendDataReportMode(InputDataType.REPORT_EXT21); } GUILayout.EndHorizontal(); if (GUILayout.Button("Request Status Report")) { wiimote.SendStatusInfoRequest(); } GUILayout.Label("IR Setup Sequence:"); GUILayout.BeginHorizontal(); if (GUILayout.Button("Basic", GUILayout.Width(100))) { wiimote.SetupIRCamera(IRDataType.BASIC); } if (GUILayout.Button("Extended", GUILayout.Width(100))) { wiimote.SetupIRCamera(IRDataType.EXTENDED); } if (GUILayout.Button("Full", GUILayout.Width(100))) { wiimote.SetupIRCamera(IRDataType.FULL); } GUILayout.EndHorizontal(); GUILayout.Label("WMP Attached: " + wiimote.wmp_attached); if (GUILayout.Button("Request Identify WMP")) { wiimote.RequestIdentifyWiiMotionPlus(); } if ((wiimote.wmp_attached || wiimote.Type == WiimoteType.PROCONTROLLER) && GUILayout.Button("Activate WMP")) { wiimote.ActivateWiiMotionPlus(); } if ((wiimote.current_ext == ExtensionController.MOTIONPLUS || wiimote.current_ext == ExtensionController.MOTIONPLUS_CLASSIC || wiimote.current_ext == ExtensionController.MOTIONPLUS_NUNCHUCK) && GUILayout.Button("Deactivate WMP")) { wiimote.DeactivateWiiMotionPlus(); //OnApplicationQuit(); //WiimoteManager.Cleanup(wiimote); /*wiimote = null; * WiimoteManager.FindWiimotes();*/ /* Debug.Log("entre1"); * * NunchuckData data = wiimote.Nunchuck; * GUILayout.Label("Stick: " + data.stick[0] + ", " + data.stick[1]); * GUILayout.Label("C: " + data.c); * GUILayout.Label("Z: " + data.z);*/ } //UnityEngine.Debug.Log("entre2"); GUILayout.Label("Calibrate Accelerometer"); GUILayout.BeginHorizontal(); for (int x = 0; x < 3; x++) { AccelCalibrationStep step = (AccelCalibrationStep)x; if (GUILayout.Button(step.ToString(), GUILayout.Width(100))) { wiimote.Accel.CalibrateAccel(step); } } GUILayout.EndHorizontal(); if (GUILayout.Button("Print Calibration Data")) { StringBuilder str = new StringBuilder(); for (int x = 0; x < 3; x++) { for (int y = 0; y < 3; y++) { str.Append(wiimote.Accel.accel_calib[y, x]).Append(" "); } str.Append("\n"); } UnityEngine.Debug.Log(str.ToString()); } if (wiimote != null && wiimote.current_ext != ExtensionController.NONE) { scrollPosition = GUILayout.BeginScrollView(scrollPosition); GUIStyle bold = new GUIStyle(GUI.skin.button); bold.fontStyle = FontStyle.Bold; if (wiimote.current_ext == ExtensionController.NUNCHUCK) { UnityEngine.Debug.Log(wiimote.current_ext); GUILayout.Label("Nunchuck:", bold); NunchuckData data = wiimote.Nunchuck; GUILayout.Label("Stick: " + data.stick[0] + ", " + data.stick[1]); GUILayout.Label("C: " + data.c); GUILayout.Label("Z: " + data.z); if (data.stick[0] > 120 && data.stick[0] < 220 && data.stick[1] > 70 && data.stick[1] < 210) { controlWii.transform.position = new Vector3(controlWii.transform.position.x + numUp, 0f, controlWii.transform.position.z); } if (data.stick[0] > 20 && data.stick[0] < 120 && data.stick[1] > 63 && data.stick[1] < 209) { controlWii.transform.position = new Vector3(controlWii.transform.position.x - numUp, 0f, controlWii.transform.position.z); } if (data.stick[0] > 48 && data.stick[0] < 186 && data.stick[1] > 140 && data.stick[1] < 235) { controlWii.transform.position = new Vector3(controlWii.transform.position.x, 0f, controlWii.transform.position.z + numUp); } if (data.stick[0] > 50 && data.stick[0] < 192 && data.stick[1] > 30 && data.stick[1] < 140) { controlWii.transform.position = new Vector3(controlWii.transform.position.x, 0f, controlWii.transform.position.z - numUp); } if (data.z && butZ) { UnityEngine.Debug.Log("Se oprimio la Z"); butZ = false; wiimote.RequestIdentifyWiiMotionPlus(); } if (data.c && butC) { UnityEngine.Debug.Log("Se oprimio la C"); butC = false; wiimote.ActivateWiiMotionPlus(); } } else if (wiimote.current_ext == ExtensionController.CLASSIC) { GUILayout.Label("Classic Controller:", bold); ClassicControllerData data = wiimote.ClassicController; GUILayout.Label("Stick Left: " + data.lstick[0] + ", " + data.lstick[1]); GUILayout.Label("Stick Right: " + data.rstick[0] + ", " + data.rstick[1]); GUILayout.Label("Trigger Left: " + data.ltrigger_range); GUILayout.Label("Trigger Right: " + data.rtrigger_range); GUILayout.Label("Trigger Left Button: " + data.ltrigger_switch); GUILayout.Label("Trigger Right Button: " + data.rtrigger_switch); GUILayout.Label("A: " + data.a); GUILayout.Label("B: " + data.b); GUILayout.Label("X: " + data.x); GUILayout.Label("Y: " + data.y); GUILayout.Label("Plus: " + data.plus); GUILayout.Label("Minus: " + data.minus); GUILayout.Label("Home: " + data.home); GUILayout.Label("ZL: " + data.zl); GUILayout.Label("ZR: " + data.zr); GUILayout.Label("D-Up: " + data.dpad_up); GUILayout.Label("D-Down: " + data.dpad_down); GUILayout.Label("D-Left: " + data.dpad_left); GUILayout.Label("D-Right: " + data.dpad_right); } else if (wiimote.current_ext == ExtensionController.MOTIONPLUS) { UnityEngine.Debug.Log(wiimote.current_ext); GUILayout.Label("Wii Motion Plus:", bold); MotionPlusData data = wiimote.MotionPlus; GUILayout.Label("Pitch Speed: " + data.PitchSpeed); GUILayout.Label("Yaw Speed: " + data.YawSpeed); GUILayout.Label("Roll Speed: " + data.RollSpeed); GUILayout.Label("Pitch Slow: " + data.PitchSlow); GUILayout.Label("Yaw Slow: " + data.YawSlow); GUILayout.Label("Roll Slow: " + data.RollSlow); if (GUILayout.Button("Zero Out WMP")) { data.SetZeroValues(); model.rot.rotation = Quaternion.FromToRotation(model.rot.rotation * GetAccelVector(), Vector3.up) * model.rot.rotation; model.rot.rotation = Quaternion.FromToRotation(model.rot.forward, Vector3.forward) * model.rot.rotation; } if (GUILayout.Button("Reset Offset")) { wmpOffset = Vector3.zero; } GUILayout.Label("Offset: " + wmpOffset.ToString()); } else if (wiimote.current_ext == ExtensionController.WIIU_PRO) { GUILayout.Label("Wii U Pro Controller:", bold); WiiUProData data = wiimote.WiiUPro; GUILayout.Label("Stick Left: " + data.lstick[0] + ", " + data.lstick[1]); GUILayout.Label("Stick Right: " + data.rstick[0] + ", " + data.rstick[1]); GUILayout.Label("A: " + data.a); GUILayout.Label("B: " + data.b); GUILayout.Label("X: " + data.x); GUILayout.Label("Y: " + data.y); GUILayout.Label("D-Up: " + data.dpad_up); GUILayout.Label("D-Down: " + data.dpad_down); GUILayout.Label("D-Left: " + data.dpad_left); GUILayout.Label("D-Right: " + data.dpad_right); GUILayout.Label("Plus: " + data.plus); GUILayout.Label("Minus: " + data.minus); GUILayout.Label("Home: " + data.home); GUILayout.Label("L: " + data.l); GUILayout.Label("R: " + data.r); GUILayout.Label("ZL: " + data.zl); GUILayout.Label("ZR: " + data.zr); } else if (wiimote.current_ext == ExtensionController.GUITAR) { GUILayout.Label("Guitar", bold); GuitarData data = wiimote.Guitar; float[] stick = data.GetStick01(); GUILayout.Label("Stick: " + stick [0] + ", " + stick [1]); GUILayout.Label("Slider: " + (data.has_slider ? Convert.ToString(data.GetSlider01()) : "unsupported")); GUILayout.Label("Green: " + data.green); GUILayout.Label("Red: " + data.red); GUILayout.Label("Yellow: " + data.yellow); GUILayout.Label("Blue: " + data.blue); GUILayout.Label("Orange: " + data.orange); GUILayout.Label("Strum Up: " + data.strum_up); GUILayout.Label("Strum Down: " + data.strum_down); GUILayout.Label("Minus: " + data.minus); GUILayout.Label("Plus: " + data.plus); GUILayout.Label("Whammy: " + data.GetWhammy01()); } GUILayout.EndScrollView(); } else { scrollPosition = Vector2.zero; } GUILayout.EndVertical(); }
private Vector3 GetBaseInput() { //returns the basic values, if it's 0 than it's not active. Vector3 p_Velocity = new Vector3(); if (controlWii.current_ext == ExtensionController.NUNCHUCK) { NunchuckData data = controlWii.Nunchuck; Vector3 acc = GetAccelVector(); if (acc.y <= -0.85f && !data.c && !data.z) { transform.Rotate(new Vector3(0, 2, 0), Space.World); } else if (acc.y >= 0.1f && !data.c && !data.z) { transform.Rotate(new Vector3(0, -2, 0), Space.World); } int my = 2; if (transform.eulerAngles.y > 90 && transform.eulerAngles.y < 270) { if (acc.z >= -0.3f) { transform.eulerAngles = new Vector3(45, transform.eulerAngles.y, 0); } /*else if (acc.z <= -0.9875f) * { * transform.eulerAngles = new Vector3(315, transform.eulerAngles.y, 0); * }*/ else { transform.eulerAngles = new Vector3(0, transform.eulerAngles.y, 0); } } else { if (acc.z >= -0.3f) { transform.eulerAngles = new Vector3(45, transform.eulerAngles.y, 0); } /*else if (acc.z <= -0.9875f) * { * transform.eulerAngles = new Vector3(315, transform.eulerAngles.y, 0); * }*/ else { transform.eulerAngles = new Vector3(0, transform.eulerAngles.y, 0); } } if (data.stick[1] - 130 > 10 && !data.c && !data.z) { p_Velocity += new Vector3(0, 0, 1); } if (data.stick[1] - 130 < -10 && !data.c && !data.z) { p_Velocity += new Vector3(0, 0, -1); } if (data.stick[0] - 125 < -10 && !data.c && !data.z) { p_Velocity += new Vector3(-1, 0, 0); } if (data.stick[0] - 125 > 10 && !data.c && !data.z) { p_Velocity += new Vector3(1, 0, 0); } } return(p_Velocity); }
void Update() { //Connectie wiimote & IR basic setup WiimoteManager.FindWiimotes(); if (!WiimoteManager.HasWiimote()) { return; } wiimote = WiimoteManager.Wiimotes[0]; if (!isInit) { wiimote.SendPlayerLED(playerLeds[0], playerLeds[1], playerLeds[2], playerLeds[3]); wiimote.SetupIRCamera(IRDataType.BASIC); isInit = true; } int response; do { response = wiimote.ReadWiimoteData(); if (response < 0) { Debug.Log("Error: " + response); } } while (response > 0); ReadOnlyMatrix <int> ir = wiimote.Ir.ir; int dotCount = 4; for (int i = 0; i < 4; i++) { if (ir[i, 0] == -1 || ir[i, 1] == -1) { dotCount--; } } if (dotCount < 2) { return; } //Wiimote camera movement float[] pointer = wiimote.Ir.GetPointingPosition(); Vector2 curAnchorMin = IR_pointer.anchorMin; Vector2 curAnchorMax = IR_pointer.anchorMax; IR_pointer.anchorMin = Vector2.SmoothDamp(curAnchorMin, new Vector2(pointer[0], pointer[1]), ref currentVelocity, 0.1f, 1f); IR_pointer.anchorMax = Vector2.SmoothDamp(curAnchorMax, new Vector2(pointer[0], pointer[1]), ref currentVelocity, 0.1f, 1f); if (setupCompleted) { playerCam.transform.LookAt(IR_pointer); if (wiimote != null && wiimote.current_ext != ExtensionController.NONE) { if (wiimote.current_ext == ExtensionController.NUNCHUCK) { nunchuckData = wiimote.Nunchuck; isRunning = nunchuckData.z; } } //Speler status if (!jump) { if (wiimote.Button.b) { jump = true; } } if (!isAirborn && characterController.isGrounded) { //Speler land moveDirection.y = 0f; isJumping = false; } if (!characterController.isGrounded && !isJumping && isAirborn) { //Speler naar beneden forceren moveDirection.y = 0f; } isAirborn = characterController.isGrounded; } }