Example #1
0
        // Helper routine for creation of a stereo eye.
        private void CreateEye(NxrViewer.Eye eye)
        {
            string nm = name + (eye == NxrViewer.Eye.Left ? " Left" : " Right");

            NxrEye[] eyes    = GetComponentsInChildren <NxrEye>();
            NxrEye   mNxrEye = null;

            if (eyes != null && eyes.Length > 0)
            {
                foreach (NxrEye mEye in eyes)
                {
                    if (mEye.eye == eye)
                    {
                        mNxrEye = mEye;
                        break;
                    }
                }
            }
            // 创建新的
            if (mNxrEye == null)
            {
                GameObject go = new GameObject(nm);
                go.transform.SetParent(transform, false);
                go.AddComponent <Camera>().enabled = false;
                mNxrEye = go.AddComponent <NxrEye>();
            }

            if (NxrOverrideSettings.OnEyeCameraInitEvent != null)
            {
                NxrOverrideSettings.OnEyeCameraInitEvent(eye, mNxrEye.gameObject);
            }

            mNxrEye.Controller = this;
            mNxrEye.eye        = eye;
            mNxrEye.CopyCameraAndMakeSideBySide(this);
            mNxrEye.OnPostRenderListener += OnPostRenderListener;
            mNxrEye.OnPreRenderListener  += OnPreRenderListener;
            NxrViewer.Instance.eyes[eye == NxrViewer.Eye.Left ? 0 : 1] = mNxrEye;
            Debug.Log("CreateEye:" + nm + (eyes == null));
        }
Example #2
0
        void UpdateReticle(GameObject previousGazedObject)
        {
            if (pointerData == null)
            {
                return;
            }

            Camera     camera = pointerData.enterEventCamera;         // Get the camera
            Vector3    intersectionPosition = GetIntersectionPosition();
            GameObject gazeObject           = GetCurrentGameObject(); // Get the gaze target

            if (gazeObject != null && NxrOverrideSettings.OnGazeEvent != null)
            {
                NxrOverrideSettings.OnGazeEvent(gazeObject);
            }

            float gazeZ = NxrGlobal.defaultGazeDistance;

            if (gazeObject != null)
            {
                gazeZ = intersectionPosition
                        .z; //  && gazeObject.transform != null &&gazeObject.transform.position.z != 0gazeObject.transform.position.z;
            }

            if (lastGazeZ != gazeZ)
            {
                lastGazeZ = gazeZ;
                // 点
                NxrViewer.Instance.GazeApi(Nxr.Internal.GazeTag.Set_Distance, (-1 * gazeZ).ToString());
            }

            // Debug.Log("--------gaze object " + (gazeObject == null ?  "" : gazeObject.name));

            // 记录距离
            NxrGlobal.focusObjectDistance = (int)(Mathf.Abs(gazeZ) * 100) / 100.0f;

            if (gazePointer == null)
            {
                if (gazeObject != null)
                {
                    INxrGazeResponder mGazeResponder = gazeObject.GetComponent <INxrGazeResponder>();
                    if (mGazeResponder != null)
                    {
                        mGazeResponder.OnUpdateIntersectionPosition(intersectionPosition);
                    }
                }
                else
                {
                    // Debug.Log("--------------------------gazePointer && gazeObject is null !!!");
                }

                return;
            }

            bool isInteractive = pointerData.pointerPress == gazeObject ||
                                 ExecuteEvents.GetEventHandler <ISelectHandler>(gazeObject) != null;

            if (gazeObject != null && gazeObject != previousGazedObject)
            {
                // Debug.LogError("Enter GazeObject=" + gazeObject.name);
                if (previousGazedObject != null)
                {
                    // Debug.LogError("Exit GazeObject=" + previousGazedObject.name);
                }
            }
            else if (gazeObject == null && previousGazedObject != null)
            {
                // Debug.LogError("Exit GazeObject=" + previousGazedObject.name);
            }

            if (gazeObject == previousGazedObject)
            {
                if (gazeObject != null && gazePointer != null)
                {
                    gazePointer.OnGazeStay(camera, gazeObject, intersectionPosition, isInteractive);
                    INxrGazeResponder mGazeResponder = gazeObject.GetComponent <INxrGazeResponder>();
                    if (mGazeResponder != null)
                    {
                        mGazeResponder.OnUpdateIntersectionPosition(intersectionPosition);
                    }
                }
            }
            else
            {
                if (previousGazedObject != null && gazePointer != null)
                {
                    gazePointer.OnGazeExit(camera, previousGazedObject);
                    if (NxrViewer.Instance != null)
                    {
                        if (NxrViewer.Instance.HeadControl == HeadControl.Hover)
                        {
                            if (NxrHeadControl.baseEventData != null)
                            {
                                NxrHeadControl.baseEventData   = null;
                                NxrHeadControl.eventGameObject = null;
                            }
                        }
                    }
                }

                if (gazeObject != null && gazePointer != null)
                {
                    gazePointer.OnGazeStart(camera, gazeObject, intersectionPosition, isInteractive);
                    if (NxrViewer.Instance != null)
                    {
                        if (NxrViewer.Instance.HeadControl == HeadControl.Hover)
                        {
                            NxrHeadControl.baseEventData = pointerData;
                        }
                    }
                }
            }
        }