Ejemplo n.º 1
0
        /// <summary>
        /// Update the cursor's transform
        /// </summary>
        protected virtual void UpdateCursorTransform()
        {
            if (Pointer == null)
            {
                Debug.LogError($"[BaseCursor.{name}] No Pointer has been assigned!");
                return;
            }

            GameObject newTargetedObject = InputSystem.FocusProvider.GetFocusedObject(Pointer);
            Vector3    lookForward;

            // Normalize scale on before update
            targetScale = Vector3.one;

            // If no game object is hit, put the cursor at the default distance
            if (newTargetedObject == null)
            {
                TargetedObject = null;
                targetPosition = RayStep.GetPointByDistance(Pointer.Rays, defaultCursorDistance);
                lookForward    = -RayStep.GetDirectionByDistance(Pointer.Rays, defaultCursorDistance);
                targetRotation = lookForward.magnitude > 0 ? Quaternion.LookRotation(lookForward, Vector3.up) : transform.rotation;
            }
            else
            {
                // Update currently targeted object
                TargetedObject = newTargetedObject;

                if (Pointer.CursorModifier != null)
                {
                    Pointer.CursorModifier.GetModifiedTransform(this, out targetPosition, out targetRotation, out targetScale);
                }
                else
                {
                    // If no modifier is on the target, just use the hit result to set cursor position
                    // Get the look forward by using distance between pointer origin and target position
                    // (This may not be strictly accurate for extremely wobbly pointers, but it should produce usable results)
                    float distanceToTarget = Vector3.Distance(Pointer.Rays[0].Origin, focusDetails.Point);
                    lookForward    = -RayStep.GetDirectionByDistance(Pointer.Rays, distanceToTarget);
                    targetPosition = focusDetails.Point + (lookForward * surfaceCursorDistance);
                    Vector3 lookRotation = Vector3.Slerp(focusDetails.Normal, lookForward, lookRotationBlend);
                    targetRotation = Quaternion.LookRotation(lookRotation == Vector3.zero ? lookForward : lookRotation, Vector3.up);
                }
            }

            float deltaTime = useUnscaledTime
                ? Time.unscaledDeltaTime
                : Time.deltaTime;

            // Use the lerp times to blend the position to the target position
            transform.position   = Vector3.Lerp(transform.position, targetPosition, deltaTime / positionLerpTime);
            transform.localScale = Vector3.Lerp(transform.localScale, targetScale, deltaTime / scaleLerpTime);
            transform.rotation   = Quaternion.Lerp(transform.rotation, targetRotation, deltaTime / rotationLerpTime);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Update the cursor's transform
        /// </summary>
        protected virtual void UpdateCursorTransform()
        {
            if (Pointer == null)
            {
                Debug.LogError($"[BaseCursor.{name}] No Pointer has been assigned!");
                return;
            }

            GameObject newTargetedObject = CoreServices.InputSystem.FocusProvider.GetFocusedObject(Pointer);
            Vector3    lookForward;

            // If no game object is hit, put the cursor at the default distance
            if (newTargetedObject == null)
            {
                TargetedObject = null;
                targetPosition = RayStep.GetPointByDistance(Pointer.Rays, defaultCursorDistance);
                lookForward    = -RayStep.GetDirectionByDistance(Pointer.Rays, defaultCursorDistance);
                targetRotation = lookForward.magnitude > 0 ? Quaternion.LookRotation(lookForward, Vector3.up) : transform.rotation;

                // If constant cursor scale is desired, skip resizing functionality
                targetScale = resizeCursorWithDistance ? ComputeScaleWithAngularScale(targetPosition) : Vector3.one;
            }
            else
            {
                // Update currently targeted object
                TargetedObject = newTargetedObject;

                if (Pointer.CursorModifier != null)
                {
                    Pointer.CursorModifier.GetModifiedTransform(this, out targetPosition, out targetRotation, out targetScale);
                }
                else
                {
                    // If no modifier is on the target, just use the hit result to set cursor position
                    // Get the look forward by using distance between pointer origin and target position
                    // (This may not be strictly accurate for extremely wobbly pointers, but it should produce usable results)
                    float distanceToTarget = Vector3.Distance(Pointer.Rays[0].Origin, focusDetails.Point);
                    lookForward    = -RayStep.GetDirectionByDistance(Pointer.Rays, distanceToTarget);
                    targetPosition = focusDetails.Point + (lookForward * surfaceCursorDistance);
                    Vector3 lookRotation = Vector3.Slerp(focusDetails.Normal, lookForward, lookRotationBlend);
                    targetRotation = Quaternion.LookRotation(lookRotation == Vector3.zero ? lookForward : lookRotation, Vector3.up);

                    // If constant cursor scale is desired, skip resizing functionality
                    targetScale = resizeCursorWithDistance ? ComputeScaleWithAngularScale(targetPosition) : Vector3.one;
                }
            }

            LerpToTargetTransform();
        }
Ejemplo n.º 3
0
        public void UpdateRenderedLine(RayStep[] lines, PointerResult result, bool selectPressed, float extent)
        {
            if (LineBase == null)
            {
                return;
            }

            Gradient lineColor = LineColorNoTarget;

            if (InteractionEnabled)
            {
                LineBase.enabled = true;

                // If we hit something
                if (result.End.Object != null)
                {
                    lineColor          = LineColorValid;
                    LineBase.LastPoint = result.End.Point;
                }
                else
                {
                    LineBase.LastPoint = RayStep.GetPointByDistance(lines, extent);
                }

                if (selectPressed)
                {
                    lineColor = LineColorSelected;
                }
            }
            else
            {
                LineBase.enabled = false;
            }

            for (int i = 0; i < LineRenderers.Length; i++)
            {
                LineRenderers[i].LineColor = lineColor;
            }
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Update the cursor's transform
        /// </summary>
        protected virtual void UpdateCursorTransform()
        {
            FocusDetails focusDetails      = FocusManager.Instance.GetFocusDetails(Pointer);
            GameObject   newTargetedObject = focusDetails.Object;
            Vector3      lookForward       = Vector3.forward;

            // Normalize scale on before update
            targetScale = Vector3.one;

            // If no game object is hit, put the cursor at the default distance
            if (newTargetedObject == null)
            {
                TargetedObject         = null;
                TargetedCursorModifier = null;

                if (pointerIsInputSourcePointer)
                {
                    // This value get re-queried every update, in case the app has
                    // changed the pointing extent of the pointer for the current scenario.
                    float distance = FocusManager.Instance.GetPointingExtent(Pointer);
                    if (DefaultCursorDistance != distance)
                    {
                        DefaultCursorDistance = distance;
                    }
                }
                else if (DefaultCursorDistance != originalDefaultCursorDistance)
                {
                    DefaultCursorDistance = originalDefaultCursorDistance;
                }

                targetPosition = RayStep.GetPointByDistance(Pointer.Rays, DefaultCursorDistance);
                lookForward    = -RayStep.GetDirectionByDistance(Pointer.Rays, DefaultCursorDistance);
                targetRotation = lookForward.magnitude > 0 ? Quaternion.LookRotation(lookForward, Vector3.up) : transform.rotation;
            }
            else
            {
                // Update currently targeted object
                TargetedObject = newTargetedObject;

                if (TargetedCursorModifier != null)
                {
                    TargetedCursorModifier.GetModifiedTransform(this, out targetPosition, out targetRotation, out targetScale);
                }
                else
                {
                    // If no modifier is on the target, just use the hit result to set cursor position
                    // Get the look forward by using distance between pointer origin and target position
                    // (This may not be strictly accurate for extremely wobbly pointers, but it should produce usable results)
                    float distanceToTarget = Vector3.Distance(Pointer.Rays[0].Origin, focusDetails.Point);
                    lookForward    = -RayStep.GetDirectionByDistance(Pointer.Rays, distanceToTarget);
                    targetPosition = focusDetails.Point + (lookForward * SurfaceCursorDistance);
                    Vector3 lookRotation = Vector3.Slerp(focusDetails.Normal, lookForward, LookRotationBlend);
                    targetRotation = Quaternion.LookRotation(lookRotation == Vector3.zero ? lookForward : lookRotation, Vector3.up);
                }
            }

            float deltaTime = UseUnscaledTime
                ? Time.unscaledDeltaTime
                : Time.deltaTime;

            // Use the lerp times to blend the position to the target position

            if (float.IsNaN(transform.position.x) || float.IsNaN(targetPosition.x) || PositionLerpTime == 0)
            {
                //transform.position = Vector3.zero;
            }
            else
            {
                transform.position   = Vector3.Lerp(transform.position, targetPosition, deltaTime / PositionLerpTime);
                transform.localScale = Vector3.Lerp(transform.localScale, targetScale, deltaTime / ScaleLerpTime);
                transform.rotation   = Quaternion.Lerp(transform.rotation, targetRotation, deltaTime / RotationLerpTime);
                //DongFengMain.Instance.ShowCursor();
            }
        }