private Vector3 GetEndPoint(LeanFinger finger, Vector3 start)
        {
            // Cauculate distance based on start position, because the Target point may override Distance
            var end    = ScreenDepth.Convert(finger.ScreenPosition, gameObject);
            var length = Vector3.Distance(start, end);

            // Limit the length?
            if (LengthMin > 0.0f && length < LengthMin)
            {
                length = LengthMin;
            }

            if (LengthMax > 0.0f && length > LengthMax)
            {
                length = LengthMax;
            }

            // Recalculate end
            var delta = Vector3.Normalize(end - start) * length;

            return(Inverse == true ? start - delta : start + delta);
        }
Example #2
0
        protected override void UpdateLine(FingerData fingerData, LeanFinger finger, LineRenderer line)
        {
            var color0 = StartColor;
            var color1 = EndColor;
            var width  = fingerData.Width;

            if (finger != null)
            {
                // Reserve points
                line.positionCount = 2;

                // Calculate preliminary points
                var point0 = ScreenDepth.Convert(finger.StartScreenPosition, gameObject);
                var point1 = ScreenDepth.Convert(finger.ScreenPosition, gameObject);

                if (StartAtOrigin == true)
                {
                    point0 = transform.position;
                }

                // Get length, and clamp?
                var length = Vector3.Distance(point0, point1);

                if (LengthMin >= 0.0f && length < LengthMin)
                {
                    length = LengthMin;
                }

                if (LengthMax >= 0.0f && length > LengthMax)
                {
                    length = LengthMax;
                }

                if (Invert == true)
                {
                    point1 = point0 - (point1 - point0);
                }

                // Write straight line
                line.SetPosition(0, point0);
                line.SetPosition(1, point0 + Vector3.Normalize(point1 - point0) * length);
            }
            else
            {
                fingerData.Age += Time.deltaTime;

                var alpha = Mathf.InverseLerp(FadeTime, 0.0f, fingerData.Age);

                color0.a *= alpha;
                color1.a *= alpha;
            }

            if (WidthScale != 0.0f && line.positionCount == 2)
            {
                var point0 = line.GetPosition(0);
                var point1 = line.GetPosition(1);
                var length = Vector3.Distance(point0, point1);

                width += length * WidthScale;
            }

            line.startColor      = color0;
            line.endColor        = color1;
            line.widthMultiplier = width;
        }