Exemplo n.º 1
0
        private void HandlePendingClick()
        {
            if (!pointerData.eligibleForClick && !pointerData.dragging)
            {
                return;
            }
            if (gazePointer != null)
            {
                Camera camera = pointerData.enterEventCamera;
                gazePointer.OnGazeTriggerEnd(camera);
            }

            var go = pointerData.pointerCurrentRaycast.gameObject;

            // Send pointer up and click events.
            ExecuteEvents.Execute(pointerData.pointerPress, pointerData, ExecuteEvents.pointerUpHandler);
            // 符合资格的点击
            if (pointerData.eligibleForClick)
            {
                if (NxrViewer.Instance != null)
                {
                    if (NxrViewer.Instance.HeadControl != HeadControl.Hover ||
                        (NxrPlayerCtrl.Instance.IsQuatConn() || ControllerAndroid.IsNoloConn()))
                    {
                        ExecuteEvents.Execute(pointerData.pointerPress, pointerData, ExecuteEvents.pointerClickHandler);
                    }
                }
            }
            else if (pointerData.dragging)
            {
                ExecuteEvents.ExecuteHierarchy(go, pointerData, ExecuteEvents.dropHandler);
                ExecuteEvents.Execute(pointerData.pointerDrag, pointerData, ExecuteEvents.endDragHandler);
            }

            // Clear the click state.
            pointerData.pointerPress     = null;
            pointerData.rawPointerPress  = null;
            pointerData.eligibleForClick = false;
            pointerData.clickCount       = 0;
            pointerData.clickTime        = 0;
            pointerData.pointerDrag      = null;
            pointerData.dragging         = false;
        }
Exemplo n.º 2
0
        // One Frame Update
        public void Process()
        {
            //when ime show unity is still running, disable input process
            if (TouchScreenKeyboard.visible)
            {
                NxrViewer.Instance.Triggered = false;
                return;
            }
            Array.Copy(KeyStateHMD, KeyStateHMD_Pre, MAX_INDEX);
            Array.Copy(KeyStateControllerLeft, KeyStateControllerLeft_Pre, MAX_INDEX);
            Array.Copy(KeyStateControllerRight, KeyStateControllerRight_Pre, MAX_INDEX);

            bool dpadCenterDown = Input.GetKey(KeyCode.JoystickButton0) || Input.GetKey((KeyCode)10) ||
                                  Input.GetMouseButtonDown(0);
            bool backDown      = Input.GetKey(KeyCode.Escape);
            bool dpadLeftDown  = Input.GetKey(KeyCode.LeftArrow);
            bool dpadRightDown = Input.GetKey(KeyCode.RightArrow);
            bool dpadUpDown    = Input.GetKey(KeyCode.UpArrow);
            bool dpadDownDown  = Input.GetKey(KeyCode.DownArrow);
            // 功能按键nf1/nf2
            bool nf1Down      = Input.GetKey(KeyCode.Joystick6Button1);
            bool nf2Down      = Input.GetKey(KeyCode.Joystick6Button2);
            bool dpadCenterUp = false;

            if ((!InteractionManager.IsControllerConnected() && !ControllerAndroid.isQuatConn() &&
                 !ControllerAndroid.IsNoloConn()) || Application.isEditor)
            {
                dpadCenterUp = Input.GetKeyUp(KeyCode.JoystickButton0) || Input.GetKeyUp((KeyCode)10) ||
                               Input.GetMouseButtonUp(0);
            }

            // 模拟一体机按键: WASD 上左下右,空格返回,回车确定
            if (Application.isEditor)
            {
                dpadCenterDown = Input.GetKey(KeyCode.Return) || Input.GetMouseButton(0);
                dpadLeftDown   = Input.GetKey(KeyCode.A);
                dpadRightDown  = Input.GetKey(KeyCode.D);
                dpadUpDown     = Input.GetKey(KeyCode.W);
                dpadDownDown   = Input.GetKey(KeyCode.S);
                backDown       = Input.GetKey(KeyCode.Space);
            }
            if (nf1Down)
            {
                KeyStateHMD[CKeyEvent.KEYCODE_NF_1] = CKeyEvent.ACTION_DOWN;
            }
            else
            {
                KeyStateHMD[CKeyEvent.KEYCODE_NF_1] = CKeyEvent.ACTION_UP;
            }

            if (nf2Down)
            {
                KeyStateHMD[CKeyEvent.KEYCODE_NF_2] = CKeyEvent.ACTION_DOWN;
            }
            else
            {
                KeyStateHMD[CKeyEvent.KEYCODE_NF_2] = CKeyEvent.ACTION_UP;
            }

            if (backDown)
            {
                KeyStateHMD[CKeyEvent.KEYCODE_BACK] = CKeyEvent.ACTION_DOWN;
            }
            else
            {
                KeyStateHMD[CKeyEvent.KEYCODE_BACK] = CKeyEvent.ACTION_UP;
            }

            if (dpadCenterUp)
            {
                NxrViewer.Instance.Triggered = true;
            }

            if (dpadCenterDown)
            {
                KeyStateHMD[CKeyEvent.KEYCODE_DPAD_CENTER] = CKeyEvent.ACTION_DOWN;
            }
            else
            {
                KeyStateHMD[CKeyEvent.KEYCODE_DPAD_CENTER] = CKeyEvent.ACTION_UP;
            }

            if (dpadLeftDown)
            {
                KeyStateHMD[CKeyEvent.KEYCODE_DPAD_LEFT] = CKeyEvent.ACTION_DOWN;
            }
            else
            {
                KeyStateHMD[CKeyEvent.KEYCODE_DPAD_LEFT] = CKeyEvent.ACTION_UP;
            }

            if (dpadRightDown)
            {
                KeyStateHMD[CKeyEvent.KEYCODE_DPAD_RIGHT] = CKeyEvent.ACTION_DOWN;
            }
            else
            {
                KeyStateHMD[CKeyEvent.KEYCODE_DPAD_RIGHT] = CKeyEvent.ACTION_UP;
            }

            if (dpadUpDown)
            {
                KeyStateHMD[CKeyEvent.KEYCODE_DPAD_UP] = CKeyEvent.ACTION_DOWN;
            }
            else
            {
                KeyStateHMD[CKeyEvent.KEYCODE_DPAD_UP] = CKeyEvent.ACTION_UP;
            }

            if (dpadDownDown)
            {
                KeyStateHMD[CKeyEvent.KEYCODE_DPAD_DOWN] = CKeyEvent.ACTION_DOWN;
            }
            else
            {
                KeyStateHMD[CKeyEvent.KEYCODE_DPAD_DOWN] = CKeyEvent.ACTION_UP;
            }

            // 3Dof/6Dof Controller
            if (InteractionManager.IsControllerConnected())
            {
                //3DOF
                Array.Copy(KeyStateController3DOF, KeyStateController3DOF_Pre, MAX_INDEX);
                int[] keyAction = InteractionManager.GetKeyAction();
                KeyStateController3DOF = keyAction;

                // NOLO
                if (InteractionManager.IsSixDofController)
                {
                    Array.Copy(KeyStateControllerNOLO_Left, KeyStateControllerNOLO_Left_Pre, MAX_INDEX);
                    Array.Copy(KeyStateControllerNOLO_Right, KeyStateControllerNOLO_Right_Pre, MAX_INDEX);
                    int[] keyActionLeft =
                        InteractionManager.GetKeyAction((int)InteractionManager.NACTION_HAND_TYPE.HAND_LEFT);
                    int[] keyActionRight =
                        InteractionManager.GetKeyAction((int)InteractionManager.NACTION_HAND_TYPE.HAND_RIGHT);
                    KeyStateControllerNOLO_Left  = keyActionLeft;
                    KeyStateControllerNOLO_Right = keyActionRight;
                }
            }
            else if (ControllerAndroid.isQuatConn() || ControllerAndroid.IsNoloConn())
            {
                // 交互库Close
                Array.Copy(KeyStateController3DOF, KeyStateController3DOF_Pre, MAX_INDEX);
                int[] keyAction = NibiruTaskApi.GetKeyAction();
                KeyStateController3DOF = keyAction;
                // type, action, x, y
                float[] touchInfo = ControllerAndroid.getTouch();
                if (touchInfo[1] == CKeyEvent.ACTION_MOVE)
                {
                    InteractionManager.TouchPadPosition = new Vector2(touchInfo[2], touchInfo[3]);
                    KeyStateController3DOF[CKeyEvent.KEYCODE_CONTROLLER_TOUCHPAD_TOUCH] = CKeyEvent.ACTION_DOWN;
                }
                else if (touchInfo[1] == CKeyEvent.ACTION_UP)
                {
                    KeyStateController3DOF[CKeyEvent.KEYCODE_CONTROLLER_TOUCHPAD_TOUCH] = CKeyEvent.ACTION_UP;
                }

                bool isNoloLeftConnected  = ControllerAndroid.isDeviceConn((int)CDevice.NOLO_TYPE.LEFT);
                bool isNoloRightConnected = ControllerAndroid.isDeviceConn((int)CDevice.NOLO_TYPE.RIGHT);
                if (isNoloLeftConnected)
                {
                    Array.Copy(KeyStateControllerNOLO_Left, KeyStateControllerNOLO_Left_Pre, MAX_INDEX);
                    int[] keyActionLeft =
                        ControllerAndroid.getKeyState((int)InteractionManager.NACTION_HAND_TYPE.HAND_LEFT, 0);
                    KeyStateControllerNOLO_Left = keyActionLeft;

                    float[] touchInfoLeft = ControllerAndroid.getTouchEvent((int)CDevice.NOLO_TYPE.LEFT);
                    if (touchInfoLeft[1] == CKeyEvent.ACTION_MOVE)
                    {
                        InteractionManager.TouchPadPosition = new Vector2(touchInfoLeft[2], touchInfoLeft[3]);
                        KeyStateControllerNOLO_Left[CKeyEvent.KEYCODE_CONTROLLER_TOUCHPAD_TOUCH] =
                            CKeyEvent.ACTION_DOWN;
                    }
                    else if (touchInfoLeft[1] == CKeyEvent.ACTION_UP)
                    {
                        KeyStateControllerNOLO_Left[CKeyEvent.KEYCODE_CONTROLLER_TOUCHPAD_TOUCH] = CKeyEvent.ACTION_UP;
                    }
                }

                if (isNoloRightConnected)
                {
                    Array.Copy(KeyStateControllerNOLO_Right, KeyStateControllerNOLO_Right_Pre, MAX_INDEX);
                    int[] keyActionRight =
                        ControllerAndroid.getKeyState((int)InteractionManager.NACTION_HAND_TYPE.HAND_RIGHT, 0);
                    KeyStateControllerNOLO_Right = keyActionRight;

                    float[] touchInfoRight = ControllerAndroid.getTouchEvent((int)CDevice.NOLO_TYPE.RIGHT);
                    if (touchInfoRight[1] == CKeyEvent.ACTION_MOVE)
                    {
                        InteractionManager.TouchPadPosition = new Vector2(touchInfoRight[2], touchInfoRight[3]);
                        KeyStateControllerNOLO_Right[CKeyEvent.KEYCODE_CONTROLLER_TOUCHPAD_TOUCH] =
                            CKeyEvent.ACTION_DOWN;
                    }
                    else if (touchInfoRight[1] == CKeyEvent.ACTION_UP)
                    {
                        KeyStateControllerNOLO_Right[CKeyEvent.KEYCODE_CONTROLLER_TOUCHPAD_TOUCH] = CKeyEvent.ACTION_UP;
                    }
                }
            }

            // 3Dof/6Dof Controller

            if (Application.isEditor && NxrViewer.Instance.RemoteDebug && NxrViewer.Instance.RemoteController)
            {
                Array.Copy(KeyStateController3DOF, KeyStateController3DOF_Pre, MAX_INDEX);
                NibiruEmulatorManager nibiruEmulatorManager = NibiruEmulatorManager.Instance;
                Array.Copy(nibiruEmulatorManager.KeyStateController3DOF, KeyStateController3DOF, MAX_INDEX);
            }

            // 内部事件处理返回键逻辑
            if (GetKeyUp(CKeyEvent.KEYCODE_BACK) ||
                GetControllerKeyUp(CKeyEvent.KEYCODE_CONTROLLER_MENU) ||
                GetControllerKeyUp(CKeyEvent.KEYCODE_CONTROLLER_MENU, InteractionManager.NACTION_HAND_TYPE.HAND_LEFT) ||
                GetControllerKeyUp(CKeyEvent.KEYCODE_CONTROLLER_MENU, InteractionManager.NACTION_HAND_TYPE.HAND_RIGHT))
            {
                bool EatBackKeyEvent = false;
                if (NibiruRemindBox.Instance && NibiruRemindBox.Instance.remindbox != null)
                {
                    NibiruRemindBox.Instance.ReleaseDestory();
                    EatBackKeyEvent = true;
                }

                if (NibiruShutDownBox.Instance && NibiruShutDownBox.Instance.Showing())
                {
                    NibiruShutDownBox.Instance.ReleaseDestory();
                    EatBackKeyEvent = true;
                }

                if (NibiruKeyBoard.Instance.isShown())
                {
                    NibiruKeyBoard.Instance.Dismiss();
                    EatBackKeyEvent = true;
                    Debug.Log("NibiruKeyBoard->Dismiss");
                }

                if (EatBackKeyEvent)
                {
                    Debug.Log("EatBackKeyEvent");
                    KeyStateHMD[CKeyEvent.KEYCODE_BACK] = CKeyEvent.ACTION_UP;
                    KeyStateController3DOF[CKeyEvent.KEYCODE_CONTROLLER_MENU]       = CKeyEvent.ACTION_UP;
                    KeyStateControllerNOLO_Left[CKeyEvent.KEYCODE_CONTROLLER_MENU]  = CKeyEvent.ACTION_UP;
                    KeyStateControllerNOLO_Right[CKeyEvent.KEYCODE_CONTROLLER_MENU] = CKeyEvent.ACTION_UP;

                    KeyStateHMD_Pre[CKeyEvent.KEYCODE_BACK] = CKeyEvent.ACTION_UP;
                    KeyStateController3DOF_Pre[CKeyEvent.KEYCODE_CONTROLLER_MENU]       = CKeyEvent.ACTION_UP;
                    KeyStateControllerNOLO_Left_Pre[CKeyEvent.KEYCODE_CONTROLLER_MENU]  = CKeyEvent.ACTION_UP;
                    KeyStateControllerNOLO_Right_Pre[CKeyEvent.KEYCODE_CONTROLLER_MENU] = CKeyEvent.ACTION_UP;
                }
            }

            bool IsTouchpadUp = GetControllerKeyUp(CKeyEvent.KEYCODE_CONTROLLER_TOUCHPAD) ||
                                GetControllerKeyUp(CKeyEvent.KEYCODE_CONTROLLER_TOUCHPAD,
                                                   InteractionManager.NACTION_HAND_TYPE.HAND_LEFT) ||
                                GetControllerKeyUp(CKeyEvent.KEYCODE_CONTROLLER_TOUCHPAD,
                                                   InteractionManager.NACTION_HAND_TYPE.HAND_RIGHT);

            if (IsTouchpadUp)
            {
                NxrViewer.Instance.Triggered = true;
            }
        }
Exemplo n.º 3
0
        public override void Process()
        {
            //when ime show unity is still running, disable input process
            if (TouchScreenKeyboard.visible)
            {
                NxrViewer.Instance.Triggered = false;
                pointerData.eligibleForClick = false;
                return;
            }

#if UNITY_ANDROID && !ANDROID_REMOTE_NRR
            if ((NxrPlayerCtrl.Instance.GamepadEnabled && NibiruTaskApi.IsQuatConn()) || ControllerAndroid.IsNoloConn())
#elif UNITY_STANDALONE_WIN || ANDROID_REMOTE_NRR
            if (NxrControllerHelper.IsLeftNoloControllerConnected || NxrControllerHelper.IsRightNoloControllerConnected)
            {
                CastRayFromController(true);
                if (isShowGaze)
                {
                    NxrViewer.Instance.GazeApi(GazeTag.Hide, "");
                    isShowGaze = false;
                }
            }
            else if (NxrControllerHelper.Is3DofControllerConnected)
#else
            if (true)
#endif
            {
                // 3dof/6dof controller
                CastRayFromGamepad();
                if (isShowGaze)
                {
                    NxrViewer.Instance.SwitchControllerMode(true);
                    isShowGaze = false;
                }
            }
            else
            {
                if (!isShowGaze)
                {
                    NxrViewer.Instance.SwitchControllerMode(false);
                    isShowGaze = true;
                    pointerData.pointerPress = null;
                    HandlePointerExitAndEnter(pointerData, null);
                }

                // Save the previous Game Object
                GameObject gazeObjectPrevious = GetCurrentGameObject();
                CastRayFromGaze();
                UpdateCurrentObject();
                UpdateReticle(gazeObjectPrevious);
            }


            if (!pointerData.eligibleForClick && NxrViewer.Instance.Triggered)
            {
                // New trigger action. ok键->click
                HandleTrigger();
                NxrViewer.Instance.Triggered = false;
            }
            else if (!NxrViewer.Instance.Triggered)
            {
                // Check if there is a pending click to handle.
                HandlePendingClick();
            }
            else if (pointerData.eligibleForClick && NxrViewer.Instance.Triggered)
            {
                NxrViewer.Instance.Triggered = false;
            }
        }
Exemplo n.º 4
0
        // Update is called once per frame
        void Update()
        {
#if UNITY_ANDROID
            if (Application.platform == RuntimePlatform.Android && (NxrPlayerCtrl.Instance.IsQuatConn() || ControllerAndroid.IsNoloConn()))
            {
                int[] KeyAction = null;
                if (InteractionManager.IsControllerConnected())
                {
                    KeyAction = InteractionManager.GetKeyAction();
                }
                else
                {
                    KeyAction = NibiruTaskApi.GetKeyAction();
                }
                if (KeyAction[CKeyEvent.KEYCODE_DPAD_CENTER] == 0)
                {
                    if (isCanUse)
                    {
                        isCanUse = false;
                        Invoke("CanKey", m_dwInputClip);
                        NibiruKeyBoard.Instance.OnPressEnterByQuat();
                    }
                }
            }
            Transform mTransform = NxrViewer.Instance.GetHead().transform;

            if (Input.GetKeyDown(KeyCode.I) || Input.GetKeyDown((KeyCode)10) || Input.GetKeyDown(KeyCode.JoystickButton0) || Input.GetMouseButtonDown(0))
            {
                if (isCanUse)
                {
                    isCanUse = false;
                    Invoke("CanKey", m_dwInputClip);
                    NibiruKeyBoard.Instance.OnPressEnterByCamera();
                }
            }
#else
            if (Input.GetMouseButtonDown(0))
            {
                if (isCanUse)
                {
                    isCanUse = false;
                    Invoke("CanKey", m_dwInputClip);
                    NibiruKeyBoard.Instance.OnPressEnterByCamera();
                    // OnPressEnterByMouse PC通过鼠标选中
                }
            }
#endif
        }