コード例 #1
0
    void Update()
    {
        if (Input.touchCount == 1)                          //一个手指触摸屏幕
        {
            if (Input.touches[0].phase == TouchPhase.Began) //开始触屏
            {
                newPicovrTriggered = true;
            }
        }
        else
        if (Input.GetKeyDown(KeyCode.JoystickButton0))
        {
            newPicovrTriggered = true;
        }

        if (pvr_UnitySDKSensor != null)
        {
            pvr_UnitySDKSensor.SensorUpdate();
        }


        picovrTriggered    = newPicovrTriggered;
        newPicovrTriggered = false;
    }
コード例 #2
0
    void Update()
    {
        if (Input.touchCount == 1)                          //一个手指触摸屏幕
        {
            if (Input.touches[0].phase == TouchPhase.Began) //开始触屏
            {
                newPicovrTriggered = true;
            }
        }
        else
        if (Input.GetKeyDown(KeyCode.JoystickButton0))
        {
            newPicovrTriggered = true;
        }

        if (pvr_UnitySDKSensor != null)
        {
            pvr_UnitySDKSensor.SensorUpdate();
        }

        picovrTriggered    = newPicovrTriggered;
        newPicovrTriggered = false;
        if (!isViewerLogicFlow)
        {
#if !UNITY_EDITOR && UNITY_ANDROID
            //safe toast 跟随
            if (safeToast.activeSelf)
            {
                safeToast.transform.localPosition = sdk.HeadPose.Position;
                safeToast.transform.localRotation = Quaternion.Euler(0, SDK.HeadPose.Orientation.eulerAngles.y, 0);
            }
            //reset panel 跟随
            if (resetPanel.activeSelf)
            {
                resetPanel.transform.localPosition = SDK.HeadPose.Position;
                resetPanel.transform.localRotation = Quaternion.Euler(0, SDK.HeadPose.Orientation.eulerAngles.y, 0);
            }
            //safe panel1 跟随
            if (safePanel1.activeSelf)
            {
                safePanel1.transform.localPosition = sdk.HeadPose.Position;
                safePanel1.transform.localRotation = Quaternion.Euler(0, SDK.HeadPose.Orientation.eulerAngles.y, 0);
            }
            //safe panel2 跟随
            if (safePanel2.activeSelf)
            {
                safePanel2.transform.localPosition = SDK.HeadPose.Position;
                safePanel2.transform.localRotation = Quaternion.Euler(0, SDK.HeadPose.Orientation.eulerAngles.y, 0);
            }
            //安全围栏
            if (HeadDofNum == HeadDofNum.SixDof)
            {
                //default 0.8m
                if (DefaultRange)
                {
                    if (isHasController)
                    {
                        if (Math.Abs(HeadPose.Position.x) > 0.56f || Math.Abs(HeadPose.Position.z) > 0.56f || Math.Abs(Controller.UPvr_GetControllerPOS(0).x) > 0.8f || Math.Abs(Controller.UPvr_GetControllerPOS(0).z) > 0.8f || Math.Abs(Controller.UPvr_GetControllerPOS(1).x) > 0.8f || Math.Abs(Controller.UPvr_GetControllerPOS(1).z) > 0.8f)
                        {
                            safeArea.transform.localScale = new Vector3(1.6f, 1.6f, 1.6f);
                            safeArea.SetActive(true);
                        }
                        else
                        {
                            safeArea.SetActive(false);
                        }
                    }
                    else
                    {
                        if (Math.Abs(HeadPose.Position.x) > 0.56f || Math.Abs(HeadPose.Position.z) > 0.56f)
                        {
                            safeArea.transform.localScale = new Vector3(1.6f, 1.6f, 1.6f);
                            safeArea.SetActive(true);
                        }
                        else
                        {
                            safeArea.SetActive(false);
                        }
                    }

                    if (Math.Abs(HeadPose.Position.x) > 0.8f || Math.Abs(HeadPose.Position.z) > 0.8f)
                    {
                        if (!safeToast.activeSelf)
                        {
                            safeToast.transform.Find("Panel").GetComponent <Canvas>().sortingOrder = resetPanel.transform.Find("Panel").GetComponent <Canvas>().sortingOrder + 1;
                            safeToast.SetActive(true);
                        }
                    }
                    else
                    {
                        if (safeToast.activeSelf)
                        {
                            safeToast.SetActive(false);
                            safeToast.transform.Find("Panel").GetComponent <Canvas>().sortingOrder = 10001;
                        }
                    }
                }
                else
                {
                    if (isHasController)
                    {
                        if (Math.Abs(HeadPose.Position.x) > (0.7f * CustomRange) || Math.Abs(HeadPose.Position.z) > (0.7f * CustomRange) || Math.Abs(Controller.UPvr_GetControllerPOS(0).x) > CustomRange || Math.Abs(Controller.UPvr_GetControllerPOS(0).z) > CustomRange || Math.Abs(Controller.UPvr_GetControllerPOS(1).x) > CustomRange || Math.Abs(Controller.UPvr_GetControllerPOS(1).z) > CustomRange)
                        {
                            safeArea.transform.localScale = new Vector3(CustomRange / 0.5f, CustomRange / 0.5f, CustomRange / 0.5f);
                            safeArea.SetActive(true);
                        }
                        else
                        {
                            safeArea.SetActive(false);
                        }
                    }
                    else
                    {
                        if (Math.Abs(HeadPose.Position.x) > (0.7f * CustomRange) || Math.Abs(HeadPose.Position.z) > (0.7f * CustomRange))
                        {
                            safeArea.transform.localScale =
                                new Vector3(CustomRange / 0.5f, CustomRange / 0.5f, CustomRange / 0.5f);
                            safeArea.SetActive(true);
                        }
                        else
                        {
                            safeArea.SetActive(false);
                        }
                    }
                    if (Math.Abs(HeadPose.Position.x) > CustomRange || Math.Abs(HeadPose.Position.z) > CustomRange)
                    {
                        if (!safeToast.activeSelf)
                        {
                            safeToast.transform.Find("Panel").GetComponent <Canvas>().sortingOrder = resetPanel.transform.Find("Panel").GetComponent <Canvas>().sortingOrder + 1;
                            safeToast.SetActive(true);
                        }
                    }
                    else
                    {
                        if (safeToast.activeSelf)
                        {
                            safeToast.SetActive(false);
                            safeToast.transform.Find("Panel").GetComponent <Canvas>().sortingOrder = 10001;
                        }
                    }
                }
            }
#endif
        }
    }
コード例 #3
0
    void Update()
    {
        if (Input.touchCount == 1)
        {
            if (Input.touches[0].phase == TouchPhase.Began)
            {
                newPicovrTriggered = true;
            }
        }
        else
        if (Input.GetKeyDown(KeyCode.JoystickButton0))
        {
            newPicovrTriggered = true;
        }

        if (pvr_UnitySDKSensor != null)
        {
            pvr_UnitySDKSensor.SensorUpdate();
        }

        if (!IsViewerLogicFlow)
        {
#if !UNITY_EDITOR && UNITY_ANDROID
            if (isHasController && (Controller.UPvr_GetControllerState(0) == ControllerState.Connected || Controller.UPvr_GetControllerState(1) == ControllerState.Connected))
            {
                if (DefaultRange)
                {
                    if (Application.systemLanguage == SystemLanguage.Chinese ||
                        Application.systemLanguage == SystemLanguage.ChineseSimplified)
                    {
                        safeToast.transform.Find("Panel/Text").GetComponent <Text>().text =
                            "若需重置位置,请确保周围半径0.8米范围内没有障碍物,将手柄指向前方,长按【Home键】";
                    }
                    else
                    {
                        safeToast.transform.Find("Panel/Text").GetComponent <Text>().text =
                            "To reset safe zone,please insure there have no obstacles in the radius of 0.8 meters,then point the controller forward,long press on the 【home button】";
                    }
                }
                else
                {
                    if (Application.systemLanguage == SystemLanguage.Chinese ||
                        Application.systemLanguage == SystemLanguage.ChineseSimplified)
                    {
                        safeToast.transform.Find("Panel/Text").GetComponent <Text>().text =
                            "若需重置位置,请确保周围半径" + CustomRange + "米范围内没有障碍物,将手柄指向前方,长按【Home键】";
                    }
                    else
                    {
                        safeToast.transform.Find("Panel/Text").GetComponent <Text>().text =
                            "To reset safe zone,please insure there have no obstacles in the radius of " + CustomRange + " meters,then point the controller forward,long press on the 【home button】";
                    }
                }

                if (Input.GetKeyDown(KeyCode.JoystickButton0) || Controller.UPvr_GetKeyDown(0, Pvr_KeyCode.TOUCHPAD) || Controller.UPvr_GetKeyDown(1, Pvr_KeyCode.TOUCHPAD))
                {
                    if (safePanel1.activeSelf)
                    {
                        safePanel1.SetActive(false);
                    }
                    if (resetPanel.activeSelf)
                    {
                        resetPanel.SetActive(false);
                        pvr_UnitySDKSensor.OptionalResetUnitySDKSensor(0, 1);
                    }
                }
            }
            else
            {
                if (DefaultRange)
                {
                    if (Application.systemLanguage == SystemLanguage.Chinese ||
                        Application.systemLanguage == SystemLanguage.ChineseSimplified)
                    {
                        safeToast.transform.Find("Panel/Text").GetComponent <Text>().text =
                            "若需重置位置,请确保周围半径0.8米范围内没有障碍物,长按头戴【Home键】";
                    }
                    else
                    {
                        safeToast.transform.Find("Panel/Text").GetComponent <Text>().text =
                            "To reset safe zone,please insure there have no obstacles in the radius of 0.8 meters,then long press on the 【home button】 on headset";
                    }
                }
                else
                {
                    if (Application.systemLanguage == SystemLanguage.Chinese ||
                        Application.systemLanguage == SystemLanguage.ChineseSimplified)
                    {
                        safeToast.transform.Find("Panel/Text").GetComponent <Text>().text =
                            "若需重置位置,请确保周围半径" + CustomRange + "米范围内没有障碍物,长按头戴【Home键】";
                    }
                    else
                    {
                        safeToast.transform.Find("Panel/Text").GetComponent <Text>().text =
                            "To reset safe zone,please insure there have no obstacles in the radius of " + CustomRange + " meters,then long press on the 【home button】 on headset";
                    }
                }
                if (Input.GetKeyDown(KeyCode.JoystickButton0))
                {
                    if (safePanel1.activeSelf)
                    {
                        safePanel1.SetActive(false);
                    }
                    if (resetPanel.activeSelf)
                    {
                        resetPanel.SetActive(false);
                        pvr_UnitySDKSensor.OptionalResetUnitySDKSensor(1, 1);
                    }
                }
            }
#endif
        }

        picovrTriggered    = newPicovrTriggered;
        newPicovrTriggered = false;
        if (!isViewerLogicFlow)
        {
#if !UNITY_EDITOR && UNITY_ANDROID
            if (safeToast.activeSelf)
            {
                safeToast.transform.localPosition = SDK.HeadPose.Position;
                safeToast.transform.localRotation = Quaternion.Euler(0, SDK.HeadPose.Orientation.eulerAngles.y, 0);
            }

            if (resetPanel.activeSelf)
            {
                resetPanel.transform.localPosition = SDK.HeadPose.Position;
                resetPanel.transform.localRotation = Quaternion.Euler(0, SDK.HeadPose.Orientation.eulerAngles.y, 0);
            }

            if (safePanel1.activeSelf)
            {
                safePanel1.transform.localPosition = SDK.HeadPose.Position;
                safePanel1.transform.localRotation = Quaternion.Euler(0, SDK.HeadPose.Orientation.eulerAngles.y, 0);
            }

            if (safePanel2.activeSelf)
            {
                safePanel2.transform.localPosition = SDK.HeadPose.Position;
                safePanel2.transform.localRotation = Quaternion.Euler(0, SDK.HeadPose.Orientation.eulerAngles.y, 0);
            }

            if (HeadDofNum == HeadDofNum.SixDof)
            {
                //default 0.8m
                if (DefaultRange)
                {
                    if (isHasController)
                    {
                        if (Mathf.Sqrt(Mathf.Pow(HeadPose.Position.x, 2.0f) + Mathf.Pow(HeadPose.Position.z, 2.0f)) > 0.56f || Mathf.Sqrt(Mathf.Pow(Controller.UPvr_GetControllerPOS(0).x, 2.0f) + Mathf.Pow(Controller.UPvr_GetControllerPOS(0).z, 2.0f)) > 0.8f || Mathf.Sqrt(Mathf.Pow(Controller.UPvr_GetControllerPOS(1).x, 2.0f) + Mathf.Pow(Controller.UPvr_GetControllerPOS(1).z, 2.0f)) > 0.8f)
                        {
                            safeArea.transform.localScale = new Vector3(1.6f, 1.6f, 1.6f);
                            safeArea.SetActive(true);
                        }
                        else
                        {
                            safeArea.SetActive(false);
                        }
                    }
                    else
                    {
                        if (Mathf.Sqrt(Mathf.Pow(HeadPose.Position.x, 2.0f) + Mathf.Pow(HeadPose.Position.z, 2.0f)) > 0.56f)
                        {
                            safeArea.transform.localScale = new Vector3(1.6f, 1.6f, 1.6f);
                            safeArea.SetActive(true);
                        }
                        else
                        {
                            safeArea.SetActive(false);
                        }
                    }

                    if (Mathf.Sqrt(Mathf.Pow(HeadPose.Position.x, 2.0f) + Mathf.Pow(HeadPose.Position.z, 2.0f)) > 0.8f)
                    {
                        if (!safeToast.activeSelf)
                        {
                            safeToast.transform.Find("Panel").GetComponent <Canvas>().sortingOrder = resetPanel.transform.Find("Panel").GetComponent <Canvas>().sortingOrder + 1;
                            safeToast.SetActive(true);
                        }
                    }
                    else
                    {
                        if (safeToast.activeSelf)
                        {
                            safeToast.SetActive(false);
                            safeToast.transform.Find("Panel").GetComponent <Canvas>().sortingOrder = 10001;
                        }
                    }
                }
                else
                {
                    if (isHasController)
                    {
                        if (Mathf.Sqrt(Mathf.Pow(HeadPose.Position.x, 2.0f) + Mathf.Pow(HeadPose.Position.z, 2.0f)) > (0.7f * CustomRange) || Mathf.Sqrt(Mathf.Pow(Controller.UPvr_GetControllerPOS(0).x, 2.0f) + Mathf.Pow(Controller.UPvr_GetControllerPOS(0).z, 2.0f)) > CustomRange || Mathf.Sqrt(Mathf.Pow(Controller.UPvr_GetControllerPOS(1).x, 2.0f) + Mathf.Pow(Controller.UPvr_GetControllerPOS(1).z, 2.0f)) > CustomRange)
                        {
                            safeArea.transform.localScale = new Vector3(CustomRange / 0.5f, CustomRange / 0.5f, CustomRange / 0.5f);
                            safeArea.SetActive(true);
                        }
                        else
                        {
                            safeArea.SetActive(false);
                        }
                    }
                    else
                    {
                        if (Mathf.Sqrt(Mathf.Pow(HeadPose.Position.x, 2.0f) + Mathf.Pow(HeadPose.Position.z, 2.0f)) > (0.7f * CustomRange))
                        {
                            safeArea.transform.localScale =
                                new Vector3(CustomRange / 0.5f, CustomRange / 0.5f, CustomRange / 0.5f);
                            safeArea.SetActive(true);
                        }
                        else
                        {
                            safeArea.SetActive(false);
                        }
                    }
                    if (Mathf.Sqrt(Mathf.Pow(HeadPose.Position.x, 2.0f) + Mathf.Pow(HeadPose.Position.z, 2.0f)) > CustomRange)
                    {
                        if (!safeToast.activeSelf)
                        {
                            safeToast.transform.Find("Panel").GetComponent <Canvas>().sortingOrder = resetPanel.transform.Find("Panel").GetComponent <Canvas>().sortingOrder + 1;
                            safeToast.SetActive(true);
                        }
                    }
                    else
                    {
                        if (safeToast.activeSelf)
                        {
                            safeToast.SetActive(false);
                            safeToast.transform.Find("Panel").GetComponent <Canvas>().sortingOrder = 10001;
                        }
                    }
                }
            }
#endif
        }
    }