Пример #1
0
        /// <summary>
        /// Queries the controller data.
        /// </summary>
        /// <returns>The controller data.</returns>
        /// <param name="controllerNum">Controller number.</param>
        public static ControllerData QueryControllerData(int controllerNum)
        {
            //Debug.Log ("queryControllerData- Getting Controller "+controllerNum+"'s data.  There are "+QueryNumControllersConnected()+" controllers.");
                        #if (UNITY_ANDROID && !UNITY_EDITOR)
            object[]       args = { controllerNum };
            String         controllerDataStr = androidClass.CallStatic <String> ("mergeVRGetControllerData", args);
            var            V = JSON.Parse(controllerDataStr);
            ControllerData controllerDataToReturn = new ControllerData();
            controllerDataToReturn.UUID                   = V ["UUID"];
            controllerDataToReturn.Buttons                = V ["Buttons"].AsInt;
            controllerDataToReturn.RSSI                   = V ["RSSI"].AsFloat;
            controllerDataToReturn.Connected              = V ["Connected"].AsBool;
            controllerDataToReturn.calibrated             = V ["Calibrated"].AsBool;
            controllerDataToReturn.FusedSensorOrientation = new Quaternion(V ["MergeVRQuaternion_X"].AsFloat, V ["MergeVRQuaternion_Y"].AsFloat, V ["MergeVRQuaternion_Z"].AsFloat, V ["MergeVRQuaternion_W"].AsFloat);
            controllerDataToReturn.LinearAcceleration     = new Vector3(V ["LinearAcceleration_X"].AsFloat, V ["LinearAcceleration_Y"].AsFloat, V ["LinearAcceleration_Z"].AsFloat);
            controllerDataToReturn.xJoyStick              = V ["xJoyStick"].AsFloat;
            controllerDataToReturn.yJoyStick              = V ["yJoyStick"].AsFloat;
            controllerDataToReturn.firmwareVersion        = V ["FirmwareVersion"];
            controllerDataToReturn.BatteryLevel           = V ["Battery"].AsInt;
//			controllerDataToReturn = androidClass.CallStatic<ControllerData> ("mergeVRGetControllerDataStruct", args);
            return(controllerDataToReturn);
                        #elif (!UNITY_EDITOR && (UNITY_IPHONE)) || (UNITY_EDITOR_OSX || UNITY_STANDALONE_OSX)
            ControllerData controllerData = mergeVRGetControllerData(controllerNum);
            return(controllerData);
                        #elif (UNITY_EDITOR_WIN)
            //WTP2.0
            return(GetControllerData());
                        #else
            ControllerData controllerDataPC = new ControllerData();
            return(controllerDataPC);
                        #endif
        }
Пример #2
0
        static ControllerData ProcessData(IntPtr PLast)
        {
            ControllerData rcData = new ControllerData();

            rcData.FusedSensorOrientation.w = dataProcess.ProcessData(new byte[] {
                Marshal.ReadByte(PLast, 1),
                Marshal.ReadByte(PLast, 0)
            }, MergeDataProcess.DataTypeEnum.qua);
            rcData.FusedSensorOrientation.x = dataProcess.ProcessData(new byte[] {
                Marshal.ReadByte(PLast, 3),
                Marshal.ReadByte(PLast, 2)
            }, MergeDataProcess.DataTypeEnum.qua);
            rcData.FusedSensorOrientation.y = dataProcess.ProcessData(new byte[] {
                Marshal.ReadByte(PLast, 5),
                Marshal.ReadByte(PLast, 4)
            }, MergeDataProcess.DataTypeEnum.qua);
            rcData.FusedSensorOrientation.z = dataProcess.ProcessData(new byte[] {
                Marshal.ReadByte(PLast, 7),
                Marshal.ReadByte(PLast, 6)
            }, MergeDataProcess.DataTypeEnum.qua);

            rcData.LinearAcceleration.x = dataProcess.ProcessData(new byte[] {
                Marshal.ReadByte(PLast, 9),
                Marshal.ReadByte(PLast, 8)
            }, MergeDataProcess.DataTypeEnum.lia);
            rcData.LinearAcceleration.y = dataProcess.ProcessData(new byte[] {
                Marshal.ReadByte(PLast, 11),
                Marshal.ReadByte(PLast, 10)
            }, MergeDataProcess.DataTypeEnum.lia);
            rcData.LinearAcceleration.z = dataProcess.ProcessData(new byte[] {
                Marshal.ReadByte(PLast, 13),
                Marshal.ReadByte(PLast, 12)
            }, MergeDataProcess.DataTypeEnum.lia);

            rcData.Buttons = dataProcess.ProcessBtn(new byte[] {
                Marshal.ReadByte(PLast, 15),
                Marshal.ReadByte(PLast, 14)
            });
            rcData.xJoyStick = dataProcess.ProcessData(new byte[] {
                Marshal.ReadByte(PLast, 19),
                Marshal.ReadByte(PLast, 18)
            }, MergeDataProcess.DataTypeEnum.joy);
            rcData.yJoyStick = dataProcess.ProcessData(new byte[] {
                Marshal.ReadByte(PLast, 17),
                Marshal.ReadByte(PLast, 16)
            }, MergeDataProcess.DataTypeEnum.joy);
            rcData.Connected = true;
            return(rcData);
        }
Пример #3
0
        /// <summary>
        /// Updates the controller.
        /// </summary>
        /// <param name="updateCData">The controller data struct to be filled with the controller data.</param>
        public void UpdateController(ControllerData updateCData)
        {
            cData = updateCData;

            buttonApp.key      = GetButton("App");
            buttonHome.key     = GetButton("Home");
            buttonSquare.key   = GetButton("Square");
            buttonDown.key     = GetButton("Down");
            buttonTrigger1.key = GetButton("Trigger1");
            buttonTrigger2.key = GetButton("Trigger2");
            buttonZ.key        = GetButton("Z");
            buttonPower.key    = GetButton("Power");

            buttonJoyStickUp.key    = GetButton("JoystickUp");
            buttonJoyStickDown.key  = GetButton("JoystickDown");
            buttonJoyStickRight.key = GetButton("JoystickRight");
            buttonJoyStickLeft.key  = GetButton("JoystickLeft");
        }
Пример #4
0
        /// <summary>
        /// Go through all the controllers, calling UpdateController with their latest data.
        /// </summary>
        static public void Update()
        {
            if (IsControllerConnected(0))
            {
                int curControllerCount = QueryNumControllersConnected();

                // For each connected controller...
                for (int i = 0; i < curControllerCount; i++)
                {
                    // Update the controller data.
                    MergeController controller = Merge.MSDK.Instance.controllerList[i];
                    ControllerData  dat        = QueryControllerData(i);
                    controller.UpdateController(dat);

                    // Question - can controllers become UN-calibrated?
                    if (dat.calibration_status == 0)
                    {
                        dat.calibrated = true;
                    }
                }
            }
        }
Пример #5
0
        static public ControllerData GetControllerData()
        {
            int iRet;

            do
            {
                iRet = GetStructData(PBuffer, BuffSize);
            } while (iRet == 1000);
            if (iRet > 0)
            {
                IntPtr PLast = (IntPtr)((uint)PBuffer + (iRet - 1) * 20);
                lastData = ProcessData(PLast);
            }
            else if (iRet == 0)
            {
                //no data
            }
            else
            {
                Debug.LogError("Get Controller Data Error!! Should Not Happen!");
            }
            return(lastData);
        }