private static void OnGUI()
    {
        if (!s_displayGraph)
        {
            return;
        }

        int curveI = 0;

        GraphDrawer.Curve GetCurve()
        {
            if (curveI == s_curveCache.Count)
            {
                s_curveCache.Add(new GraphDrawer.Curve());
            }
            return(s_curveCache[curveI]);
        }

        for (int i = 0; i < s_loggedCurves.Count; i++)
        {
            LoggedCurve loggedCurve = s_loggedCurves[i];

            // remove all points that are older than TIME_RANGE
            for (int p = 0; p < loggedCurve.Points.Count - 1; p++)
            {
                if (Time.time - loggedCurve.Points[p].x > TIME_RANGE &&
                    Time.time - loggedCurve.Points[p + 1].x > TIME_RANGE)
                {
                    loggedCurve.Points.RemoveAt(p);
                    p--;
                }
            }

            if (loggedCurve.Points.Count == 0)
            {
                s_loggedCurves.RemoveAt(i);
                i--;
            }
            else
            {
                GraphDrawer.Curve coloredCurve = GetCurve();

                coloredCurve.Positions.Clear();
                coloredCurve.Positions.AddRange(loggedCurve.Points);
            }
        }

        s_graphDrawer.ScreenDisplayRect.xMin = Time.time - TIME_RANGE;
        s_graphDrawer.ScreenDisplayRect.xMax = Time.time;
        s_graphDrawer.Draw();
    }
    public static void Log(string curveName, float value)
    {
        LoggedCurve curve = null;

        for (int i = 0; i < s_loggedCurves.Count; i++)
        {
            if (s_loggedCurves[i].Name == curveName)
            {
                curve = s_loggedCurves[i];
            }
        }

        if (curve == null)
        {
            s_loggedCurves.Add(curve = new LoggedCurve());
        }

        curve.Points.Add(new Vector2(Time.time, value));
    }