Esempio n. 1
0
        public override void UpdateState()
        {
            Quaternion rot = Quaternion.identity;

            if (Input.GetKey(KeyCode.LeftAlt) || Input.GetKey(KeyCode.RightAlt))
            {
                mouseX += Input.GetAxis("Mouse X") * 5;
                if (mouseX <= -180)
                {
                    mouseX += 360;
                }
                else if (mouseX > 180)
                {
                    mouseX -= 360;
                }
                mouseY -= Input.GetAxis("Mouse Y") * 2.4f;
                mouseY  = Mathf.Clamp(mouseY, -85, 85);
            }
            else if (Input.GetKey(KeyCode.LeftControl) || Input.GetKey(KeyCode.RightControl))
            {
                mouseZ += Input.GetAxis("Mouse X") * 5;
                mouseZ  = Mathf.Clamp(mouseZ, -85, 85);
            }

            bool IsNeedUpdatePose = false;

            if (Application.isEditor && NxrViewer.Instance.RemoteDebug)
            {
                if (remoteQaut.w != 0)
                {
                    rot = remoteQaut;
                    IsNeedUpdatePose = true;
                }
            }

            if (mouseX != 0 || mouseY != 0 || mouseZ != 0)
            {
                rot = Quaternion.Euler(mouseY, mouseX, mouseZ);
                IsNeedUpdatePose = true;
            }

            if (IsNeedUpdatePose)
            {
                headPose.Set(Vector3.zero, rot);
            }

#if UNITY_STANDALONE_WIN || ANDROID_REMOTE_NRR
            // ÊÖ±ú¼üֵ״̬
            if (NxrInstantNativeApi.Inited)
            {
                NxrInstantNativeApi.Holoever_Pose pose = NxrInstantNativeApi.GetPoseByDeviceType(NxrInstantNativeApi.HoloeverDeviceType.Hmd);
                if (pose.rotation.w == 0)
                {
                    pose.rotation.w = 1;
                }
                this.headPose.Set(pose.position, new Quaternion(pose.rotation.x, pose.rotation.y, -pose.rotation.z, -pose.rotation.w));
            }
#endif
            isHeadPoseUpdated = true;
        }
Esempio n. 2
0
        // Update is called once per frame
        void Update()
        {
#if UNITY_ANDROID //&& !UNITY_EDITOR
            if (!NxrViewer.Instance.IsWinPlatform && !isGamePad)
            {
                // Android/NOLO
                int  noloType    = GetNoloType();
                int  handType    = noloType == (int)CDevice.NOLO_TYPE.LEFT ? (int)InteractionManager.NACTION_HAND_TYPE.HAND_LEFT : (int)InteractionManager.NACTION_HAND_TYPE.HAND_RIGHT;
                bool isConnected = false;
                if (InteractionManager.IsInteractionSDKEnabled())
                {
                    isConnected = InteractionManager.IsSixDofControllerConnected(handType);
                }
                else
                {
                    isConnected = ControllerAndroid.isDeviceConn(noloType);
                }

                if (DebugInEditor)
                {
                    isConnected = true;
                }

                if (_currentStates.connectStatus == 0 && isConnected)
                {
                    NxrViewer.Instance.SwitchControllerMode(true);
                    _currentStates.connectStatus = 1;
                    NxrPlayerCtrl mNxrPlayerCtrl = NxrPlayerCtrl.Instance;
                    if (mNxrPlayerCtrl != null)
                    {
                        // 关闭3dof手柄显示
                        mNxrPlayerCtrl.GamepadEnabled = false;
                        // 关闭白点显示
                    }
                }
                else if (_currentStates.connectStatus == 1 && !isConnected)
                {
                    _currentStates.connectStatus = 0;
                }

                //Debug.Log("status="+_currentStates.connectStatus + ", " + deviceType.ToString() + ","
                //    + ControllerAndroid.isDeviceConn((int) CDevice.NOLO_TYPE.LEFT) + ", " + ControllerAndroid.isDeviceConn((int)CDevice.NOLO_TYPE.RIGHT));

                if (!IsConneted() && controllerModel != null && controllerModel.gameObject.activeSelf)
                {
                    if (controllerPower != null)
                    {
                        controllerPower.gameObject.SetActive(false);
                    }
                    controllerModel.gameObject.SetActive(false);
                    laserPointer.holder.SetActive(false);
                    NxrControllerHelper.ControllerRaycastObject = null;
                    Debug.Log("controllerModel Dismiss " + deviceType + "," + controllerModel.gameObject.activeSelf);
                }
                else if (IsConneted() && controllerModel != null && !controllerModel.gameObject.activeSelf)
                {
                    if (controllerPower != null)
                    {
                        controllerPower.gameObject.SetActive(true);
                    }
                    controllerModel.gameObject.SetActive(true);
                    laserPointer.holder.SetActive(true);
                    Debug.Log("controllerModel Show " + deviceType);
                }

                if (GetButtonUp(ButtonID.InternalTrigger))
                {
                    NxrSDKApi.Instance.SixDofControllerPrimaryDeviceType = deviceType;
                    Debug.Log("IsPrimaryControllerHand " + deviceType.ToString());
                }

                if (laserPointer != null && controllerModel != null)
                {
                    if (NxrSDKApi.Instance.SixDofControllerPrimaryDeviceType != deviceType)
                    {
                        // 非主手柄,隐藏射线
                        laserPointer.holder.SetActive(false);
                    }
                    else
                    {
                        laserPointer.holder.SetActive(controllerModel.gameObject.activeSelf);
                    }
                }

                if (IsConneted())
                {
                    processControllerKeyEvent(noloType);
                    float[] poseData = new float[8];
                    if (InteractionManager.IsSixDofControllerConnected(handType))
                    {
                        float[] pose = InteractionManager.GetControllerPose((InteractionManager.NACTION_HAND_TYPE)handType);
                        poseData[1] = pose[4];
                        poseData[2] = pose[5];
                        poseData[3] = pose[6];
                        for (int i = 0; i < 4; i++)
                        {
                            poseData[4 + i] = pose[i];
                        }
                    }
                    else
                    {
                        poseData = ControllerAndroid.getCPoseEvent(noloType, 1);
                    }

                    if (NxrViewer.Instance.SixDofMode == SixDofMode.Head_3Dof_Ctrl_6Dof)
                    {
                        Vector3 HeadPosition = NxrSDKApi.Instance.HeadPosition;
                        // Debug.LogError(noloType + ".NOLO Controller Y: " + poseData[2] + "/HeadY=" + HeadPosition.y);
                        poseData[1] = poseData[1] - HeadPosition.x;
                        poseData[2] = poseData[2] - HeadPosition.y;
                        poseData[3] = poseData[3] - HeadPosition.z;
                    }
                    else if (NxrViewer.Instance.SixDofMode == SixDofMode.Head_3Dof_Ctrl_3Dof)
                    {
                        var factor  = handType == (int)InteractionManager.NACTION_HAND_TYPE.HAND_LEFT ? -1 : 1;
                        var headPos = NxrViewer.Instance.GetHead().transform.localPosition;
                        var pos     = new Vector3(headPos.x + 0.25f * factor, headPos.y - 0.6f, headPos.z + 0.5f);
                        poseData[1] = pos.x;
                        poseData[2] = pos.y;
                        poseData[3] = pos.z;
                    }

                    transform.localPosition = new Vector3(poseData[1], poseData[2], poseData[3]);
                    transform.localRotation = new Quaternion(poseData[4], poseData[5], poseData[6], poseData[7]);
                }
            }
#endif

#if UNITY_STANDALONE_WIN
            if (NxrInstantNativeApi.Inited)
            {
                _prevStates    = _currentStates;
                _currentStates = NxrInstantNativeApi.GetControllerStates(deviceType);
                if (isGamePad)
                {
                    // 3dof手柄左右手模式切换
                    if (!IsConneted())
                    {
                        _currentStates = NxrInstantNativeApi.GetControllerStates(NxrInstantNativeApi.HoloeverDeviceType.LeftController);
                        if (!IsConneted())
                        {
                            deviceType = NxrInstantNativeApi.HoloeverDeviceType.RightController;
                        }
                        else
                        {
                            NxrControllerHelper.HandMode3DOF = NxrControllerHelper.LEFT_HAND_MODE;
                            deviceType = NxrInstantNativeApi.HoloeverDeviceType.LeftController;
                            Debug.Log("Current 3dof HandMode is Left !!!");
                        }
                    }
                }

                if (!IsConneted() && controllerModel != null && controllerModel.gameObject.activeSelf)
                {
                    controllerModel.gameObject.SetActive(false);
                    laserPointer.holder.SetActive(false);
                    if (deviceType == NxrInstantNativeApi.HoloeverDeviceType.LeftController)
                    {
                        NxrControllerHelper.IsLeftNoloControllerConnected = false;
                    }
                    else if (deviceType == NxrInstantNativeApi.HoloeverDeviceType.RightController)
                    {
                        NxrControllerHelper.IsRightNoloControllerConnected = false;
                    }
                    Debug.Log("controllerModel Dismiss " + deviceType + "," + controllerModel.gameObject.activeSelf);
                }
                else if (IsConneted() && controllerModel != null && !controllerModel.gameObject.activeSelf)
                {
                    controllerModel.gameObject.SetActive(true);
                    laserPointer.holder.SetActive(true);

                    if (NxrControllerHelper.ControllerType == (int)NxrInstantNativeApi.HoloeverControllerId.NOLO)
                    {
                        if (deviceType == NxrInstantNativeApi.HoloeverDeviceType.LeftController)
                        {
                            NxrControllerHelper.IsLeftNoloControllerConnected = true;
                        }
                        else if (deviceType == NxrInstantNativeApi.HoloeverDeviceType.RightController)
                        {
                            NxrControllerHelper.IsRightNoloControllerConnected = true;
                        }
                    }
                    Debug.Log("controllerModel Show " + deviceType);
                }
                else if (!IsConneted() && isGamePad && NxrControllerHelper.Is3DofControllerConnected)
                {
                    NxrControllerHelper.Is3DofControllerConnected = false;
                    Debug.Log("Controller 3dof Dismiss.");
                }
                else if (IsConneted() && isGamePad && !NxrControllerHelper.Is3DofControllerConnected)
                {
                    if (NxrControllerHelper.ControllerType == (int)NxrInstantNativeApi.HoloeverControllerId.NORMAL_3DOF)
                    {
                        NxrControllerHelper.Is3DofControllerConnected = true;
                    }
                    Debug.Log("Controller 3dof Show." + NxrControllerHelper.ControllerType);
                }

                if (!isGamePad)
                {
                    NxrInstantNativeApi.Holoever_Pose pose = NxrInstantNativeApi.GetPoseByDeviceType(deviceType);
                    // NOLO 非3DOF
                    transform.localPosition = pose.position;
                    transform.localRotation = new Quaternion(pose.rotation.x, pose.rotation.y, pose.rotation.z, pose.rotation.w);
                }
            }
#endif
        }