示例#1
0
        public void OnDisable()
        {
            if (viewDisabled != null)
            {
                viewDisabled();
            }

#if UNITY_2017_2_OR_NEWER
            XRSettings.enabled = false;
#endif

            EditorPrefs.SetBool(k_ShowDeviceView, m_ShowDeviceView);
            EditorPrefs.SetBool(k_UseCustomPreviewCamera, m_UseCustomPreviewCamera);

            SetOtherViewsEnabled(true);

            if (m_CameraRig)
            {
                DestroyImmediate(m_CameraRig.gameObject, true);
            }

            Assert.IsNotNull(s_ActiveView, "EditorXR should have an active view");
            s_ActiveView = null;

            if (s_ExistingSceneMainCamera)
            {
                s_ExistingSceneMainCamera.enabled = s_ExistingSceneMainCameraEnabledState;
            }
        }
示例#2
0
        public void Setup()
        {
#if UNITY_EDITOR
            SetupMonoScriptTypeNames();
#endif

            EditorVR.DefaultMenu          = GetTypeSafe(m_DefaultMainMenuName);
            EditorVR.DefaultAlternateMenu = GetTypeSafe(m_DefaultAlternateMenuName);

            if (m_DefaultToolStackNames != null)
            {
                EditorVR.DefaultTools = m_DefaultToolStackNames.Select(GetTypeSafe).ToArray();
            }

            if (m_HiddenTypeNames != null)
            {
                EditorVR.HiddenTypes = m_HiddenTypeNames.Select(GetTypeSafe).ToArray();
            }

            s_Instance = m_Instance = ObjectUtils.CreateGameObjectWithComponent <EditorVR>();

            if (Application.isPlaying)
            {
                var camera    = CameraUtils.GetMainCamera();
                var cameraRig = m_Instance.transform;
                VRView.CreateCameraRig(ref camera, ref cameraRig);
            }

            XRSettings.eyeTextureResolutionScale = m_RenderScale;
        }
示例#3
0
        public void OnEnable()
        {
            Assert.IsNull(s_ActiveView, "Only one EditorXR should be active");

            autoRepaintOnSceneChange = true;
            s_ActiveView             = this;
            CreateCameraRig(ref m_Camera, ref m_CameraRig);

            m_ShowDeviceView         = EditorPrefs.GetBool(k_ShowDeviceView, false);
            m_UseCustomPreviewCamera = EditorPrefs.GetBool(k_UseCustomPreviewCamera, false);

            // Disable other views to increase rendering performance for EditorVR
            SetOtherViewsEnabled(false);

            // VRSettings.enabled latches the reference pose for the current camera
            var currentCamera = Camera.current;

            Camera.SetupCurrent(m_Camera);
#if UNITY_2017_2_OR_NEWER
            XRSettings.enabled = true;
#endif
            Camera.SetupCurrent(currentCamera);

            if (viewEnabled != null)
            {
                viewEnabled();
            }
        }
示例#4
0
        public void OnEnable()
        {
            EditorApplication.playmodeStateChanged += OnPlaymodeStateChanged;

            Assert.IsNull(s_ActiveView, "Only one EditorVR should be active");

            autoRepaintOnSceneChange = true;
            s_ActiveView             = this;

            GameObject cameraGO = EditorUtility.CreateGameObjectWithHideFlags("VRCamera", HideFlags.HideAndDontSave, typeof(Camera));

            m_Camera = cameraGO.GetComponent <Camera>();
            m_Camera.useOcclusionCulling = false;
            m_Camera.enabled             = false;
            m_Camera.cameraType          = CameraType.VR;

            GameObject rigGO = EditorUtility.CreateGameObjectWithHideFlags("VRCameraRig", HideFlags.HideAndDontSave, typeof(EditorMonoBehaviour));

            m_CameraRig = rigGO.transform;
            m_Camera.transform.parent = m_CameraRig;
            m_Camera.nearClipPlane    = 0.01f;
            m_Camera.farClipPlane     = 1000f;

            // Generally, we want to be at a standing height, so default to that
            const float kHeadHeight = 1.7f;
            Vector3     position    = m_CameraRig.position;

            position.y           = kHeadHeight;
            m_CameraRig.position = position;
            m_CameraRig.rotation = Quaternion.identity;

            m_ShowDeviceView         = EditorPrefs.GetBool(k_ShowDeviceView, false);
            m_UseCustomPreviewCamera = EditorPrefs.GetBool(k_UseCustomPreviewCamera, false);

            // Disable other views to increase rendering performance for EditorVR
            SetOtherViewsEnabled(false);

            VRSettings.StartRenderingToDevice();
            InputTracking.Recenter();

            // HACK: Fix VRSettings.enabled or some other API to check for missing HMD
            m_VRInitialized = false;
#if ENABLE_OVR_INPUT
            m_VRInitialized |= OVRPlugin.initialized;
#endif
#if ENABLE_STEAMVR_INPUT
            m_VRInitialized |= (OpenVR.IsHmdPresent() && OpenVR.Compositor != null);
#endif

            if (viewEnabled != null)
            {
                viewEnabled();
            }
        }
示例#5
0
        void OnVRViewGUI(VRView view)
        {
            var position = view.position;

            m_EditingContextPopupRect.y = position.height - m_EditingContextPopupRect.height;
            m_EditingContextPopupRect.x = position.width - m_EditingContextPopupRect.width;

            m_SelectedContextIndex = EditorGUI.Popup(m_EditingContextPopupRect, string.Empty, m_SelectedContextIndex, m_ContextNames);
            if (GUI.changed)
            {
                SetEditingContext(s_AvailableContexts[m_SelectedContextIndex]);
                GUIUtility.ExitGUI();
            }
        }
示例#6
0
文件: VRView.cs 项目: qipa/EditorVR
        public void OnEnable()
        {
            EditorApplication.playmodeStateChanged += OnPlaymodeStateChanged;

            Assert.IsNull(s_ActiveView, "Only one EditorVR should be active");

            autoRepaintOnSceneChange = true;
            s_ActiveView             = this;

            GameObject cameraGO = EditorUtility.CreateGameObjectWithHideFlags("VRCamera", HideFlags.HideAndDontSave, typeof(Camera));

            m_Camera = cameraGO.GetComponent <Camera>();
            m_Camera.useOcclusionCulling = false;
            m_Camera.enabled             = false;
            m_Camera.cameraType          = CameraType.VR;

            GameObject rigGO = EditorUtility.CreateGameObjectWithHideFlags("VRCameraRig", HideFlags.HideAndDontSave, typeof(EditorMonoBehaviour));

            m_CameraRig = rigGO.transform;
            m_Camera.transform.parent = m_CameraRig;
            m_Camera.nearClipPlane    = 0.01f;
            m_Camera.farClipPlane     = 1000f;

            // Generally, we want to be at a standing height, so default to that
            const float kHeadHeight = 1.7f;
            Vector3     position    = m_CameraRig.position;

            position.y           = kHeadHeight;
            m_CameraRig.position = position;
            m_CameraRig.rotation = Quaternion.identity;

            m_ShowDeviceView         = EditorPrefs.GetBool(k_ShowDeviceView, false);
            m_UseCustomPreviewCamera = EditorPrefs.GetBool(k_UseCustomPreviewCamera, false);

            // Disable other views to increase rendering performance for EditorVR
            SetOtherViewsEnabled(false);

            // VRSettings.enabled latches the reference pose for the current camera
            var currentCamera = Camera.current;

            Camera.SetupCurrent(m_Camera);
            VRSettings.enabled = true;
            InputTracking.Recenter();
            Camera.SetupCurrent(currentCamera);

            if (viewEnabled != null)
            {
                viewEnabled();
            }
        }
示例#7
0
        static void OpenIfUserPresent()
        {
            if (EditorApplication.isCompiling || Application.isPlaying || EditorApplication.isPlayingOrWillChangePlaymode)
            {
                return;
            }

            if (!ShouldShowEditorVR())
            {
                return;
            }

            if (!XRSettings.enabled)
            {
                XRSettings.enabled = true;
                if (!XRSettings.enabled)
                {
                    // Initialization failed, so don't keep trying
                    EditorApplication.update -= OpenIfUserPresent;
                    s_EnableXRFailed          = true;
                    return;
                }
            }

            s_EnableXRFailed = false;

            if (EditorWindow.mouseOverWindow == null)
            {
                return;
            }

            var userPresent = VRView.GetIsUserPresent();
            var view        = VRView.activeView;

            if (!s_UserWasPresent && userPresent && !view && !s_AutoOpened)
            {
                s_AutoOpened = true;
                EditorApplication.delayCall += ShowEditorVR;
            }
            else if (s_UserWasPresent && view && !userPresent && s_AutoOpened)
            {
                s_AutoOpened = false;
                EditorApplication.delayCall += view.Close;
            }

            s_UserWasPresent = userPresent;
        }
示例#8
0
        public void OnEnable()
        {
            Assert.IsNull(s_ActiveView, "Only one EditorXR should be active");

            autoRepaintOnSceneChange = true;
            s_ActiveView             = this;

            GameObject cameraGO = EditorUtility.CreateGameObjectWithHideFlags("VRCamera", HideFlags.HideAndDontSave, typeof(Camera));

            m_Camera = cameraGO.GetComponent <Camera>();
            m_Camera.useOcclusionCulling = false;
            m_Camera.enabled             = false;
            m_Camera.cameraType          = CameraType.VR;

            GameObject rigGO = EditorUtility.CreateGameObjectWithHideFlags("VRCameraRig", HideFlags.HideAndDontSave, typeof(EditorMonoBehaviour));

            m_CameraRig = rigGO.transform;
            m_Camera.transform.parent = m_CameraRig;
            m_Camera.nearClipPlane    = 0.01f;
            m_Camera.farClipPlane     = 1000f;
            m_CameraRig.position      = headCenteredOrigin;
            m_CameraRig.rotation      = Quaternion.identity;

            m_ShowDeviceView         = EditorPrefs.GetBool(k_ShowDeviceView, false);
            m_UseCustomPreviewCamera = EditorPrefs.GetBool(k_UseCustomPreviewCamera, false);

            // Disable other views to increase rendering performance for EditorVR
            SetOtherViewsEnabled(false);

            // VRSettings.enabled latches the reference pose for the current camera
            var currentCamera = Camera.current;

            Camera.SetupCurrent(m_Camera);
#if UNITY_2017_2_OR_NEWER
            XRSettings.enabled = true;
#endif
            Camera.SetupCurrent(currentCamera);

            if (viewEnabled != null)
            {
                viewEnabled();
            }
        }
示例#9
0
        void OnVRViewGUI(VRView view)
        {
            const float paddingX = 5;
            var         position = view.position;
            var         height   = position.height - m_ContextPopupRect.height * 2;
            var         popupX   = position.width - m_ContextPopupRect.width - paddingX;

            m_ContextPopupRect.x = popupX;
            m_ContextPopupRect.y = height;
            m_ContextLabelRect.x = popupX - m_ContextLabelRect.width;
            m_ContextLabelRect.y = height;

            GUI.Label(m_ContextLabelRect, "Editing Context:");
            m_SelectedContextIndex = EditorGUI.Popup(m_ContextPopupRect, m_SelectedContextIndex, m_ContextNames);
            if (GUI.changed)
            {
                SetEditingContext(s_AvailableContexts[m_SelectedContextIndex]);
                GUIUtility.ExitGUI();
            }
        }
示例#10
0
        public void OnDisable()
        {
            if (viewDisabled != null)
            {
                viewDisabled();
            }

            VRSettings.enabled = false;

            EditorPrefs.SetBool(k_ShowDeviceView, m_ShowDeviceView);
            EditorPrefs.SetBool(k_UseCustomPreviewCamera, m_UseCustomPreviewCamera);

            SetOtherViewsEnabled(true);

            if (m_CameraRig)
            {
                DestroyImmediate(m_CameraRig.gameObject, true);
            }

            Assert.IsNotNull(s_ActiveView, "EditorVR should have an active view");
            s_ActiveView = null;
        }
示例#11
0
        public void OnDisable()
        {
            if (viewDisabled != null)
            {
                viewDisabled();
            }

            EditorApplication.playmodeStateChanged -= OnPlaymodeStateChanged;

            VRSettings.StopRenderingToDevice();

            EditorPrefs.SetBool(k_ShowDeviceView, m_ShowDeviceView);
            EditorPrefs.SetBool(k_UseCustomPreviewCamera, m_UseCustomPreviewCamera);

            SetOtherViewsEnabled(true);

            if (m_CameraRig)
            {
                DestroyImmediate(m_CameraRig.gameObject, true);
            }

            Assert.IsNotNull(s_ActiveView, "EditorVR should have an active view");
            s_ActiveView = null;
        }
示例#12
0
        public void OnEnable()
        {
            Assert.IsNull(s_ActiveView, "Only one EditorXR should be active");

            autoRepaintOnSceneChange = true;
            s_ActiveView             = this;
            const float nearClipPlane = 0.01f;
            const float farClipPlane  = 1000f;

            s_ExistingSceneMainCamera = Camera.main;
            // TODO: Copy camera settings when changing contexts
            if (EditingContextManager.defaultContext.copyExistingCameraSettings && s_ExistingSceneMainCamera && s_ExistingSceneMainCamera.enabled)
            {
                GameObject cameraGO = EditorUtility.CreateGameObjectWithHideFlags(k_CameraName, HideFlags.HideAndDontSave);
                m_Camera = ObjectUtils.CopyComponent(s_ExistingSceneMainCamera, cameraGO);

                if (m_Camera.nearClipPlane > nearClipPlane)
                {
                    Debug.LogWarning("Copying settings from scene camera that is tagged 'MainCamera'." + Environment.NewLine +
                                     " Clipping issues may occur with NearClipPlane values is greater than " + nearClipPlane);

                    m_Camera.nearClipPlane = nearClipPlane;
                }

                // TODO: Support multiple cameras
                if (m_Camera.clearFlags == CameraClearFlags.Nothing)
                {
                    m_Camera.clearFlags = CameraClearFlags.SolidColor;
                }

                m_Camera.stereoTargetEye = StereoTargetEyeMask.Both;
                // Force HDR on because of a bug in the mirror view
                m_Camera.allowHDR = true;
            }
            else
            {
                GameObject cameraGO = EditorUtility.CreateGameObjectWithHideFlags(k_CameraName, HideFlags.HideAndDontSave, typeof(Camera));
                m_Camera = cameraGO.GetComponent <Camera>();

                m_Camera.nearClipPlane = nearClipPlane;
                m_Camera.farClipPlane  = farClipPlane;
            }

            if (s_ExistingSceneMainCamera)
            {
                s_ExistingSceneMainCameraEnabledState = s_ExistingSceneMainCamera.enabled;
                s_ExistingSceneMainCamera.enabled     = false; // Disable existing MainCamera in the scene
            }

            m_Camera.enabled             = false;
            m_Camera.cameraType          = CameraType.VR;
            m_Camera.useOcclusionCulling = false;
            GameObject rigGO = EditorUtility.CreateGameObjectWithHideFlags("VRCameraRig", HideFlags.HideAndDontSave, typeof(EditorMonoBehaviour));

            m_CameraRig = rigGO.transform;
            m_Camera.transform.parent = m_CameraRig;
            m_CameraRig.position      = headCenteredOrigin;
            m_CameraRig.rotation      = Quaternion.identity;

            m_ShowDeviceView         = EditorPrefs.GetBool(k_ShowDeviceView, false);
            m_UseCustomPreviewCamera = EditorPrefs.GetBool(k_UseCustomPreviewCamera, false);

            // Disable other views to increase rendering performance for EditorVR
            SetOtherViewsEnabled(false);

            // VRSettings.enabled latches the reference pose for the current camera
            var currentCamera = Camera.current;

            Camera.SetupCurrent(m_Camera);
#if UNITY_2017_2_OR_NEWER
            XRSettings.enabled = true;
#endif
            Camera.SetupCurrent(currentCamera);

            if (viewEnabled != null)
            {
                viewEnabled();
            }
        }