////////////////////////////////////////////////////////////////////////
        // Private Methods
        ////////////////////////////////////////////////////////////////////////

        private void UpdateLineRendererPositions(ZPointer pointer)
        {
            // Update the end point.
            Vector3 hitPosition = pointer.HitInfo.worldPosition;

            if (pointer.AnyButtonPressed)
            {
                this._endPoint = hitPosition;
            }
            else
            {
                this._endPoint = Vector3.SmoothDamp(
                    this._endPoint, hitPosition, ref this._velocity, this.EndPointSmoothTime);
            }

            // Compute the control points for the line renderer's quadratic
            // bezier curve. Additionally, transform the control points to be
            // in the local space of the pointer since the current assumption
            // is that the line renderer is a child of the pointer.
            Vector3 p0 = pointer.transform.position;
            Vector3 p2 = this._endPoint;
            Vector3 p1 = p0 + Vector3.Project(p2 - p0, pointer.transform.forward);

            Matrix4x4 worldToLocalMatrix = this.transform.worldToLocalMatrix;

            p0 = worldToLocalMatrix.MultiplyPoint(p0);
            p1 = worldToLocalMatrix.MultiplyPoint(p1);
            p2 = worldToLocalMatrix.MultiplyPoint(p2);

            this._lineRenderer.SetPosition(0, p0);
            this._lineRenderer.SetBezierCurve(
                1, Vector3.Lerp(p0, p1, this.CurveStartPivot), p1, p2);
        }
Beispiel #2
0
        /// <summary>
        /// Get the interactable's specified drag plane.
        /// </summary>
        /// <param name="pointer"></param>
        /// <returns></returns>
        public virtual Plane GetDragPlane(ZPointer pointer)
        {
            if (pointer.DefaultCustomDragPlane != null)
            {
                return(pointer.DefaultCustomDragPlane(pointer));
            }

            return(default(Plane));
        }
Beispiel #3
0
        ////////////////////////////////////////////////////////////////////////
        // Public Methods
        ////////////////////////////////////////////////////////////////////////

        /// <summary>
        /// Overrides the pointer's current drag policy for this interactable.
        /// </summary>
        ///
        /// <param name="pointer">
        /// A reference to the pointer currently interacting with this
        /// interactable.
        /// </param>
        ///
        /// <returns>
        /// The interactable's drag policy.
        /// </returns>
        public virtual ZPointer.DragPolicy GetDragPolicy(ZPointer pointer)
        {
            if (this.GetComponent <RectTransform>() != null)
            {
                return(pointer.UIDragPolicy);
            }
            else
            {
                return(pointer.ObjectDragPolicy);
            }
        }
        ////////////////////////////////////////////////////////////////////////
        // Public Properties
        ////////////////////////////////////////////////////////////////////////

        public override void Process(ZPointer pointer, Vector3 worldScale)
        {
            base.Process(pointer, worldScale);

            this._lineRenderer.gameObject.SetActive(pointer.IsVisible);

            this._lineRenderer.widthMultiplier =
                this._originalWidthMultiplier *
                Mathf.Min(worldScale.x, worldScale.y);

            this.UpdateLineRendererPositions(pointer);
        }
        ////////////////////////////////////////////////////////////////////////
        // Public Properties
        ////////////////////////////////////////////////////////////////////////

        public override void Process(ZPointer pointer, Vector3 worldScale)
        {
            base.Process(pointer, worldScale);

            // Update the mouse cursor's position and rotation.
            this.transform.SetPose(this.GetEndPointPose(pointer));

            // Update the mouse cursor's scale based on whether
            // stereoscopic 3D rendering is currently active. When
            // rendering in monoscopic 3D, scale the cursor based on its
            // distance from the camera.
            float distanceScale = this.GetCameraDistanceScale(
                pointer.EventCamera, this.transform.position);

            this.transform.localScale = Vector3.Lerp(
                Vector3.one * distanceScale,
                worldScale,
                pointer.EventCamera.StereoWeight);

            // Update whether the mouse cursor should be flipped about its
            // horizontal and vertical axes based on the hit normal in
            // screen space. This will minimize the chance that the mouse
            // cursor will be occluded by the object it is intersecting.
            if (!pointer.AnyButtonPressed)
            {
                float flipThreshold = 89;

                Vector3 screenNormal =
                    Quaternion.Inverse(this.transform.rotation) *
                    pointer.HitInfo.worldNormal;

                this._flipHorizontal =
                    (Vector3.Angle(screenNormal, Vector3.left) < flipThreshold);

                this._flipVertical =
                    (Vector3.Angle(screenNormal, Vector3.up) < flipThreshold);
            }

            // Update the mouse cursor's corresponding sprite.
            this.UpdateSprite();
        }
        ////////////////////////////////////////////////////////////////////////
        // Private Methods
        ////////////////////////////////////////////////////////////////////////

        private Pose GetEndPointPose(ZPointer pointer)
        {
            if (pointer.AnyButtonPressed || pointer.MaxHitRadius == 0)
            {
                this._positionWeight = 1;
            }
            else if (pointer.HitInfo.gameObject != this._previousHitObject)
            {
                this._positionWeight = 0;
                this._startPosition  = this.transform.position;
            }

            Pose pose = pointer.EndPointWorldPose;

            pose.position =
                Vector3.Lerp(this._startPosition, pose.position, this._positionWeight) +
                (pose.rotation * Vector3.back * 0.0001f);

            this._previousHitObject = pointer.HitInfo.gameObject;
            this._positionWeight   += Time.unscaledDeltaTime / this.SnapDuration;
            this._positionWeight    = Mathf.Clamp01(this._positionWeight);

            return(pose);
        }
 public virtual void Process(ZPointer pointer, Vector3 worldScale)
 {
 }