Beispiel #1
0
        // 3dof手柄不区分左右手,返回结果一致
        // 1s=60, 60s更新1次
        /// <summary>
        /// Get the power of controller.
        /// </summary>
        /// <param name="handType">left or right</param>
        /// <returns></returns>
        public static int GetControllerPower(NACTION_HAND_TYPE handType = NACTION_HAND_TYPE.HAND_RIGHT)
        {
            InitManagerContext();
            if (managerContext == null)
            {
                return(0);
            }
            if (powerCallCount[(int)handType] < 0 || powerCallCount[(int)handType] > 3600)
            {
                powerCacheValue[(int)handType] = managerContext.Call <int>("getControllerBatteryLevel", (int)handType);
                powerCallCount[(int)handType]  = 0;
            }

            powerCallCount[(int)handType] = powerCallCount[(int)handType] + 1;
            return(Mathf.Max(powerCacheValue[(int)handType], 0));
        }
Beispiel #2
0
        // action : 2=move,1=up
        //        -1
        // -1 --/-- 1
        //      1
        public static void OnCTouchEvent(string touchInfo)
        {
            //1016_2_0.0_0.0_2
            // msgId_action_x_y
            // Debug.Log("OnCTouchEvent: " + touchInfo);
            string[]          data     = touchInfo.Split('_');
            int               action   = int.Parse(data[1]);
            float             x        = (float)Math.Round(double.Parse(data[2]), 4);
            float             y        = (float)Math.Round(double.Parse(data[3]), 4);
            NACTION_HAND_TYPE handType =
                int.Parse(data[4]) == 1 ? NACTION_HAND_TYPE.HAND_LEFT : NACTION_HAND_TYPE.HAND_RIGHT;

            TouchPadPosition = new Vector2(x, y);
            if (handType == NACTION_HAND_TYPE.HAND_LEFT)
            {
                TouchPadPositionLeft = new Vector2(x, y);
            }
            else
            {
                TouchPadPositionRight = new Vector2(x, y);
            }

            if (action == CKeyEvent.ACTION_MOVE)
            {
                keystate[CKeyEvent.KEYCODE_CONTROLLER_TOUCHPAD_TOUCH] = CKeyEvent.ACTION_DOWN;
                if (handType == NACTION_HAND_TYPE.HAND_LEFT)
                {
                    keystateLeft[CKeyEvent.KEYCODE_CONTROLLER_TOUCHPAD_TOUCH] = CKeyEvent.ACTION_DOWN;
                }
                else if (handType == NACTION_HAND_TYPE.HAND_RIGHT)
                {
                    keystateRight[CKeyEvent.KEYCODE_CONTROLLER_TOUCHPAD_TOUCH] = CKeyEvent.ACTION_DOWN;
                }
            }
            else if (action == CKeyEvent.ACTION_UP)
            {
                keystate[CKeyEvent.KEYCODE_CONTROLLER_TOUCHPAD_TOUCH] = CKeyEvent.ACTION_UP;
                if (handType == NACTION_HAND_TYPE.HAND_LEFT)
                {
                    keystateLeft[CKeyEvent.KEYCODE_CONTROLLER_TOUCHPAD_TOUCH] = CKeyEvent.ACTION_UP;
                }
                else if (handType == NACTION_HAND_TYPE.HAND_RIGHT)
                {
                    keystateRight[CKeyEvent.KEYCODE_CONTROLLER_TOUCHPAD_TOUCH] = CKeyEvent.ACTION_UP;
                }
            }
        }
Beispiel #3
0
        // hand代表左/右手,hand=0->左手,hand=1->右手,float数组为长度为4的四元数+长度为3的位移
        // 四元数的顺序: x-y-z-w
        public static float[] GetControllerPose(NACTION_HAND_TYPE handType = NACTION_HAND_TYPE.HAND_RIGHT)
        {
            InitManagerContext();
            if (managerContext == null || !IsControllerConnected())
            {
                return new float[] { 0, 0, 0, 0, 0, 0, 0 }
            }
            ;

            if (handType == NACTION_HAND_TYPE.HAND_LEFT && !IsLeftControllerConnected())
            {
                return(new float[] { 0, 0, 0, 0, 0, 0, 0 });
            }

            if (handType == NACTION_HAND_TYPE.HAND_RIGHT && !IsRightControllerConnected())
            {
                return(new float[] { 0, 0, 0, 0, 0, 0, 0 });
            }

            return(managerContext.Call <float[]>("getControllerPose", (int)handType));
        }
Beispiel #4
0
        public static void OnCKeyEvent(string keyCodeInfo)
        {
            // msgId_action_keyCode
            Debug.Log("OnCKeyEvent: " + keyCodeInfo + "," + Time.frameCount);
            string[] data = keyCodeInfo.Split('_');
            // 0=down,1=up
            int action  = int.Parse(data[1]);
            int keyCode = int.Parse(data[2]);

            if (keyCode == 105)
            {
                // 统一使用103作为trigger
                keyCode = CKeyEvent.KEYCODE_CONTROLLER_TRIGGER;
            }

            if (!NxrViewer.Instance.IsAppHandleTriggerEvent && CKeyEvent.KEYCODE_CONTROLLER_TRIGGER == keyCode)
            {
                if (action == 1)
                {
                    NxrViewer.Instance.Triggered = true;
                }

                // action = 1;
                keyCode = CKeyEvent.KEYCODE_CONTROLLER_TRIGGER_INTERNAL;
            }

            NACTION_HAND_TYPE handType =
                int.Parse(data[3]) == 1 ? NACTION_HAND_TYPE.HAND_LEFT : NACTION_HAND_TYPE.HAND_RIGHT;

            // 1=left.2=right
            keystate[keyCode] = action;
            if (handType == NACTION_HAND_TYPE.HAND_LEFT)
            {
                keystateLeft[keyCode] = action;
            }
            else if (handType == NACTION_HAND_TYPE.HAND_RIGHT)
            {
                keystateRight[keyCode] = action;
            }
        }