InverseLerp() public static method

public static InverseLerp ( float from, float to, float value ) : float
from float
to float
value float
return float
Example #1
0
        public float Update()
        {
            _currentTime = _currentTime + Time.deltaTime;
            if (_currentTime > _duration)
            {
                _currentTime = _duration;
            }

            // how far into the time are we?
            var percentageComplete = Math.InverseLerp(0, _duration, _currentTime);

            // return a new morph value that represents progressing _currentTime thorugh things
            return(_startValue + ((_targetValue - _startValue) * _easing(percentageComplete)));
        }
Example #2
0
        public void LateUpdate()
        {
            if (!show || (!Application.isPlaying && !showInEditor))
            {
                return;
            }

            if (Time.unscaledDeltaTime <= 0.0001f)
            {
                return;
            }

            int collCount = System.GC.CollectionCount(0);

            if (lastCollectNum != collCount)
            {
                lastCollectNum = collCount;
                delta          = Time.realtimeSinceStartup - lastCollect;
                lastCollect    = Time.realtimeSinceStartup;
                lastDeltaTime  = Time.unscaledDeltaTime;
                collectAlloc   = allocMem;
            }

            allocMem = (int)System.GC.GetTotalMemory(false);

            bool collectEvent = allocMem < peakAlloc;

            peakAlloc = !collectEvent ? allocMem : peakAlloc;

            if (Time.realtimeSinceStartup - lastAllocSet > 0.3F || !Application.isPlaying)
            {
                int diff = allocMem - lastAllocMemory;
                lastAllocMemory  = allocMem;
                lastAllocSet     = Time.realtimeSinceStartup;
                delayedDeltaTime = Time.unscaledDeltaTime;

                if (diff >= 0)
                {
                    allocRate = diff;
                }
            }

            if (Application.isPlaying)
            {
                fpsDrops[Time.frameCount % fpsDrops.Length] = Time.unscaledDeltaTime > 0.00001f ? 1F / Time.unscaledDeltaTime : 0;
                int graphIndex = Time.frameCount % graph.Length;
                graph[graphIndex].fps          = Time.unscaledDeltaTime < 0.00001f ? 1F / Time.unscaledDeltaTime : 0;
                graph[graphIndex].collectEvent = collectEvent;
                graph[graphIndex].memory       = allocMem;
            }

            if (Application.isPlaying && cam != null && showGraph)
            {
                graphWidth = cam.pixelWidth * 0.8f;


                float minMem = float.PositiveInfinity, maxMem = 0, minFPS = float.PositiveInfinity, maxFPS = 0;
                for (int i = 0; i < graph.Length; i++)
                {
                    minMem = Mathf.Min(graph[i].memory, minMem);
                    maxMem = Mathf.Max(graph[i].memory, maxMem);
                    minFPS = Mathf.Min(graph[i].fps, minFPS);
                    maxFPS = Mathf.Max(graph[i].fps, maxFPS);
                }

                int currentGraphIndex = Time.frameCount % graph.Length;

                Matrix4x4 m = Matrix4x4.TRS(new Vector3((cam.pixelWidth - graphWidth) / 2f, graphOffset, 1), Quaternion.identity, new Vector3(graphWidth, graphHeight, 1));

                for (int i = 0; i < graph.Length - 1; i++)
                {
                    if (i == currentGraphIndex)
                    {
                        continue;
                    }

                    DrawGraphLine(i, m, i / (float)graph.Length, (i + 1) / (float)graph.Length, Mathf.InverseLerp(minMem, maxMem, graph[i].memory), Mathf.InverseLerp(minMem, maxMem, graph[i + 1].memory), Color.blue);
                    DrawGraphLine(i, m, i / (float)graph.Length, (i + 1) / (float)graph.Length, Mathf.InverseLerp(minFPS, maxFPS, graph[i].fps), Mathf.InverseLerp(minFPS, maxFPS, graph[i + 1].fps), Color.green);
                }
            }
        }
Example #3
0
 /// <summary>
 /// Rescale parameter `v` which is in range (minA, maxA) to be in range (minB, maxB)
 /// </summary>
 /// <param name="v">Value to rescale</param>
 /// <param name="minA">Min value of original interval</param>
 /// <param name="maxA">Max value of original interval</param>
 /// <param name="minB">Min value of new interval</param>
 /// <param name="maxB">Max value of new interval</param>
 /// <returns></returns>
 private static float Rescale(float v, float minA, float maxA, float minB, float maxB)
 {
     return(Mathf.Lerp(minB, maxB, Mathf.InverseLerp(minA, maxA, v)));
 }