public void OnDisable() { if (viewDisabled != null) { viewDisabled(); } EditorPrefs.SetBool(k_ShowDeviceView, m_ShowDeviceView); EditorPrefs.SetBool(k_UseCustomPreviewCamera, m_UseCustomPreviewCamera); SetOtherViewsEnabled(true); if (m_CameraRig) { DestroyImmediate(m_CameraRig.gameObject, true); } XRSettings.enabled = false; Assert.IsNotNull(s_ActiveView, "EditorXR should have an active view"); s_ActiveView = null; if (s_ExistingSceneMainCamera) { s_ExistingSceneMainCamera.enabled = s_ExistingSceneMainCameraEnabledState; } }
public void OnEnable() { Assert.IsNull(s_ActiveView, "Only one EditorXR should be active"); autoRepaintOnSceneChange = true; s_ActiveView = this; CreateCameraRig(ref m_Camera, out m_CameraRig); m_ShowDeviceView = EditorPrefs.GetBool(k_ShowDeviceView, false); m_UseCustomPreviewCamera = EditorPrefs.GetBool(k_UseCustomPreviewCamera, false); // Disable other views to increase rendering performance for EditorXR SetOtherViewsEnabled(false); // VRSettings.enabled latches the reference pose for the current camera var currentCamera = Camera.current; Camera.SetupCurrent(m_Camera); XRSettings.enabled = true; Camera.SetupCurrent(currentCamera); if (viewEnabled != null) { viewEnabled(); } }
static void OpenIfUserPresent() { if (EditorApplication.isCompiling || Application.isPlaying || EditorApplication.isPlayingOrWillChangePlaymode) { return; } if (!ShouldShowEditorXR()) { 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 += ShowEditorXR; } else if (s_UserWasPresent && view && !userPresent && s_AutoOpened) { s_AutoOpened = false; EditorApplication.delayCall += view.Close; } s_UserWasPresent = userPresent; }
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:"); using (var check = new EditorGUI.ChangeCheckScope()) { m_SelectedContextIndex = EditorGUI.Popup(m_ContextPopupRect, m_SelectedContextIndex, m_ContextNames); if (check.changed) { SetEditingContext(s_AvailableContexts[m_SelectedContextIndex]); GUIUtility.ExitGUI(); } } }
public void Setup() { #if UNITY_EDITOR SetupMonoScriptTypeNames(); #endif EditorXR.DefaultMenu = GetTypeSafe(m_DefaultMainMenuName); EditorXR.DefaultAlternateMenu = GetTypeSafe(m_DefaultAlternateMenuName); if (m_DefaultToolStackNames != null) { EditorXR.DefaultTools = m_DefaultToolStackNames.Select(GetTypeSafe).ToArray(); } if (m_HiddenTypeNames != null) { EditorXR.HiddenTypes = m_HiddenTypeNames.Select(GetTypeSafe).ToArray(); } if (Application.isPlaying) { var camera = CameraUtils.GetMainCamera(); VRView.CreateCameraRig(ref camera, out m_CameraRig); } m_Instance = ModuleLoaderCore.instance.GetModule <EditorXR>(); if (m_Instance == null) { Debug.LogWarning("EditorXR Module not loaded"); return; } m_Instance.Initialize(); XRSettings.eyeTextureResolutionScale = m_RenderScale; }