コード例 #1
0
        private void OnWiimoteDeviceDisconneted(object sender, EventArgs e)
        {
            Application.Current.Dispatcher.Invoke(() =>
            {
                WiimoteDevice DisconnectedWiimoteDevice = sender as WiimoteDevice;

                ConnectedWiimoteDevices.Remove(DisconnectedWiimoteDevice);
                ConnectedDevicesListBox.Items.Refresh();

                if ((ConnectedDevicesListBox.SelectedItem == null) && ConnectedDevicesListBox.HasItems)
                {
                    ConnectedDevicesListBox.SelectedItem = ConnectedDevicesListBox.Items[0];
                }
            });
        }
コード例 #2
0
        private void OnClosing(object sender, System.ComponentModel.CancelEventArgs e)
        {
            if (DeviceInterfaceDiscoverer != null)
            {
                DeviceInterfaceDiscoverer.Stop();
            }

            foreach (WiimoteDevice WiimoteDevice in ConnectedWiimoteDevices)
            {
                WiimoteDevice.Disconneted -= OnWiimoteDeviceDisconneted;
                WiimoteDevice.Disconnect();
            }

            ConnectedWiimoteDevices.Clear();
            ConnectedDevicesListBox.Items.Refresh();
        }
コード例 #3
0
        private void OnNewWiimoteDeviceInterfaceFound(object sender, UserModeLib.IWiimoteDeviceInterface NewInterface)
        {
            Application.Current.Dispatcher.Invoke(() => {
                WiimoteDevice NewWiimoteDevice = new WiimoteDevice(NewInterface);

                NewWiimoteDevice.Disconneted += OnWiimoteDeviceDisconneted;
                ConnectedWiimoteDevices.Add(NewWiimoteDevice);
                ConnectedDevicesListBox.Items.Refresh();

                if (ConnectedDevicesListBox.SelectedItem == null)
                {
                    ConnectedDevicesListBox.SelectedItem = NewWiimoteDevice;
                }

                NewWiimoteDevice.Initilize();
            });
        }
コード例 #4
0
        // Update is called once per frame
        void Update()
        {
            //
            //						if (InputManager.GetInputHold ((int)States.Wave)) {
            //
            //								Debug.Log ("Wave -Hold");
            //								// animator.Play((int)States.Wave);
            //								//	animator.Play (Animator.StringToHash ("Wave"));
            //						}
            //
            //
            //
            //						if (InputManager.GetInputDown ((int)States.Wave)) {
            //
            //								Debug.Log ("Wave -Down");
            //								// animator.Play((int)States.Wave);
            //								//	animator.Play (Animator.StringToHash ("Wave"));
            //						}
            //
            //						if (InputManager.GetInputUp ((int)States.Wave)) {
            //
            //								Debug.Log ("Wave -Up");
            //								// animator.Play((int)States.Wave);
            //								//	animator.Play (Animator.StringToHash ("Wave"));
            //						}
            //
            //
            //						if (InputManager.GetInputDown ((int)States.MyCustomState)) {
            //							Debug.Log (States.MyCustomState + "-Down");
            //							// animator.Play((int)States.Wave);
            //						}
            //
            //						if (InputManager.GetInputUp ((int)States.MyCustomState)) {
            //								Debug.Log (States.MyCustomState + "-Up");
            //								// animator.Play((int)States.Wave);
            //						}


            #region Testing Fuzer
            //Demo of use of M+ and Acc data from Wiimote
            //you will use ofcourse some sofisticate algo based on Kalman or Magdwick filter to process data


            //take all devices of type WiimoteDevice
            List <WiimoteDevice> wiimoteDevices = InputManager.GetDevices <WiimoteDevice>();

            if (wiimoteDevices.Count > 0)
            {
                WiimoteDevice device = wiimoteDevices[0];

                if (device.isReady)
                {
                    if (device.motionPlus != null && device.motionPlus.Enabled)
                    {
                        if (lastTime < 0f)
                        {
                            lastTime = Time.time;
                        }

                        complementaryFuzer.Update(device.Axis[JoystickAxis.AxisAccX].value, device.Axis[JoystickAxis.AxisAccY].value, device.Axis[JoystickAxis.AxisAccZ].value, device.motionPlus.Values.x * DEG_TO_RAD, device.motionPlus.Values.y * DEG_TO_RAD, device.motionPlus.Values.z * DEG_TO_RAD, Time.time - lastTime);
                        lastTime = Time.time;



                        Angles.x = (float)(complementaryFuzer.Angles.x * RAD_TO_DEG);
                        Angles.y = (float)(complementaryFuzer.Angles.z * RAD_TO_DEG);
                        Angles.z = (float)(complementaryFuzer.Angles.y * RAD_TO_DEG);

                        // UnityEngine.Debug.Log(Angles.z);
                        // UnityEngine.Debug.Log(Angles.x + " " + Angles.y + " " + Angles.z);

                        wiimote.transform.rotation = Quaternion.Euler(Angles);
                    }
                }
            }

            #endregion



            //
            //
//            if (InputManager.GetInputHold(Animator.StringToHash("WalkBackward")))
//            {
//                Debug.Log("WalkBackward-Hold");
//            }
//
//
//            if (InputManager.GetInputDown(Animator.StringToHash("WalkBackward")))
//            {
//                Debug.Log("WalkBackward-Down");
//            }
//
//            if (InputManager.GetInputUp(Animator.StringToHash("WalkBackward")))
//            {
//                Debug.Log("WalkBackward-Up");
//            }
//
//
//            if (InputManager.GetInputHold(Animator.StringToHash("WalkForward")))
//            {
//                Debug.Log("WalkForward-Hold");
//            }
//
//            if (InputManager.GetInputDown(Animator.StringToHash("WalkForward")))
//            {
//                Debug.Log("WalkForward-Down");
//            }
//
//            if (InputManager.GetInputUp(Animator.StringToHash("WalkForward")))
//            {
//                Debug.Log("WalkForward-Up");
//            }
            //
            ////

            //Bind Axis as one part

            //						InputManager.MapStateToInput ("WalkForward", KeyCodeExtension.W.SINGLE);
            //						InputManager.MapStateToInput ("WalkForward", 1, KeyCodeExtension.Joystick1AxisXPositive.SINGLE);
            //
            //
            //						InputManager.MapStateToInput ("WalkBackward", KeyCodeExtension.S.SINGLE);
            //						InputManager.MapStateToInput ("WalkBackward", 1, KeyCodeExtension.Joystick1AxisYNegative.SINGLE);
            //
            //

            //			float axisPos = InputManager.GetInput (Animator.StringToHash ("WalkForward"), 0.3f, 0.1f, 0.2f);
            //
            //			float axisNeg= InputManager.GetInput (Animator.StringToHash ("WalkBackward"),  0.3f, 0.1f, 0.1f);
            //
            //			float analogVal=axisPos - axisNeg;

            //Debug.Log (analogVal);//would go from  -1 to 1



            // Hardware normalized value in range of -1f to 1f (keys,mouse would return 0f or 1f, triggers 0f to 1f)
            //float analogVal2= InputManager.GetInput (Animator.StringToHash ("WalkBackward"));
            //Debug.Log (analogVal2);
        }