Beispiel #1
0
        void Update()
        {
            foreach (DataSet d in dataSets)
            {
                int lengthOfArray = d.values.Count;
                if (d.currentlyInterpolating)
                {
                    if (d.interpolateAmt >= 1f)
                    {
                        // finished interpolating, so add it to the list
                        d.values.Add(d.valueToAdd);
                        d.currentlyInterpolating = false;
                        d.interpolateAmt         = 0f;
                    }
                    lengthOfArray++;
                }

                Vector2[] newPointArray = new Vector2[lengthOfArray];
                Vector2   lastPoint     = new Vector2(0, 0);
                for (int i = 0; i < d.values.Count; i++)
                {
                    // Let's scale the points to fit the whatchamacallit

                    Vector2 point = d.values[i];

                    // point.x /= xBounds.y;
                    // point.y /= yBounds.y;

                    // point.x -= xBounds.x / xBounds.y;
                    // point.y -= yBounds.x / yBounds.y;

                    point.x = NiceExtensions.InverseLerpUnclamped(xBounds.x, xBounds.y, point.x);
                    point.y = NiceExtensions.InverseLerpUnclamped(yBounds.x, yBounds.y, point.y);

                    newPointArray[i] = point;
                    lastPoint        = point;
                }

                if (d.currentlyInterpolating)
                {
                    float   interpX     = d.valueToAdd.x / xBounds.y;
                    float   interpY     = d.valueToAdd.y / yBounds.y;
                    Vector2 interpPoint = new Vector2(Mathf.SmoothStep(lastPoint.x, interpX, d.interpolateAmt), Mathf.SmoothStep(lastPoint.y, interpY, d.interpolateAmt));
                    newPointArray[lengthOfArray - 1] = interpPoint;
                    d.interpolateAmt += Time.deltaTime * animationSpeed;
                }
                d.lineRenderer.Points        = newPointArray;
                d.lineRenderer.LineThickness = lineWidth;


                d.lineRenderer.color = d.mainColor;
            }

            gridRenderer.color = gridColor;
        }
Beispiel #2
0
    public void Start()
    {
        DOTween.Init();

        float a   = 0;
        float b   = 1;
        float val = 2;

        float origLerpInverse = Mathf.InverseLerp(a, b, val);
        float myLerpInverse   = NiceExtensions.InverseLerpUnclamped(a, b, val);

        Debug.Log(string.Format("Normal lerp inverse gives {0}, mine gives {1}", origLerpInverse, myLerpInverse));
    }