Esempio n. 1
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 (onEnable != null)
            {
                onEnable();
            }
        }
Esempio n. 2
0
        public void OnDisable()
        {
            onDisable();

            EditorApplication.playmodeStateChanged -= OnPlaymodeStateChanged;

            VRSettings.StopRenderingToDevice();

            EditorPrefs.SetBool(kShowDeviceView, m_ShowDeviceView);
            EditorPrefs.SetBool(kUseCustomPreviewCamera, m_UseCustomPreviewCamera);

            SetOtherViewsEnabled(true);

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

            Assert.IsNotNull(s_ActiveView, "EditorVR should have an active view");
            s_ActiveView = null;
        }
Esempio n. 3
0
 public static void ShowEditorVR()
 {
     // Using a utility window improves performance by saving from the overhead of DockArea.OnGUI()
     VRView.GetWindow <VRView>(true, "EditorVR", true);
 }