// ----------------------------------- private bool FindWiimote() { WiimoteManager.FindWiimotes(); if (WiimoteManager.HasWiimote()) { wiimote = WiimoteManager.Wiimotes[0]; wiimote.SendPlayerLED(true, false, false, false); // Mode = acceleration + extensions wiimote.SendDataReportMode(InputDataType.REPORT_BUTTONS_ACCEL_EXT16); // Acceleration //wiimote.Accel.CalibrateAccel(AccelCalibrationStep.A_BUTTON_UP); // IR wiimote.SetupIRCamera(IRDataType.BASIC); Debug.Log("Wiimote found and set up"); return(true); } else { wiimote = null; return(false); } }
// --------------------------------------------------------------------------------------------- #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)); }
void SearchAndInitialize() { WiimoteManager.FindWiimotes(); wiimote = WiimoteManager.Wiimotes[0]; wiimote.SendDataReportMode(InputDataType.REPORT_BUTTONS_ACCEL); wiimote.SetupIRCamera(IRDataType.EXTENDED); wiimote.SendPlayerLED(true, true, true, true); }
public override void Start() { base.Start(); #if UP_USE_WII_INPUT_MANAGER WiimoteManager.FindWiimotes(); // Poll native bluetooth drivers to find Wiimotes foreach (Wiimote r in WiimoteManager.Wiimotes) { remote = r; remote.SendPlayerLED(true, false, false, true); remote.SendDataReportMode(InputDataType.REPORT_BUTTONS); } #endif }
void SearchAndInitialize() { WiimoteManager.FindWiimotes(); if (!WiimoteManager.HasWiimote()) { return; } wiimote = WiimoteManager.Wiimotes[0]; wiimote.SendDataReportMode(InputDataType.REPORT_BUTTONS_ACCEL); wiimote.SetupIRCamera(IRDataType.BASIC); wiimote.SendPlayerLED(true, true, true, true); }
// Use this for initialization void Start() { if (wiimote == null) { WiimoteManager.FindWiimotes(); wiimote = WiimoteManager.Wiimotes [0]; wiimote.RequestIdentifyWiiMotionPlus(); wiimote.SendDataReportMode(InputDataType.REPORT_EXT21); if (wiimote.ActivateWiiMotionPlus()) { Debug.Log("WiiMotionPlus Activated"); } wiimote.SendPlayerLED(true, false, false, false); } }
// Use this for initialization void Start() { // Wiimote Calibration WiimoteManager.FindWiimotes( ); if (WiimoteManager.HasWiimote( )) { wiimote = WiimoteManager.Wiimotes[0]; wiimote.SendPlayerLED(true, false, false, false); wiimote.SendDataReportMode(InputDataType.REPORT_BUTTONS_ACCEL); } currentState = State.NONE; powerInput = 0.2f; powerMod = 0.2f; movementEnabled = true; }
void Update() { if (_wiimote == null) { return; } _wiimote.SendDataReportMode(InputDataType.REPORT_BUTTONS_ACCEL); _wiimote.SendStatusInfoRequest(); while (_wiimote.ReadWiimoteData() > 0) { ; //read all data to get up to date values; } CalibratedAccel = new ReadOnlyCollection <float>(_wiimote.Accel.GetCalibratedAccelData()); //LogDebugHelper.printVectors(new Vector3(CalibratedAccel[0], CalibratedAccel[1], CalibratedAccel[2]), "Accelerometer"); }
void Start() { // store default rotation quaternion defaultRotation = transform.rotation; WiimoteManager.FindWiimotes(); if (WiimoteManager.HasWiimote()) { Debug.Log("Wiimote is connected"); wiimote = WiimoteManager.Wiimotes [0]; wiimote.SendPlayerLED(true, false, false, false); // set output data format wiimote.SendDataReportMode(InputDataType.REPORT_BUTTONS_ACCEL_EXT16); wiimote.RequestIdentifyWiiMotionPlus(); wiimote.Accel.accel_calib = accelCalibrationData; } }
void Update() { if (!WiimoteManager.HasWiimote()) { return; } bool n = wiimote == null; wiimote = WiimoteManager.Wiimotes[0]; if (n && wiimote != null) { wiimote.SendPlayerLED(true, false, false, false); wiimote.SendDataReportMode(InputDataType.REPORT_EXT21); } int ret; do { ret = wiimote.ReadWiimoteData(); } while (ret > 0); }
public void findWiimote() { WiimoteManager.FindWiimotes(); // Poll native bluetooth drivers to find Wiimotes foreach (Wiimote remote in WiimoteManager.Wiimotes) { // Do stuff. //Console.WriteLine("Gefunden"); //LEDs markieren, dass WiiRemote verbunden ist wiiRemote = remote; //remote.RumbleOn = true; wiiRemote.SendStatusInfoRequest(); wiiRemote.SendPlayerLED(true, false, false, false); //Thread.Sleep(1000); //remote.RumbleOn = false; wiiRemote.SendStatusInfoRequest(); wiiRemote.SendDataReportMode(InputDataType.REPORT_BUTTONS_ACCEL); count++; } if (count != 0) { /*if (GameObject.Find("CalibMenu").gameObject.activeSelf) * { * setFindWiimoteText(); * //Debug.Log("START ---------- Wiimote gefunden"); * //Debug.Log("Wiimote Daten: " + wiiRemote.Accel.GetCalibratedAccelData().ToString()); * }*/ } /*return true; * } * else * { * return false; * }*/ }
// --------------------------------------------------------------------------------------------- private void Update() { // Find wiimote if (!WiimoteManager.HasWiimote()) { Debug.Log("Finding wiimote..."); if (!FindWiimote()) { return; // Exit if no wiimote found } } wiimote = WiimoteManager.Wiimotes[0]; if (GetWiimoteButtonDown(Button.One)) { Debug.Log("test"); } // --- int ret; do { // IMPORTANT - this variable assignment step stops controller latency? // Specifically the assignment part, not the read function. // Yeah I'm confused too but oh well ret = wiimote.ReadWiimoteData(); // WMP stuff if (ret > 0 && wiimote.current_ext == ExtensionController.MOTIONPLUS) { Vector3 offset = new Vector3(-wiimote.MotionPlus.PitchSpeed, wiimote.MotionPlus.YawSpeed, wiimote.MotionPlus.RollSpeed) / 95f; // Divide by 95Hz (average updates per second from wiimote) wmpOffset += offset; } } while(ret > 0); #region Button Debugs and Toggles /*if(wiimote.Button.a) { * Debug.Log(GetAccelVector()); * }*/ // Wii motion plus if (Input.GetKeyDown(KeyCode.Q)) { wiimote.RequestIdentifyWiiMotionPlus(); Debug.Log("Wii motion plus setting up..."); } if (Input.GetKeyDown(KeyCode.W)) { wiimote.RequestIdentifyWiiMotionPlus(); if (FindWMP()) { Debug.Log("Wii Motion Plus enabled"); } else { Debug.Log("Wii Motion Plus failed to enable"); } } // Accelerometer if (Input.GetKeyDown(KeyCode.R)) { wiimote.Accel.CalibrateAccel(AccelCalibrationStep.A_BUTTON_UP); Debug.Log("Accelerometer recalibrated"); if (wiimote.current_ext == ExtensionController.MOTIONPLUS) { wiimote.MotionPlus.SetZeroValues(); wmpOffset = Vector3.zero; Debug.Log("Wii Motion Plus reset"); } } // Input mode if (Input.GetKeyDown(KeyCode.I)) { wiimote.SendDataReportMode(InputDataType.REPORT_BUTTONS_ACCEL_EXT16); Debug.Log("Updated wiimote input data type"); } #endregion // --- #region Pointer // Pointer anchors and rotation if (pointerRotate) { if (irAnchors.Length < 2) { Debug.LogError("IR anchors not found"); return; } foreach (RectTransform anchor in irAnchors) { anchor.gameObject.SetActive(true); } float[,] ir = wiimote.Ir.GetProbableSensorBarIR(); /*string output = ""; * for(int i = 0; i < ir.Length; i++) { * output += "{" + ir + "}\n"; * } * Debug.Log(output);*/ for (int i = 0; i < 2; i++) { float x = ir[i, 0] / 1023f; float y = ir[i, 1] / 767f; if (x == -1 || y == -1) { irAnchors[i].anchorMin = new Vector2(0, 0); irAnchors[i].anchorMax = new Vector2(0, 0); } irAnchors[i].anchorMin = new Vector2(x, y); irAnchors[i].anchorMax = new Vector2(x, y); } pointer.rotation = GetPointerRotation(irAnchors[0].localPosition, irAnchors[1].localPosition); } else { foreach (RectTransform anchor in irAnchors) { anchor.gameObject.SetActive(false); } pointer.transform.rotation = Quaternion.identity; } // Pointer Vector2 pointerPos; if (pointerSmoothing) { pointerPos = StabilizePointerPos(pointer.anchorMax, new Vector2(wiimote.Ir.GetPointingPosition()[0], wiimote.Ir.GetPointingPosition()[1])); // Smoothed } else { pointerPos = new Vector2(wiimote.Ir.GetPointingPosition()[0], wiimote.Ir.GetPointingPosition()[1]); // Unsmoothed } pointer.anchorMin = new Vector2(pointerPos[0], pointerPos[1]); pointer.anchorMax = new Vector2(pointerPos[0], pointerPos[1]); #endregion // --- // Shake and twist if (Time.frameCount % 2 == 0) // Every 2 frames { CalculateShake(); CalculateTwist(); } }
void Update() { tempTime += Time.deltaTime; if (!WiimoteManager.HasWiimote()) { return; } // initialisierung wiimote = WiimoteManager.Wiimotes[0]; if (firstTime) { wiimote.SendDataReportMode(InputDataType.REPORT_BUTTONS_ACCEL_EXT16); int[,] caldata = { { 464, 500, 600 }, { 499, 600, 500 }, { 596, 497, 500 } }; wiimote.Accel.accel_calib = caldata; wiimote.RequestIdentifyWiiMotionPlus(); wiimote.ActivateWiiMotionPlus(); } firstTime = false; int ret; do { ret = wiimote.ReadWiimoteData(); if (ret > 0 && wiimote.current_ext == ExtensionController.MOTIONPLUS) { Vector3 offset = new Vector3(-wiimote.MotionPlus.PitchSpeed, wiimote.MotionPlus.YawSpeed, wiimote.MotionPlus.RollSpeed) / 95f; // Divide by 95Hz (average updates per second from wiimote) wmpOffset += offset; model.rot.Rotate(offset, Space.Self); } } while (ret > 0); // speichere die Accelerometerwerte der wiimote in ein Array accs = wiimote.Accel.GetCalibratedAccelData(); // Debug.Log("Calib Accel " +accs[0] + " | "+ accs[1] + " | "+accs[2]); RemoveGravity( model.rot.transform.localRotation.eulerAngles.x, model.rot.transform.localRotation.eulerAngles.y, model.rot.transform.localRotation.eulerAngles.z, accs[0], accs[1], accs[2] ); a_x = mA[0]; a_y = mA[1]; a_z = mA[2]; sVec[0] = s_x; sVec[1] = s_y; sVec[2] = s_z; v_x += a_x * Time.deltaTime; v_y += a_y * Time.deltaTime; v_z += a_z * Time.deltaTime; s_x += v_x * Time.deltaTime * speedFactor; s_y += v_y * Time.deltaTime * speedFactor; s_z += v_z * Time.deltaTime * speedFactor; model.rot.transform.Translate(s_x, s_y, s_z); /* //Hab mal versucht, die Achsen zu ändern, hat leider nichts gebracht... * RemoveGravity1( * model.rot.transform.localRotation.eulerAngles.z, * model.rot.transform.localRotation.eulerAngles.x, * model.rot.transform.localRotation.eulerAngles.y, * accs[1], * accs[0], * accs[2] * ); */ /* * RemoveGravity2( * model.rot.transform.localRotation.eulerAngles.x, * model.rot.transform.localRotation.eulerAngles.y, * model.rot.transform.localRotation.eulerAngles.z, * accs[0], * accs[1], * accs[2] * ); */ /* * Vector3 v_accel = RemoveGravity3( * model.rot.transform.localRotation.eulerAngles.x, * model.rot.transform.localRotation.eulerAngles.y, * model.rot.transform.localRotation.eulerAngles.z, * accs[0], * accs[1], * accs[2]); * */ /* * // schicke die Accelerometerwerte durch die Formel und gib mir die Positionsänderung zurück * * float xA = InertialTest(accs[0], v0, tempTime, s0); * float yA = InertialTest(accs[1], v0, tempTime, s0); * float zA = InertialTest(accs[2], v0, tempTime, s0); * * Debug.Log("ACC_CALC: X: "+xA+" Y: "+yA+ " Z: "+zA); * * // addiere Positionsänderung auf den orangen dummyCube * * dummyCube.transform.position += new Vector3(xA,yA,zA); * * * // führe functions alle timeInterval Sekunden aus * if (tempTime >timeInterval) * { * tempTime = 0; * Debug.Log("Zeitintervall: "+ timeInterval); * // functions... * } */ // button handler model.a.enabled = wiimote.Button.a; if (model.a.enabled) { Debug.Log("A pressed"); ZeroOut(); ResetOffset(); } ; model.b.enabled = wiimote.Button.b; if (!model.b.enabled) { myLineRenderer.enabled = false; } if (model.b.enabled) { Debug.Log("B pressed"); myLineRenderer.enabled = true; RaycastHit hit; if (Physics.Raycast(laser.transform.position, laser.transform.forward, out hit)) { if (hit.collider.gameObject.name == "OptionA") { print("Hit: " + hit.collider.gameObject.name); OptionAClick(); } } } ; model.one.enabled = wiimote.Button.one; model.two.enabled = wiimote.Button.two; model.d_up.enabled = wiimote.Button.d_up; model.d_down.enabled = wiimote.Button.d_down; model.d_left.enabled = wiimote.Button.d_left; model.d_right.enabled = wiimote.Button.d_right; model.plus.enabled = wiimote.Button.plus; model.minus.enabled = wiimote.Button.minus; model.home.enabled = wiimote.Button.home; if (wiimote.current_ext != ExtensionController.MOTIONPLUS) { model.rot.localRotation = initial_rotation; } if (ir_dots.Length < 4) { return; } float[,] ir = wiimote.Ir.GetProbableSensorBarIR(); for (int i = 0; i < 2; i++) { float x = (float)ir[i, 0] / 1023f; float y = (float)ir[i, 1] / 767f; if (x == -1 || y == -1) { ir_dots[i].anchorMin = new Vector2(0, 0); ir_dots[i].anchorMax = new Vector2(0, 0); } ir_dots[i].anchorMin = new Vector2(x, y); ir_dots[i].anchorMax = new Vector2(x, y); if (ir[i, 2] != -1) { int index = (int)ir[i, 2]; float xmin = (float)wiimote.Ir.ir[index, 3] / 127f; float ymin = (float)wiimote.Ir.ir[index, 4] / 127f; float xmax = (float)wiimote.Ir.ir[index, 5] / 127f; float ymax = (float)wiimote.Ir.ir[index, 6] / 127f; ir_bb[i].anchorMin = new Vector2(xmin, ymin); ir_bb[i].anchorMax = new Vector2(xmax, ymax); } } float[] pointer = wiimote.Ir.GetPointingPosition(); ir_pointer.anchorMin = new Vector2(pointer[0], pointer[1]); ir_pointer.anchorMax = new Vector2(pointer[0], pointer[1]); }
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); Vector3 offset = new Vector3(-data.PitchSpeed, data.YawSpeed, data.RollSpeed); /*if (data.PitchSpeed != 0) * { * //Debug.Log("Updating CSV"); * //Update_csv(offset); * } */ 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(); }
//============================================================================= // 関数名: void OnGUI() // 引数 : なし // 戻り値: なし // 説明 : DebugGUI //============================================================================= void OnGUI() { // 枠 GUI.Box(new Rect(0, 0, 0, Screen.height), ""); GUILayout.BeginVertical(GUILayout.Width(300)); GUILayout.Label("WiimoteFound:" + WiimoteManager.HasWiimote()); // 接続ボタン if (GUILayout.Button("Find Wiimote")) { WiimoteManager.FindWiimotes(); //wm = InitMotionPlus(WiimoteManager.Wiimotes[0]); wm = InitWiimote(WiimoteManager.Wiimotes[0]); } // 切断ボタン if (GUILayout.Button("Cleanup")) { Debug.Log("Wiiリモコンの接続を解除しました"); WiimoteManager.Cleanup(wm); wm = null; } // 接続されていなかったらこれ以降を表示しない if (wm == null) { return; } // 外部コントローラー確認 GUILayout.Label("Extension: " + wm.current_ext.ToString() + wm.Type); // LEDチェック GUILayout.BeginHorizontal(); for (int i = 0; i < 4; i++) { if (GUILayout.Button("" + i, GUILayout.Width(300 / 4))) { wm.SendPlayerLED(i == 0, i == 1, i == 2, i == 3); } } if (GUILayout.Button("LED Reset", GUILayout.Width(300 / 4))) { wm.SendPlayerLED(false, false, false, false); } GUILayout.EndHorizontal(); // 振動 GUILayout.Label("振動"); if (GUILayout.Button("ON")) { wm.RumbleOn = true; wm.SendStatusInfoRequest(); } if (GUILayout.Button("OFF")) { wm.RumbleOn = false; wm.SendStatusInfoRequest(); } // 加速度 GUILayout.BeginHorizontal(); if (GUILayout.Button("But/Acc", GUILayout.Width(300 / 4))) { wm.SendDataReportMode(InputDataType.REPORT_BUTTONS); } if (GUILayout.Button("But/Ext8", GUILayout.Width(300 / 4))) { wm.SendDataReportMode(InputDataType.REPORT_BUTTONS_EXT8); } if (GUILayout.Button("B/A/Ext16", GUILayout.Width(300 / 4))) { wm.SendDataReportMode(InputDataType.REPORT_BUTTONS_ACCEL_EXT16); } if (GUILayout.Button("Ext21", GUILayout.Width(300 / 4))) { wm.SendDataReportMode(InputDataType.REPORT_EXT21); } GUILayout.EndHorizontal(); // モーションプラス設定 GUILayout.Label("WMP Attached: " + wm.wmp_attached); if (GUILayout.Button("Request Identify WMP")) { wm.RequestIdentifyWiiMotionPlus(); } if ((wm.wmp_attached || wm.Type == WiimoteType.PROCONTROLLER) && GUILayout.Button("Activate WMP")) { wm.ActivateWiiMotionPlus(); } if ((wm.current_ext == ExtensionController.MOTIONPLUS || wm.current_ext == ExtensionController.MOTIONPLUS_CLASSIC || wm.current_ext == ExtensionController.MOTIONPLUS_NUNCHUCK) && GUILayout.Button("Deactivate WMP")) { wm.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))) { wm.Accel.CalibrateAccel(step); } } GUILayout.EndHorizontal(); }
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.MOTIONPLUS) { GUILayout.Label("Wii Motion Plus:", bold); //MotionPlusData data = wiimote.MotionPlus; dataMP = wiimote.MotionPlus; GUILayout.Label("Pitch Speed: " + dataMP.PitchSpeed); GUILayout.Label("Yaw Speed: " + dataMP.YawSpeed); GUILayout.Label("Roll Speed: " + dataMP.RollSpeed); GUILayout.Label("Pitch Slow: " + dataMP.PitchSlow); GUILayout.Label("Yaw Slow: " + dataMP.YawSlow); GUILayout.Label("Roll Slow: " + dataMP.RollSlow); /* * if (GUILayout.Button("Zero Out WMP")) * //if (IsStarted == false) * { * dataMP.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; * Flashlight.rot.rotation = Quaternion.FromToRotation(Flashlight.rot.rotation*GetAccelVector(), Vector3.up) * Flashlight.rot.rotation; * Flashlight.rot.rotation = Quaternion.FromToRotation(Flashlight.rot.forward, Vector3.forward) * Flashlight.rot.rotation; * IsStarted = true; * } */ if (GUILayout.Button("Reset Offset")) { wmpOffset = Vector3.zero; } GUILayout.Label("Offset: " + wmpOffset.ToString()); } GUILayout.EndScrollView(); } else { scrollPosition = Vector2.zero; } GUILayout.EndVertical(); }
// Update is called once per frame void Update() { WiimoteManager.FindWiimotes(); if (!WiimoteManager.HasWiimote()) { if (!thrown) { float xAxis = Input.GetAxis("Horizontal"); Vector3 position = transform.position; position.x += xAxis * horizontalSpeed; transform.position = position; } if (!thrown && Input.GetKeyDown(KeyCode.Space)) { thrown = true; rigidBody.isKinematic = false; rigidBody.velocity = new Vector3(0, 0, speed); } } else { wiimote = WiimoteManager.Wiimotes[0]; if (wiimote != null) { wiimote.SendPlayerLED(true, false, false, true); wiimote.SendDataReportMode(InputDataType.REPORT_EXT21); } int ret; do { ret = wiimote.ReadWiimoteData(); } while (ret > 0); if (!thrown) { if (wiimote.Button.d_right) { Vector3 position = transform.position; position.x += horizontalSpeed; position.x = (position.x > 0.9f) ? 0.9f : position.x; transform.position = position; } if (wiimote.Button.d_left) { Vector3 position = transform.position; position.x -= horizontalSpeed; position.x = (position.x < -0.9f) ? -0.9f : position.x; transform.position = position; } } // goal if (!thrown && wiimote.Button.b) { thrown = true; rigidBody.isKinematic = false; rigidBody.velocity = new Vector3(0, 0, speed); } // plus and minus speed if (wiimote.Button.plus) { speed = (++speed > 20) ? 20 : speed; } if (wiimote.Button.minus) { speed = (--speed < 10) ? 10 : speed; } // change of terrain if (wiimote.Button.d_up) { index = Random.Range(0, 7);//(++index > 6) ? 6 : index; transform.position = terrain[index]; } if (wiimote.Button.d_down) { index = Random.Range(0, 7);//(--index < 0) ? 0 : index; transform.position = terrain[index]; } } }
private void Update() { WiimoteManager.FindWiimotes(); if (!WiimoteManager.HasWiimote()) { if (Input.GetKeyDown(KeyCode.LeftArrow)) { MoveLane(false); } if (Input.GetKeyDown(KeyCode.RightArrow)) { MoveLane(true); } Vector3 targetPosition = transform.position.z * Vector3.forward; if (desiredLane == 0) { targetPosition += Vector3.left * LANE_DISTANSE; } else { if (desiredLane == 2) { targetPosition += Vector3.right * LANE_DISTANSE; } } Vector3 moveVector = Vector2.zero; moveVector.x = (targetPosition - transform.position).normalized.x * speed; moveVector.y = verticalVelocity; moveVector.z = speed; controller.Move(moveVector * Time.deltaTime); //Jump if (IsGrounded()) { if (Input.GetKeyDown(KeyCode.UpArrow)) { verticalVelocity = jumpForce; } } else { verticalVelocity -= (gravity * Time.deltaTime); if (Input.GetKeyDown(KeyCode.UpArrow)) { verticalVelocity = -jumpForce; } } } else { wiimote = WiimoteManager.Wiimotes[0]; if (wiimote != null) { wiimote.SendPlayerLED(true, false, true, false); wiimote.SendDataReportMode(InputDataType.REPORT_EXT21); } int ret; do { ret = wiimote.ReadWiimoteData(); }while(ret > 0); if (wiimote.Button.d_left) { Debug.Log("Left"); MoveLane(false); } if (wiimote.Button.d_right) { Debug.Log("ight"); MoveLane(true); } Vector3 targetPosition = transform.position.z * Vector3.forward; if (desiredLane == 0) { targetPosition += Vector3.left * LANE_DISTANSE; } else { if (desiredLane == 2) { targetPosition += Vector3.right * LANE_DISTANSE; } } Vector3 moveVector = Vector2.zero; moveVector.x = (targetPosition - transform.position).normalized.x * speed; moveVector.y = verticalVelocity; moveVector.z = speed; controller.Move(moveVector * Time.deltaTime); //Jump if (IsGrounded()) { if (wiimote.Button.b) { verticalVelocity = jumpForce; } } else { verticalVelocity -= (gravity * Time.deltaTime); if (Input.GetKeyDown(KeyCode.UpArrow)) { verticalVelocity = -jumpForce; } } } }
void Update() { numUp = 0.1f; if (!WiimoteManager.HasWiimote()) { return; } wiimote = WiimoteManager.Wiimotes[0]; int ret; do { ret = wiimote.ReadWiimoteData(); if (ret > 0 && wiimote.current_ext == ExtensionController.MOTIONPLUS) { Vector3 offset = new Vector3(-wiimote.MotionPlus.PitchSpeed, wiimote.MotionPlus.YawSpeed, wiimote.MotionPlus.RollSpeed) / 95f; // Divide by 95Hz (average updates per second from wiimote) wmpOffset += offset; model.rot.Rotate(offset, Space.Self); } } while (ret > 0); model.a.enabled = wiimote.Button.a; model.b.enabled = wiimote.Button.b; model.one.enabled = wiimote.Button.one; model.two.enabled = wiimote.Button.two; model.d_up.enabled = wiimote.Button.d_up; model.d_down.enabled = wiimote.Button.d_down; model.d_left.enabled = wiimote.Button.d_left; model.d_right.enabled = wiimote.Button.d_right; model.plus.enabled = wiimote.Button.plus; model.minus.enabled = wiimote.Button.minus; model.home.enabled = wiimote.Button.home; if (wiimote.Button.a) { UnityEngine.Debug.Log("El valor de rex es: " + rex); } //Hace funcionar el nunchuck y el home para reiniciar if (wiimote.Button.one) { /*if (num!=0){ * try { * wiimote.SendDataReportMode(InputDataType.REPORT_BUTTONS_ACCEL_EXT16); * }catch{ * UnityEngine.Debug.Log("Error"); * }*/ wiimote.SendDataReportMode(InputDataType.REPORT_BUTTONS_ACCEL_EXT16); num = 0; rex = true; butZ = true; butC = true; calib = true; wmpOffset = Vector3.zero; } //Calibra el control if (wiimote.Button.two && calib) { //UnityEngine.Debug.Log(wiimote.current_ext); MotionPlusData data = wiimote.MotionPlus; 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; wmpOffset = Vector3.zero; calib = false; } //UnityEngine.Debug.Log("Se oprimio A es: " + wiimote.Button.a); //Recargar el control if (wiimote.Button.home && rex) { rex = false; OnApplicationQuit(); //UnityEngine.Debug.Log("?????????"); WiimoteManager.FindWiimotes(); num = 1; } try { if (wiimote.current_ext != ExtensionController.MOTIONPLUS) { model.rot.localRotation = initial_rotation; } if (ir_dots.Length < 4) { return; } float[,] ir = wiimote.Ir.GetProbableSensorBarIR(); for (int i = 0; i < 2; i++) { float x = (float)ir[i, 0] / 1023f; float y = (float)ir[i, 1] / 767f; if (x == -1 || y == -1) { ir_dots[i].anchorMin = new Vector2(0, 0); ir_dots[i].anchorMax = new Vector2(0, 0); } ir_dots[i].anchorMin = new Vector2(x, y); ir_dots[i].anchorMax = new Vector2(x, y); if (ir[i, 2] != -1) { int index = (int)ir[i, 2]; float xmin = (float)wiimote.Ir.ir[index, 3] / 127f; float ymin = (float)wiimote.Ir.ir[index, 4] / 127f; float xmax = (float)wiimote.Ir.ir[index, 5] / 127f; float ymax = (float)wiimote.Ir.ir[index, 6] / 127f; ir_bb[i].anchorMin = new Vector2(xmin, ymin); ir_bb[i].anchorMax = new Vector2(xmax, ymax); } } float[] pointer = wiimote.Ir.GetPointingPosition(); ir_pointer.anchorMin = new Vector2(pointer[0], pointer[1]); ir_pointer.anchorMax = new Vector2(pointer[0], pointer[1]); } catch { UnityEngine.Debug.Log("Dio algo"); } /*if (num!=0) * { * try { wiimote.SendDataReportMode(InputDataType.REPORT_BUTTONS_ACCEL_EXT16); * } * catch * { * UnityEngine.Debug.Log("Error"); * } * num = 0; * }*/ }