Esempio n. 1
0
        internal void ResetWorkspaceRotations()
        {
            var cameraTransform = CameraUtils.GetMainCamera().transform;

            foreach (var ws in workspaces)
            {
                var forward = (ws.transform.position - cameraTransform.position).normalized;
                ResetRotation(ws, forward);
            }
        }
Esempio n. 2
0
        public static void SetBufferDistance(Transform[] transforms)
        {
            if (transforms != null)
            {
                var bounds = BoundsUtils.GetBounds(transforms);

                s_BufferDistance = bounds.size != Vector3.zero ? (bounds.center - CameraUtils.GetMainCamera().transform.position).magnitude : 1f;
                var viewerModule = ModuleLoaderCore.instance.GetModule <EditorXRViewerModule>();
                s_BufferDistance /= viewerModule.GetViewerScale(); // Normalize this value in case viewer scale changes before paste happens
            }
        }
Esempio n. 3
0
            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);
            }
Esempio n. 4
0
        void UpdatePlayerDirectionArrow()
        {
            var directionArrowTransform = m_PlayerDirectionArrow.transform;
            var playerPos    = CameraUtils.GetMainCamera().transform.position;
            var miniWorldPos = m_MiniWorld.referenceTransform.position;
            var targetDir    = playerPos - miniWorldPos;
            var newDir       = Vector3.RotateTowards(directionArrowTransform.up, targetDir, 360f, 360f);

            directionArrowTransform.localRotation = Quaternion.LookRotation(newDir);
            directionArrowTransform.Rotate(Vector3.right, -90.0f);
        }
Esempio n. 5
0
        void Update()
        {
            if (snappingEnabled)
            {
                var camera = CameraUtils.GetMainCamera();
                var shouldActivateGroundPlane = false;
                foreach (var statesForRay in m_SnappingStates)
                {
                    foreach (var kvp in statesForRay.Value)
                    {
                        var state = kvp.Value;
                        if (state.groundSnapping)
                        {
                            shouldActivateGroundPlane = true;
                        }

                        var widget = state.widget;
                        if (state.surfaceSnapping && widgetEnabled)
                        {
                            if (widget == null)
                            {
                                widget       = ObjectUtils.Instantiate(m_Widget, transform).transform;
                                state.widget = widget;
                            }

                            widget.gameObject.SetActive(true);

                            var distanceToCamera = Vector3.Distance(camera.transform.position, state.snappingPosition);
                            widget.position   = state.snappingPosition;
                            widget.rotation   = state.snappingRotation;
                            widget.localScale = Vector3.one * k_WidgetScale * distanceToCamera;
                        }
                        else if (state.widget != null)
                        {
                            widget.gameObject.SetActive(false);
                        }
                    }
                }

                m_GroundPlane.SetActive(shouldActivateGroundPlane);

                if (shouldActivateGroundPlane)
                {
                    m_GroundPlane.transform.localScale = Vector3.one * k_GroundPlaneScale * this.GetViewerScale();
                }
            }
            else
            {
                m_GroundPlane.SetActive(false);
                m_Widget.SetActive(false);
            }
        }
        internal void CreateWorkspace(Type t, Action <IWorkspace> createdCallback = null)
        {
            if (!typeof(IWorkspace).IsAssignableFrom(t))
            {
                return;
            }

            // 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);
            }
        }
Esempio n. 7
0
        IEnumerator PlaceSceneObjectCoroutine(Transform obj, Vector3 targetScale)
        {
            // Don't let us direct select while placing
            removeFromSpatialHash(obj.gameObject);

            float start    = Time.realtimeSinceStartup;
            var   currTime = 0f;

            obj.parent = null;
            var startScale     = obj.localScale;
            var startPosition  = obj.position;
            var startRotation  = obj.rotation;
            var targetRotation = MathUtilsExt.ConstrainYawRotation(startRotation);

            //Get bounds at target scale
            var origScale = obj.localScale;

            obj.localScale = targetScale;
            var bounds = ObjectUtils.GetBounds(obj.gameObject);

            obj.localScale = origScale;

            // We want to position the object so that it fits within the camera perspective at its original scale
            var camera      = CameraUtils.GetMainCamera();
            var halfAngle   = camera.fieldOfView * 0.5f;
            var perspective = halfAngle + k_InstantiateFOVDifference;
            var camPosition = camera.transform.position;
            var forward     = obj.position - camPosition;

            var distance       = bounds.size.magnitude / Mathf.Tan(perspective * Mathf.Deg2Rad);
            var targetPosition = obj.position;

            if (distance > forward.magnitude && obj.localScale != targetScale)
            {
                targetPosition = camPosition + forward.normalized * distance;
            }

            while (currTime < k_GrowDuration)
            {
                currTime = Time.realtimeSinceStartup - start;
                var t        = currTime / k_GrowDuration;
                var tSquared = t * t;
                obj.localScale = Vector3.Lerp(startScale, targetScale, tSquared);
                obj.position   = Vector3.Lerp(startPosition, targetPosition, tSquared);
                obj.rotation   = Quaternion.Lerp(startRotation, targetRotation, tSquared);
                yield return(null);
            }
            obj.localScale             = targetScale;
            Selection.activeGameObject = obj.gameObject;

            addToSpatialHash(obj.gameObject);
        }
Esempio n. 8
0
        void SetRingPosition()
        {
            if (!this.IsSharedUpdater(this))
            {
                return;
            }

            var cameraTransform = CameraUtils.GetMainCamera().transform;
            var cameraYaw       = MathUtilsExt.ConstrainYawRotation(cameraTransform.localRotation);
            var ringTransform   = m_Ring.transform;

            ringTransform.localPosition = cameraTransform.localPosition + cameraYaw * k_RingOffset;
            ringTransform.localRotation = cameraYaw;
        }
        public override void Process()
        {
            ExecuteUpdateOnSelectedObject();

            if (m_EventCamera == null)
            {
                return;
            }

            // World scaling also scales clipping planes
            var camera = CameraUtils.GetMainCamera();

            m_EventCamera.nearClipPlane = camera.nearClipPlane;
            m_EventCamera.farClipPlane  = camera.farClipPlane;
        }
Esempio n. 10
0
        public void LoadModule()
        {
            var mainCamera = CameraUtils.GetMainCamera();

            if (mainCamera == null)
            {
                return;
            }

            m_GazeTransform = mainCamera.transform;
            if (m_GazeTransform)
            {
                m_WorldspaceAnchorTransform = m_GazeTransform.parent;
            }
        }
Esempio n. 11
0
            internal void AddPlayerModel()
            {
                m_PlayerBody = ObjectUtils.Instantiate(evr.m_PlayerModelPrefab, CameraUtils.GetMainCamera().transform, false).GetComponent <PlayerBody>();
                var renderer = m_PlayerBody.GetComponent <Renderer>();

                evr.GetModule <SpatialHashModule>().spatialHash.AddObject(renderer, renderer.bounds);
                var playerObjects = m_PlayerBody.GetComponentsInChildren <Renderer>(true);

                foreach (var playerObject in playerObjects)
                {
                    m_VRPlayerObjects.Add(playerObject.gameObject);
                }

                evr.GetModule <IntersectionModule>().standardIgnoreList.AddRange(m_VRPlayerObjects);
            }
Esempio n. 12
0
        private void Start()
        {
            m_BlinkVisualsGO       = ObjectUtils.Instantiate(m_BlinkVisualsPrefab, rayOrigin);
            m_BlinkVisuals         = m_BlinkVisualsGO.GetComponentInChildren <BlinkVisuals>();
            m_BlinkVisuals.enabled = false;
            m_BlinkVisuals.showValidTargetIndicator  = false;            // We don't define valid targets, so always show green
            m_BlinkVisualsGO.transform.parent        = rayOrigin;
            m_BlinkVisualsGO.transform.localPosition = Vector3.zero;
            m_BlinkVisualsGO.transform.localRotation = Quaternion.identity;

            m_MainCamera            = CameraUtils.GetMainCamera();
            m_OriginalNearClipPlane = m_MainCamera.nearClipPlane;
            m_OriginalFarClipPlane  = m_MainCamera.farClipPlane;

            Shader.SetGlobalFloat(k_WorldScaleProperty, 1);
        }
Esempio n. 13
0
 /// <summary>
 /// Search the cache for currently active pointers, return true if found.
 /// </summary>
 /// <param name="id">Touch ID</param>
 /// <param name="data">Found data</param>
 /// <param name="create">If not found should it be created</param>
 /// <returns>True if pointer is found.</returns>
 protected bool GetRayData(int id, out RayEventData data, bool create)
 {
     if (!m_RayData.TryGetValue(id, out data) && create)
     {
         var mainCamera = CameraUtils.GetMainCamera();
         data = new RayEventData(eventSystem)
         {
             pointerId = id,
             camera    = mainCamera,
             rayOrigin = mainCamera.transform
         };
         m_RayData.Add(id, data);
         return(true);
     }
     return(false);
 }
Esempio n. 14
0
        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");
            }
        }
Esempio n. 15
0
 void Update()
 {
     if (!dragging)
     {
         // Place the plane handles in a good location that is accessible to the user
         var viewerPosition = CameraUtils.GetMainCamera().transform.position;
         foreach (Transform t in m_PlaneHandlesParent)
         {
             var localPos = t.localPosition;
             localPos.x      = Mathf.Abs(localPos.x) * (transform.position.x < viewerPosition.x ? 1 : -1);
             localPos.y      = Mathf.Abs(localPos.y) * (transform.position.y < viewerPosition.y ? 1 : -1);
             localPos.z      = Mathf.Abs(localPos.z) * (transform.position.z < viewerPosition.z ? 1 : -1);
             t.localPosition = localPos;
         }
     }
 }
Esempio n. 16
0
        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();
        }
Esempio n. 17
0
        public override void ExecuteAction()
        {
            Unsupported.DuplicateGameObjectsUsingPasteboard();
            var selection = Selection.transforms;
            var bounds    = ObjectUtils.GetBounds(selection);

            foreach (var s in selection)
            {
                var clone = s.gameObject;
                clone.hideFlags = HideFlags.None;
                var cloneTransform  = clone.transform;
                var cameraTransform = CameraUtils.GetMainCamera().transform;
                var viewDirection   = cloneTransform.position - cameraTransform.position;
                cloneTransform.position = cameraTransform.TransformPoint(Vector3.forward * viewDirection.magnitude / this.GetViewerScale())
                                          + cloneTransform.position - bounds.center;
                this.AddToSpatialHash(clone);
            }
        }
 void Update()
 {
     if (!dragging)
     {
         // Place the plane handles in a good location that is accessible to the user
         var viewerPosition = CameraUtils.GetMainCamera().transform.position;
         var childCount     = m_PlaneHandlesParent.childCount;
         for (var i = 0; i < childCount; i++)
         {
             var t        = m_PlaneHandlesParent.GetChild(i);
             var localPos = t.localPosition;
             localPos.x      = Mathf.Abs(localPos.x) * (transform.position.x < viewerPosition.x ? 1 : -1);
             localPos.y      = Mathf.Abs(localPos.y) * (transform.position.y < viewerPosition.y ? 1 : -1);
             localPos.z      = Mathf.Abs(localPos.z) * (transform.position.z < viewerPosition.z ? 1 : -1);
             t.localPosition = localPos;
         }
     }
 }
Esempio n. 19
0
        public override void ExecuteAction()
        {
            Unsupported.PasteGameObjectsFromPasteboard();
            var transforms = Selection.transforms;
            var bounds     = ObjectUtils.GetBounds(transforms);

            foreach (var transform in transforms)
            {
                var pasted          = transform.gameObject;
                var pastedTransform = pasted.transform;
                pasted.hideFlags = HideFlags.None;
                var cameraTransform = CameraUtils.GetMainCamera().transform;
                pastedTransform.position = cameraTransform.TransformPoint(Vector3.forward * s_BufferDistance)
                                           + pastedTransform.position - bounds.center;
                pasted.SetActive(true);
                this.AddToSpatialHash(pasted);
            }
        }
Esempio n. 20
0
        void Update()
        {
            if (snappingEnabled)
            {
                SnappingState surfaceSnapping           = null;
                var           shouldActivateGroundPlane = false;
                foreach (var statesForRay in m_SnappingStates.Values)
                {
                    foreach (var state in statesForRay.Values)
                    {
                        if (state.groundSnapping)
                        {
                            shouldActivateGroundPlane = true;
                        }

                        if (state.surfaceSnapping)
                        {
                            surfaceSnapping = state;
                        }
                    }
                }
                m_GroundPlane.SetActive(shouldActivateGroundPlane);

                if (widgetEnabled)
                {
                    var shouldActivateWidget = surfaceSnapping != null;
                    m_Widget.SetActive(shouldActivateWidget);
                    if (shouldActivateWidget)
                    {
                        var camera           = CameraUtils.GetMainCamera();
                        var distanceToCamera = Vector3.Distance(camera.transform.position, m_CurrentSurfaceSnappingPosition);
                        m_Widget.transform.position   = m_CurrentSurfaceSnappingHit;
                        m_Widget.transform.rotation   = m_CurrentSurfaceSnappingRotation;
                        m_Widget.transform.localScale = Vector3.one * k_WidgetScale * distanceToCamera;
                    }
                }
            }
            else
            {
                m_GroundPlane.SetActive(false);
                m_Widget.SetActive(false);
            }
        }
Esempio n. 21
0
        private IEnumerator MoveTowardTarget(Vector3 targetPosition)
        {
            m_State        = State.Moving;
            targetPosition = new Vector3(targetPosition.x + (cameraRig.position.x - CameraUtils.GetMainCamera().transform.position.x), cameraRig.position.y, targetPosition.z + (cameraRig.position.z - CameraUtils.GetMainCamera().transform.position.z));
            const float kTargetDuration = 0.05f;
            var         currentPosition = cameraRig.position;
            var         currentDuration = 0f;

            while (currentDuration < kTargetDuration)
            {
                currentDuration   += Time.deltaTime;
                currentPosition    = Vector3.Lerp(currentPosition, targetPosition, currentDuration / kTargetDuration);
                cameraRig.position = currentPosition;
                yield return(null);
            }

            cameraRig.position = targetPosition;
            m_State            = State.Inactive;
        }
Esempio n. 22
0
            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;
            }
Esempio n. 23
0
        void SetRingPosition()
        {
            if (!this.IsSharedUpdater(this))
            {
                return;
            }

            var cameraTransform = CameraUtils.GetMainCamera().transform;
            var cameraYaw       = cameraTransform.localRotation.ConstrainYaw();

            if (!m_MouseLocomotionRing)
            {
                return;
            }

            var ringTransform = m_MouseLocomotionRing.transform;

            ringTransform.localPosition = cameraTransform.localPosition + cameraYaw * k_RingOffset;
            ringTransform.localRotation = cameraYaw;
        }
Esempio n. 24
0
            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 (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 && evr.m_PreviewCameraPrefab)
                {
                    var go = ObjectUtils.Instantiate(evr.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
            }
Esempio n. 25
0
        public override void ExecuteAction()
        {
            var selection = Selection.gameObjects;
            var clones    = new GameObject[selection.Length];
            var index     = 0;
            var bounds    = ObjectUtils.GetBounds(selection);

            foreach (var s in selection)
            {
                var clone = ObjectUtils.Instantiate(s.gameObject);
                clone.hideFlags = HideFlags.None;
                var cloneTransform  = clone.transform;
                var cameraTransform = CameraUtils.GetMainCamera().transform;
                var viewDirection   = cloneTransform.position - cameraTransform.position;
                cloneTransform.position = cameraTransform.TransformPoint(Vector3.forward * viewDirection.magnitude)
                                          + cloneTransform.position - bounds.center;
                this.AddToSpatialHash(clone);
                clones[index++] = clone;
            }
            Selection.objects = clones;
        }
Esempio n. 26
0
        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);
            }
        }
Esempio n. 27
0
        IEnumerator MoveTowardTarget(Vector3 targetPosition)
        {
            m_BlinkMoving = true;

            var offset = cameraRig.position - CameraUtils.GetMainCamera().transform.position;
            offset.y = 0;
            offset += VRView.headCenteredOrigin * this.GetViewerScale();

            targetPosition += offset;
            const float kTargetDuration = 0.05f;
            var currentPosition = cameraRig.position;
            var currentDuration = 0f;
            while (currentDuration < kTargetDuration)
            {
                currentDuration += Time.unscaledDeltaTime;
                currentPosition = Vector3.Lerp(currentPosition, targetPosition, currentDuration / kTargetDuration);
                cameraRig.position = currentPosition;
                yield return null;
            }

            cameraRig.position = targetPosition;
            m_BlinkMoving = false;
        }
Esempio n. 28
0
        void AddPlayerModel()
        {
            m_PlayerBody = EditorXRUtils.Instantiate(m_PlayerModelPrefab, CameraUtils.GetMainCamera().transform, false).GetComponent <PlayerBody>();
            this.InjectFunctionalitySingle(m_PlayerBody);
            if (this.HasProvider <IProvidesSpatialHash>())
            {
                this.AddRendererToSpatialHash(m_PlayerBody.GetComponent <Renderer>());
            }

            var playerObjects = m_PlayerBody.GetComponentsInChildren <Renderer>(true);

            foreach (var playerObject in playerObjects)
            {
                m_VRPlayerObjects.Add(playerObject.gameObject);
            }

            var selectionModule = ModuleLoaderCore.instance.GetModule <SelectionModule>();

            if (selectionModule != null)
            {
                selectionModule.standardIgnoreList.AddRange(m_VRPlayerObjects);
            }
        }
Esempio n. 29
0
            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.hideFlags     = defaultHideFlags;
                    playerHead.parent        = mainCamera;
                    playerHead.localRotation = Quaternion.identity;
                    playerHead.localPosition = Vector3.zero;

                    foreach (var renderer in playerHeadRenderers)
                    {
                        renderer.enabled = true;
                    }
                }));
            }
Esempio n. 30
0
        void SetPosition()
        {
            var iconContainerLocal = m_IconsContainer.localPosition;
            var viewerScale        = this.GetViewerScale();

            iconContainerLocal.x           = Mathf.Log10(viewerScale) * m_IconTranslateCoefficient + m_IconTranslateOffset;
            m_IconsContainer.localPosition = iconContainerLocal;

            var camera      = CameraUtils.GetMainCamera().transform;
            var leftToRight = leftHand.position - rightHand.position;

            // If hands reverse, switch hands
            if (Vector3.Dot(leftToRight, camera.right) > 0)
            {
                leftToRight *= -1;
                var tmp = leftHand;
                leftHand  = rightHand;
                rightHand = tmp;
            }

            transform.position = rightHand.position + leftToRight * 0.5f;
            transform.rotation = Quaternion.LookRotation(leftToRight, camera.position - transform.position);

            leftToRight = transform.InverseTransformVector(leftToRight);
            var length = leftToRight.magnitude * 0.5f;

            m_Line.SetPosition(0, Vector3.left * length);
            m_Line.SetPosition(1, Vector3.right * length);
            var lineWidth = m_LineWidth * viewerScale;

            m_Line.SetWidth(lineWidth, lineWidth);

#if INCLUDE_TEXT_MESH_PRO
            m_ScaleText.text = string.Format("Viewer Scale: {0:f2}", viewerScale);
#endif
        }