Beispiel #1
0
    // Start is called before the first frame update
    void Start()
    {
        //Find and stor Wiimote ref in variable
        WiimoteManager.FindWiimotes();
        if (WiimoteManager.Wiimotes.Count != 0)
        {
            _remote = WiimoteManager.Wiimotes[0];
            _remote.SendPlayerLED(false, false, false, false);

            isConnected = true;

            //Setup IR Camera
            if (_remote.SetupIRCamera(IRDataType.BASIC))
            {
                Debug.Log("IR Setup Successful!");
            }
            else
            {
                Debug.Log("IR Setup Failed!");
            }
        }
        else
        {
            isConnected = false;

            Debug.Log("Wiimote not connected!");
        }
    }
Beispiel #2
0
    //Used to connect / disconnect wii
    public void ConnectWii()
    {
        //If Wiimote is detected
        if (wiimote != null)
        {
            //Disconnect wii
            WiimoteManager.Cleanup(wiimote);
            wiimote = null;
        }
        else
        {
            WiimoteManager.FindWiimotes();  //Find for connected Wii Mote

            //Check if Manager has wii mote connected
            if (WiimoteManager.HasWiimote())
            {
                //Assign our variable to the first
                wiimote = WiimoteManager.Wiimotes[0];

                if (wiimote != null)
                {
                    wiimote.SendPlayerLED(true, false, false, false);
                }

                //Setup IR Camera
                bool IRSetUp = wiimote.SetupIRCamera(IRDataType.BASIC);

                print(IRSetUp);
            }
        }
    }
Beispiel #3
0
    // -----------------------------------

    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);
        }
    }
    private void OnCollisionStay(Collision collision)
    {
        GameObject obj = collision.gameObject;

        if (obj.name.Equals("RightHand"))
        {
            RightHand = collision.gameObject;
        }
        if (TouchingFurniture() && OpenFingersRight <= 2)
        {
            transform.SetParent(RightHand.transform.parent.transform);
            transform.position = new Vector3(vista.transform.position.x, vista.transform.position.y, vista.transform.position.z);
            GetComponent <Rigidbody>().useGravity  = false;
            GetComponent <Rigidbody>().isKinematic = true;
            isGrabbed = true;
            WiimoteManager.FindWiimotes();
            controlWii = WiimoteManager.Wiimotes[0];
            controlWii.SetupIRCamera(IRDataType.BASIC);
            if (!transform.name.Equals(nameFurni))
            {
                nameFurni   = transform.name;
                actualScale = transform.localScale;
            }
        }
    }
Beispiel #5
0
 void Start()
 {
     WiimoteManager.FindWiimotes();
     wiimote = WiimoteManager.Wiimotes[0];
     wiimote.SendPlayerLED(true, true, false, false);
     wiimote.SetupIRCamera(IRDataType.FULL);
 }
Beispiel #6
0
    // ---------------------------------------------------------------------------------------------

    #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));
    }
Beispiel #7
0
    void SearchAndInitialize()
    {
        WiimoteManager.FindWiimotes();

        wiimote = WiimoteManager.Wiimotes[0];
        wiimote.SendDataReportMode(InputDataType.REPORT_BUTTONS_ACCEL);
        wiimote.SetupIRCamera(IRDataType.EXTENDED);
        wiimote.SendPlayerLED(true, true, true, true);
    }
Beispiel #8
0
    // Use this for initialization
    void Start()
    {
        WiimoteManager.FindWiimotes();
        wiimote = WiimoteManager.Wiimotes[0];
        wiimote.RequestIdentifyWiiMotionPlus();
        wiimote.ActivateWiiMotionPlus();
        wiimote.SetupIRCamera(IRDataType.BASIC);

        pivot = transform.parent;
    }
Beispiel #9
0
    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++;
                }
            }
        }
    }
Beispiel #10
0
    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);
    }
    void Update()
    {
        transform.position = new Vector3(transform.position.x, 2f, transform.position.z);
        int ret;

        do
        {
            ret = controlWii.ReadWiimoteData();
        } while (ret > 0);
        //Debug.Log(controlWii.current_ext);

        controlWii.SetupIRCamera(IRDataType.BASIC);
        transform.eulerAngles = new Vector3(transform.eulerAngles.x, transform.eulerAngles.y, 0);
        //Keyboard commands
        Vector3 p = GetBaseInput();

        if (Input.GetKey(KeyCode.LeftShift))
        {
            totalRun += Time.deltaTime;
            p         = p * totalRun * shiftAdd;
            p.x       = Mathf.Clamp(p.x, -maxShift, maxShift);
            p.y       = Mathf.Clamp(p.y, -maxShift, maxShift);
            p.z       = Mathf.Clamp(p.z, -maxShift, maxShift);
        }
        else
        {
            totalRun = Mathf.Clamp(totalRun * 0.5f, 1f, 1000f);
            p        = p * mainSpeed;
        }

        p = p * Time.deltaTime;
        Vector3 newPosition = transform.position;

        if (Input.GetKey(KeyCode.Space))
        { //If player wants to move on X and Z axis only
            transform.Translate(p);
            newPosition.x      = transform.position.x;
            newPosition.z      = transform.position.z;
            transform.position = newPosition;
        }
        else
        {
            transform.Translate(p);
        }
        if (controlWii.Button.b)
        {
            SceneManager.LoadScene("MenuPrincipal");
        }
    }
Beispiel #12
0
 void Start()
 {
     if (Singleton != null)
     {
         Debug.LogError("Two WiimoteHandlers in scene at the same time!  Destroying extra WiimoteHandler.");
         Destroy(this);
         return;
     }
     WiimoteManager.FindWiimotes();
     if (WiimoteManager.HasWiimote())
     {
         Wiimote remote = WiimoteManager.Wiimotes[0];
         remote.SendPlayerLED(true, false, false, false);
         remote.SetupIRCamera();
     }
 }
Beispiel #13
0
    // Display for player to connect their wiimote to Unity
    void OnGUI()
    {
        GUI.Box(new Rect(0, 0, 235, Screen.height), "");

        GUILayout.BeginVertical(GUILayout.Width(230));
        // Find wiimote
        GUILayout.Label(" Wiimote Found: " + WiimoteManager.HasWiimote());
        if (GUILayout.Button("Find Your Wiimote"))
        {
            WiimoteManager.FindWiimotes();
        }

        // Remove wiimote
        if (GUILayout.Button("Cleanup"))
        {
            WiimoteManager.Cleanup(wiimote);
            wiimote = null;
        }

        if (wiimote == null)
        {
            return;
        }

        GUILayout.Label(" Press A on your wiimote to start!");
        // Finds and activates wii motion plus
        if (GUILayout.Button("Press if Wiimotion Plus attached"))
        {
            wiimote.SetupIRCamera(IRDataType.BASIC);
            wiimote.RequestIdentifyWiiMotionPlus();
        }
        if ((wiimote.wmp_attached || wiimote.Type == WiimoteType.PROCONTROLLER) &&
            GUILayout.Button("Press to activate Wiimotion Plus"))
        {
            wiimote.ActivateWiiMotionPlus();
        }

        // Instructions for player
        if (wiimote.current_ext == ExtensionController.MOTIONPLUS)
        {
            GUILayout.Label(" Wii Motion Plus Activated!");
            GUILayout.Label(" Press A on your wiimote to start!");
            GUILayout.Label(" Press A or shake wiimote upwards to control the flappy bird");
        }

        GUILayout.EndVertical();
    }
Beispiel #14
0
    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);
            }
        }
    }
Beispiel #15
0
    // 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;
                }
            }
        }
    }
Beispiel #16
0
    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();
    }
Beispiel #17
0
    /// <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;
        }
    }
Beispiel #18
0
    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())
        {
            return;
        }

        // Setup blue camera when at least one remote is detected
        if (!blueIsSet)
        {
            wiimoteBlue = WiimoteManager.Wiimotes[1];
            blueIsSet   = wiimoteBlue.SetupIRCamera(IRDataType.BASIC);
        }

        if (!gamestarted)
        {
            StartScreen();
        }
        else
        {
            if (blueIsSet)
            {
                CollectWiimoteData(wiimoteBlue);

                if (!wiimoteBlue.Button.a && blueTime > 0)
                {
                    blueTime -= Time.deltaTime;
                    UpdateCrosshairPosition(wiimoteBlue, blueCrosshair);
                    if (blueTime <= 0)
                    {
                        roundOver("Too late! Times up");
                        ammoCount = 0;
                    }
                }

                /*check if b button pressed and check accel data*/
                else if (ammoCount > 0)
                {
                    // Debug.Log("Blue B button pressed");
                    Vector3 accelData = GetAccelVector(wiimoteBlue);
                    // Debug.Log(accelData.ToString());
                    if ((accelData.x < -3.0f || accelData.y < -3.0f) && !bluefired)
                    {
                        targetVector.y = blueCrosshair.anchorMin.y - 0.5f;
                        targetVector.x = blueCrosshair.anchorMin.x - 0.5f;

                        if (targetVector.y < 0.0f)
                        {
                            targetVector.y = 0.0f;                        //cap it for calibration
                        }
                        Transform  ingredTransform = blueProjectile.GetComponentsInChildren <Transform>(true)[0];
                        Quaternion ingredRotation  = ingredTransform.rotation;
                        Vector3    ingredPosition  = new Vector3(12, 9.66f, -1.5f);

                        GameObject foodBullet = Instantiate(blueProjectile, ingredPosition, ingredRotation) as GameObject;
                        if (foodBullet.GetComponent <Rigidbody>() == null)
                        {
                            foodBullet.AddComponent <Rigidbody>();
                        }
                        if (foodBullet.GetComponent <SphereCollider>() == null)
                        {
                            foodBullet.AddComponent <SphereCollider>();
                        }
                        if (foodBullet.GetComponent <ProjectileBehaviour>() == null)
                        {
                            foodBullet.AddComponent <ProjectileBehaviour>();
                        }
                        // GameObject foodBullet = Instantiate(blueProjectile, blueProjectile.transform.position, Quaternion.identity) as GameObject;
                        foodBullet.name = "BlueProjectile";
                        foodBullet.GetComponent <Rigidbody>().useGravity  = true;
                        foodBullet.GetComponent <SphereCollider>().radius = 0.01f;
                        ScaleProjectile(foodBullet);
                        foodBullet.GetComponent <Rigidbody>().AddForce(-forcex, targetVector.y * forcey, targetVector.x * forcez);
                        bluefired  = true;
                        ammoCount -= 1;
                    }
                }
            }

            DisplayTime();
        }
    }
Beispiel #20
0
    // Update is called once per frame
    void Update()
    {
        WiimoteManager.FindWiimotes();
        if (!WiimoteManager.HasWiimote())
        {
            return;
        }

        // Setup red camera when at least one remote is detected
        if (!redIsSet)
        {
            wiimoteRed = WiimoteManager.Wiimotes[0];
            wiimoteRed.SetupIRCamera(IRDataType.BASIC);
            redIsSet = true;
        }

        // Set up the blue camera when multiple remotes are detected
        if (!blueIsSet && WiimoteManager.Wiimotes.Count > 1)
        {
            wiimoteBlue = WiimoteManager.Wiimotes[1];
            wiimoteBlue.SetupIRCamera(IRDataType.BASIC);
            blueIsSet = true;
        }

        if (redIsSet)
        {
            collectWiimoteData(wiimoteRed);
            if (!wiimoteRed.Button.b)
            {
                redTime -= Time.deltaTime;
                updateCrosshairPosition(wiimoteRed, ir_pointerRed);
                if (redTime <= 0)
                {
                    redTimeOverPanel.gameObject.SetActive(true);
                    redTime = 0f;
                }
            }

            /*check if b button pressed and check accel data*/
            else
            {
                Vector3 accelData = GetAccelVector(wiimoteRed);
                Debug.Log(accelData.ToString());
                //throw some projectile
            }
        }
        if (blueIsSet)
        {
            collectWiimoteData(wiimoteBlue);
            if (!wiimoteBlue.Button.b)
            {
                blueTime -= Time.deltaTime;
                updateCrosshairPosition(wiimoteBlue, ir_pointerBlue);
                if (blueTime <= 0)
                {
                    blueTimeOverPanel.gameObject.SetActive(true);
                    blueTime = 0f;
                }
            }

            /*check if b button pressed and check accel data*/
            else
            {
                Vector3 accelData = GetAccelVector(wiimoteBlue);
                Debug.Log(accelData.ToString());
                //throw some projectile
            }
        }
        displayTime();
    }
    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;
        }
    }