Пример #1
0
        private void DrawnPath(Rect r, recordType type, double scaleX, bool downRange, Color color)
        {
            if (recorder.history.Length <= 2 || recorder.historyIdx == 0)
            {
                return;
            }

            graphState graphState = graphStates[(int)type];

            double scaleY = (graphState.maximum - graphState.minimum) / height;

            float yBase = r.yMax + (float)(graphState.minimum / scaleY);

            Vector2 p1 = new Vector2(r.xMin + (float)((downRange ? recorder.history[0].downRange : recorder.history[0].timeSinceMark) / scaleX), yBase - (float)(recorder.history[0][type] / scaleY));
            Vector2 p2 = new Vector2();

            int t = 1;

            while (t <= recorder.historyIdx && t < recorder.history.Length)
            {
                var rec = recorder.history[t];
                p2.x = r.xMin + (float)((downRange ? rec.downRange : rec.timeSinceMark) / scaleX);
                p2.y = yBase - (float)(rec[type] / scaleY);

                // skip 0 length line but always drawn the first 2 points
                if (r.Contains(p2) && ((p1 - p2).sqrMagnitude >= 1.0 || t < 2))
                {
                    Drawing.DrawLine(p1, p2, color, 2, true);

                    p1.x = p2.x;
                    p1.y = p2.y;
                }
                t++;
            }
        }
        private void DrawScaleLabels(Rect r)
        {
            if (scaleIdx == 0)
            {
                return;
            }

            const int w             = 80;
            const int h             = 20;
            GUIStyle  centeredStyle = new GUIStyle(GUI.skin.label)
            {
                alignment = TextAnchor.MiddleRight
            };

            graphState state = graphStates[scaleIdx];

            if (state.labels == null)
            {
                return;
            }

            int    count     = state.labelsActive;
            double invScaleY = height / (state.maximum - state.minimum);
            float  yBase     = r.yMax + (float)(state.minimum * invScaleY);

            for (int i = 0; i < count; i++)
            {
                GUI.Label(new Rect(r.xMin - w, yBase - (float)(invScaleY * state.labelsPos[i]) - h * 0.5f, w, h), state.labels[i], centeredStyle);
            }
        }