public void Initialize() { var cameraRig = CameraUtils.GetCameraRig(); var proxyTypes = CollectionPool <List <Type>, Type> .GetCollection(); typeof(IProxy).GetImplementationsOfInterface(proxyTypes); foreach (var proxyType in proxyTypes) { var proxy = (IProxy)EditorXRUtils.CreateGameObjectWithComponent(proxyType, cameraRig, false); this.ConnectInterfaces(proxy); this.InjectFunctionalitySingle(proxy); var trackedObjectInput = m_DeviceInputModule.trackedObjectInput; if (trackedObjectInput == null) { Debug.LogError("Device Input Module not initialized--trackedObjectInput is null"); } proxy.trackedObjectInput = trackedObjectInput; proxy.activeChanged += () => OnProxyActiveChanged(proxy); m_Proxies.Add(proxy); } CollectionPool <List <Type>, Type> .RecycleCollection(proxyTypes); }
internal void CreateWorkspace(Type t, Action <IWorkspace> createdCallback = null) { var cameraTransform = CameraUtils.GetMainCamera().transform; var workspace = (IWorkspace)ObjectUtils.CreateGameObjectWithComponent(t, CameraUtils.GetCameraRig(), false); m_Workspaces.Add(workspace); workspace.destroyed += OnWorkspaceDestroyed; connectInterfaces(workspace); //Explicit setup call (instead of setting up in Awake) because we need interfaces to be hooked up first workspace.Setup(); var offset = k_DefaultWorkspaceOffset; offset.z += workspace.vacuumBounds.extents.z; var workspaceTransform = workspace.transform; workspaceTransform.position = cameraTransform.TransformPoint(offset); workspaceTransform.rotation = Quaternion.LookRotation(cameraTransform.forward) * k_DefaultWorkspaceTilt; if (createdCallback != null) { createdCallback(workspace); } if (workspaceCreated != null) { workspaceCreated(workspace); } }
internal override void OnDestroy() { base.OnDestroy(); #if UNITY_EDITOR VRView.hmdStatusChange -= OnHMDStatusChange; #endif var cameraRig = CameraUtils.GetCameraRig(); if (cameraRig) { cameraRig.transform.parent = null; } ObjectUtils.Destroy(m_PlayerFloor); if (m_PlayerBody) { ObjectUtils.Destroy(m_PlayerBody.gameObject); } if (customPreviewCamera != null) { ObjectUtils.Destroy(((MonoBehaviour)customPreviewCamera).gameObject); } }
internal void InitializeCamera() { var cameraRig = CameraUtils.GetCameraRig(); cameraRig.parent = evr.transform; // Parent the camera rig under EditorVR cameraRig.hideFlags = defaultHideFlags; var viewerCamera = CameraUtils.GetMainCamera(); viewerCamera.gameObject.hideFlags = defaultHideFlags; m_OriginalNearClipPlane = viewerCamera.nearClipPlane; m_OriginalFarClipPlane = viewerCamera.farClipPlane; if (VRSettings.loadedDeviceName == "OpenVR") { // Steam's reference position should be at the feet and not at the head as we do with Oculus cameraRig.localPosition = Vector3.zero; } var hmdOnlyLayerMask = 0; if (evr.m_PreviewCameraPrefab) { var go = ObjectUtils.Instantiate(evr.m_PreviewCameraPrefab); go.transform.SetParent(CameraUtils.GetCameraRig(), false); customPreviewCamera = go.GetComponentInChildren <IPreviewCamera>(); if (customPreviewCamera != null) { VRView.customPreviewCamera = customPreviewCamera.previewCamera; customPreviewCamera.vrCamera = VRView.viewerCamera; hmdOnlyLayerMask = customPreviewCamera.hmdOnlyLayerMask; evr.m_Interfaces.ConnectInterfaces(customPreviewCamera); } } VRView.cullingMask = UnityEditor.Tools.visibleLayers | hmdOnlyLayerMask; }
void FocusSelection(Transform rayOrigin) { if (Selection.gameObjects.Length == 0) { return; } var mainCamera = CameraUtils.GetMainCamera().transform; var bounds = ObjectUtils.GetBounds(Selection.transforms); var size = bounds.size; size.y = 0; var maxSize = size.MaxComponent(); const float kExtraDistance = 0.25f; // Add some extra distance so selection isn't in your face maxSize += kExtraDistance; var viewDirection = mainCamera.transform.forward; viewDirection.y = 0; viewDirection.Normalize(); var cameraDiff = mainCamera.position - CameraUtils.GetCameraRig().position; cameraDiff.y = 0; this.MoveCameraRig(bounds.center - cameraDiff - viewDirection * maxSize); OnButtonClicked(rayOrigin); }
internal static void DropPlayerHead(Transform playerHead) { var cameraRig = CameraUtils.GetCameraRig(); var mainCamera = CameraUtils.GetMainCamera().transform; // Hide player head to avoid jarring impact var playerHeadRenderers = playerHead.GetComponentsInChildren <Renderer>(); foreach (var renderer in playerHeadRenderers) { renderer.enabled = false; } var rotationDiff = MathUtilsExt.ConstrainYawRotation(Quaternion.Inverse(mainCamera.rotation) * playerHead.rotation); var cameraDiff = cameraRig.position - mainCamera.position; cameraDiff.y = 0; var rotationOffset = rotationDiff * cameraDiff - cameraDiff; var endPosition = cameraRig.position + (playerHead.position - mainCamera.position) + rotationOffset; var endRotation = cameraRig.rotation * rotationDiff; var viewDirection = endRotation * Vector3.forward; evr.StartCoroutine(UpdateCameraRig(endPosition, viewDirection, () => { playerHead.parent = mainCamera; playerHead.localRotation = Quaternion.identity; playerHead.localPosition = Vector3.zero; foreach (var renderer in playerHeadRenderers) { renderer.enabled = true; } })); }
public void Shutdown() { m_CameraInitialized = false; m_OriginalNearClipPlane = 0; m_OriginalFarClipPlane = 0; hmdReady = false; foreach (var playerObject in m_VRPlayerObjects) { UnityObjectUtils.Destroy(playerObject); } m_VRPlayerObjects.Clear(); var cameraRig = CameraUtils.GetCameraRig(); if (cameraRig) { cameraRig.transform.parent = null; } if (customPreviewCamera != null && customPreviewCamera as MonoBehaviour != null) { UnityObjectUtils.Destroy(((MonoBehaviour)customPreviewCamera).gameObject); } }
void SetViewerScale(float scale) { var camera = CameraUtils.GetMainCamera(); CameraUtils.GetCameraRig().localScale = Vector3.one * scale; camera.nearClipPlane = m_OriginalNearClipPlane * scale; camera.farClipPlane = m_OriginalFarClipPlane * scale; }
public void ConnectInterface(object obj, Transform rayOrigin = null) { var usesCameraRig = obj as IUsesCameraRig; if (usesCameraRig != null) { usesCameraRig.cameraRig = CameraUtils.GetCameraRig(); } }
public void ConnectInterface(object target, object userData = null) { var usesCameraRig = target as IUsesCameraRig; if (usesCameraRig != null) { usesCameraRig.cameraRig = CameraUtils.GetCameraRig(); } }
void SetViewerScale(float scale) { var camera = CameraUtils.GetMainCamera(); CameraUtils.GetCameraRig().localScale = Vector3.one * scale; camera.nearClipPlane = m_OriginalNearClipPlane * scale; camera.farClipPlane = m_OriginalFarClipPlane * scale; Shader.SetGlobalFloat(k_WorldScaleProperty, 1f / scale); }
public void CreateWorkspace(Type t, Action <IWorkspace> createdCallback = null) { if (!typeof(IWorkspace).IsAssignableFrom(t)) { return; } // HACK: MiniWorldWorkspace is not working in single pass yet #if UNITY_EDITOR if (t == typeof(MiniWorldWorkspace) && PlayerSettings.stereoRenderingPath != StereoRenderingPath.MultiPass) { Debug.LogWarning("The MiniWorld workspace is not working on single pass, currently."); return; } #endif var cameraTransform = CameraUtils.GetMainCamera().transform; var workspaceComponent = EditorXRUtils.CreateGameObjectWithComponent(t, CameraUtils.GetCameraRig(), false); var workspace = (IWorkspace)workspaceComponent; m_Workspaces.Add(workspace); workspace.destroyed += OnWorkspaceDestroyed; this.ConnectInterfaces(workspace); this.InjectFunctionalitySingle(workspace); var evrWorkspace = workspace as Workspace; if (evrWorkspace != null) { evrWorkspace.leftRayOrigin = leftRayOrigin; evrWorkspace.rightRayOrigin = rightRayOrigin; } //Explicit setup call (instead of setting up in Awake) because we need interfaces to be hooked up first workspace.Setup(); var offset = DefaultWorkspaceOffset; offset.z += workspace.vacuumBounds.extents.z; var workspaceTransform = workspace.transform; workspaceTransform.position = cameraTransform.TransformPoint(offset); ResetRotation(workspace, cameraTransform.forward); if (createdCallback != null) { createdCallback(workspace); } if (workspaceCreated != null) { workspaceCreated(workspace); } #if UNITY_EDITOR EditorXRAnalyticsEvents.WorkspaceState.Send(new UiComponentArgs(t.Name, true)); #endif }
void SaveCameraState() { var camera = CameraUtils.GetMainCamera(); var cameraRig = CameraUtils.GetCameraRig(); var cameraTransform = camera.transform; var cameraRigScale = cameraRig.localScale.x; m_Preferences.cameraRigScale = cameraRigScale; m_Preferences.cameraPosition = cameraTransform.position; m_Preferences.cameraRotation = MathUtilsExt.ConstrainYawRotation(cameraTransform.rotation); }
public float GetViewerScale() { var cameraRig = CameraUtils.GetCameraRig(); if (!cameraRig) { return(1); } return(cameraRig.localScale.x); }
private void OnEnable() { if (!referenceTransform) { referenceTransform = ObjectUtils.CreateEmptyGameObject("MiniWorldReference").transform; } m_MiniWorldRenderer = ObjectUtils.AddComponent <MiniWorldRenderer>(CameraUtils.GetMainCamera().gameObject); m_MiniWorldRenderer.miniWorld = this; m_MiniWorldRenderer.cullingMask = m_RendererCullingMask; Transform rig = CameraUtils.GetCameraRig(); referenceTransform.position = rig.transform.position; }
internal void CreateAllProxies() { var deviceInputModule = evr.GetModule <DeviceInputModule>(); var cameraRig = CameraUtils.GetCameraRig(); foreach (var proxyType in ObjectUtils.GetImplementationsOfInterface(typeof(IProxy))) { var proxy = (IProxy)ObjectUtils.CreateGameObjectWithComponent(proxyType, cameraRig, false); this.ConnectInterfaces(proxy); proxy.trackedObjectInput = deviceInputModule.trackedObjectInput; proxy.activeChanged += () => OnProxyActiveChanged(proxy); m_Proxies.Add(proxy); } }
public void ConnectInterface(object obj, Transform rayOrigin = null) { var locomotion = obj as ILocomotor; if (locomotion != null) { locomotion.cameraRig = VRView.cameraRig; } var usesCameraRig = obj as IUsesCameraRig; if (usesCameraRig != null) { usesCameraRig.cameraRig = CameraUtils.GetCameraRig(); } }
public void SetViewerScale(float scale) { var camera = CameraUtils.GetMainCamera(); CameraUtils.GetCameraRig().localScale = Vector3.one * scale; Shader.SetGlobalFloat(k_WorldScaleProperty, 1f / scale); if (m_CameraInitialized) { camera.nearClipPlane = m_OriginalNearClipPlane * scale; camera.farClipPlane = m_OriginalFarClipPlane * scale; } else { Debug.LogWarning("Premature use of SetViewerScale"); } }
internal void CreateWorkspace(Type t, Action <IWorkspace> createdCallback = null) { // HACK: MiniWorldWorkspace is not working in single pass yet if (t == typeof(MiniWorldWorkspace) && PlayerSettings.stereoRenderingPath != StereoRenderingPath.MultiPass) { Debug.LogWarning("The MiniWorld workspace is not working on single pass, currently."); return; } var cameraTransform = CameraUtils.GetMainCamera().transform; var workspace = (IWorkspace)ObjectUtils.CreateGameObjectWithComponent(t, CameraUtils.GetCameraRig(), false); m_Workspaces.Add(workspace); workspace.destroyed += OnWorkspaceDestroyed; this.ConnectInterfaces(workspace); var evrWorkspace = workspace as Workspace; if (evrWorkspace != null) { evrWorkspace.leftRayOrigin = leftRayOrigin; evrWorkspace.rightRayOrigin = rightRayOrigin; } //Explicit setup call (instead of setting up in Awake) because we need interfaces to be hooked up first workspace.Setup(); var offset = DefaultWorkspaceOffset; offset.z += workspace.vacuumBounds.extents.z; var workspaceTransform = workspace.transform; workspaceTransform.position = cameraTransform.TransformPoint(offset); ResetRotation(workspace, cameraTransform.forward); if (createdCallback != null) { createdCallback(workspace); } if (workspaceCreated != null) { workspaceCreated(workspace); } }
void SaveCameraState() { var camera = CameraUtils.GetMainCamera(); var cameraRig = CameraUtils.GetCameraRig(); if (!cameraRig || !camera) { return; } var cameraTransform = camera.transform; var cameraRigScale = cameraRig.localScale.x; m_Preferences.cameraRigScale = cameraRigScale; m_Preferences.cameraPosition = cameraTransform.position; m_Preferences.cameraRotation = cameraTransform.rotation.ConstrainYaw(); }
internal override void OnDestroy() { base.OnDestroy(); VRView.hmdStatusChange -= OnHMDStatusChange; var cameraRig = CameraUtils.GetCameraRig(); cameraRig.transform.parent = null; ObjectUtils.Destroy(m_PlayerBody.gameObject); if (customPreviewCamera != null) { ObjectUtils.Destroy(((MonoBehaviour)customPreviewCamera).gameObject); } }
void CreateUI() { if (s_SpatialMenuUI == null) { var parent = CameraUtils.GetCameraRig(); s_SpatialMenuUI = this.InstantiateUI(m_SpatialMenuUiPrefab.gameObject, parent, rayOrigin: rayOrigin).GetComponent <SpatialMenuUI>(); // HACK: For some reason, the spatial menu ends up outside of the VRCameraRig in play mode s_SpatialMenuUI.transform.parent = parent; s_SpatialMenuUI.spatialMenuData = k_SpatialMenuData; // set shared reference to menu name/type, elements, and highlighted state s_SpatialMenuUI.Setup(); s_SpatialMenuUI.returnToPreviousMenuLevel = ReturnToPreviousMenuLevel; s_SpatialMenuUI.changeMenuState = ChangeMenuState; } visible = false; }
public void OnDeserializePreferences(object obj) { if (!preserveCameraRig) { return; } var preferences = (Preferences)obj; var camera = CameraUtils.GetMainCamera(); var cameraRig = CameraUtils.GetCameraRig(); var cameraTransform = camera.transform; var cameraRotation = MathUtilsExt.ConstrainYawRotation(cameraTransform.rotation); var inverseRotation = Quaternion.Inverse(cameraRotation); cameraRig.position = Vector3.zero; cameraRig.rotation = inverseRotation * preferences.cameraRotation; SetViewerScale(preferences.cameraRigScale); cameraRig.position = preferences.cameraPosition - cameraTransform.position; }
void InitializeCamera() { var cameraRig = CameraUtils.GetCameraRig(); cameraRig.parent = ModuleLoaderCore.instance.GetModuleParent().transform; var viewerCamera = CameraUtils.GetMainCamera(); m_OriginalNearClipPlane = viewerCamera.nearClipPlane; m_OriginalFarClipPlane = viewerCamera.farClipPlane; if (XRSettings.loadedDeviceName == "OpenVR") { // Steam's reference position should be at the feet and not at the head as we do with Oculus cameraRig.localPosition = Vector3.zero; } #if UNITY_EDITOR var hmdOnlyLayerMask = 0; #endif if (!Application.isPlaying && m_PreviewCameraPrefab) { var go = EditorXRUtils.Instantiate(m_PreviewCameraPrefab); go.transform.SetParent(CameraUtils.GetCameraRig(), false); #if UNITY_EDITOR customPreviewCamera = go.GetComponentInChildren <IPreviewCamera>(); if (customPreviewCamera != null) { VRView.customPreviewCamera = customPreviewCamera.previewCamera; customPreviewCamera.vrCamera = VRView.viewerCamera; hmdOnlyLayerMask = customPreviewCamera.hmdOnlyLayerMask; this.ConnectInterfaces(customPreviewCamera); } #endif } #if UNITY_EDITOR VRView.cullingMask = UnityEditor.Tools.visibleLayers | hmdOnlyLayerMask; #endif m_CameraInitialized = true; }
internal void CreateWorkspace(Type t, Action <IWorkspace> createdCallback = null) { var cameraTransform = CameraUtils.GetMainCamera().transform; var workspace = (IWorkspace)ObjectUtils.CreateGameObjectWithComponent(t, CameraUtils.GetCameraRig(), false); m_Workspaces.Add(workspace); workspace.destroyed += OnWorkspaceDestroyed; this.ConnectInterfaces(workspace); var evrWorkspace = workspace as Workspace; if (evrWorkspace != null) { evrWorkspace.leftRayOrigin = leftRayOrigin; evrWorkspace.rightRayOrigin = rightRayOrigin; } //Explicit setup call (instead of setting up in Awake) because we need interfaces to be hooked up first workspace.Setup(); var offset = DefaultWorkspaceOffset; offset.z += workspace.vacuumBounds.extents.z; var workspaceTransform = workspace.transform; workspaceTransform.position = cameraTransform.TransformPoint(offset); ResetRotation(workspace, cameraTransform.forward); if (createdCallback != null) { createdCallback(workspace); } if (workspaceCreated != null) { workspaceCreated(workspace); } }
static IEnumerator UpdateCameraRig(Vector3 position, Vector3?viewDirection, Action onComplete = null) { var cameraRig = CameraUtils.GetCameraRig(); var startPosition = cameraRig.position; var startRotation = cameraRig.rotation; var rotation = startRotation; if (viewDirection.HasValue) { var direction = viewDirection.Value; direction.y = 0; rotation = Quaternion.LookRotation(direction.normalized, Vector3.up); } var diffTime = 0f; var startTime = Time.realtimeSinceStartup; while (diffTime < k_CameraRigTransitionTime) { var t = diffTime / k_CameraRigTransitionTime; // Use a Lerp instead of SmoothDamp for constant velocity (avoid motion sickness) cameraRig.position = Vector3.Lerp(startPosition, position, t); cameraRig.rotation = Quaternion.Lerp(startRotation, rotation, t); yield return(null); diffTime = Time.realtimeSinceStartup - startTime; } cameraRig.position = position; cameraRig.rotation = rotation; if (onComplete != null) { onComplete(); } }
public KeyboardUI SpawnAlphaNumericKeyboard() { if (m_NumericKeyboard != null) { m_NumericKeyboard.gameObject.SetActive(false); } // Check if the prefab has already been instantiated if (m_StandardKeyboard == null) { m_StandardKeyboard = EditorXRUtils.Instantiate(m_StandardKeyboardPrefab.gameObject, CameraUtils.GetCameraRig(), false).GetComponent <KeyboardUI>(); var smoothMotions = m_StandardKeyboard.GetComponentsInChildren <SmoothMotion>(true); foreach (var smoothMotion in smoothMotions) { this.InjectFunctionalitySingle(smoothMotion); this.ConnectInterfaces(smoothMotion); } } return(m_StandardKeyboard); }
void CreateUI() { if (s_SpatialMenuUI == null) { s_SpatialMenuUI = this.InstantiateUI(m_SpatialMenuUiPrefab.gameObject, CameraUtils.GetCameraRig(), rayOrigin: rayOrigin).GetComponent <SpatialMenuUI>(); s_SpatialMenuUI.spatialMenuData = k_SpatialMenuData; // set shared reference to menu name/type, elements, and highlighted state s_SpatialMenuUI.Setup(); s_SpatialMenuUI.returnToPreviousMenuLevel = ReturnToPreviousMenuLevel; s_SpatialMenuUI.changeMenuState = ChangeMenuState; } visible = false; }
internal static float GetViewerScale() { return(CameraUtils.GetCameraRig().localScale.x); }
public KeyboardUI SpawnAlphaNumericKeyboard() { if (m_NumericKeyboard != null) { m_NumericKeyboard.gameObject.SetActive(false); } // Check if the prefab has already been instantiated if (m_StandardKeyboard == null) { m_StandardKeyboard = ObjectUtils.Instantiate(m_StandardKeyboardPrefab.gameObject, CameraUtils.GetCameraRig()).GetComponent <KeyboardUI>(); } return(m_StandardKeyboard); }