Esempio n. 1
0
        // 绘制曲线
        void DrawCurve(Rect rect, Color backgroundColor, Color range01Color, Color curveColor, Color borderColor)
        {
            EditorGUI.DrawRect(rect, backgroundColor);

            Vector2 origin = new Vector2(rect.x + 1, rect.y + 1);
            Vector2 scale  = new Vector2(rect.width - 2, (rect.height - 2) / (_maxValue - _minValue));

            if (_maxValue > 0f && _minValue < 1f)
            {
                float yMin   = origin.y + (_maxValue - Mathf.Min(_maxValue, 1f)) * scale.y;
                float yMax   = origin.y + (_maxValue - Mathf.Max(_minValue, 0f)) * scale.y;
                Rect  rect01 = new Rect(rect.x, yMin, rect.width, yMax - yMin);
                EditorGUI.DrawRect(rect01, range01Color);
            }

            Vector3 last = _samples[0];

            last.x = origin.x + last.x * scale.x;
            last.y = origin.y + (_maxValue - last.y) * scale.y;

            EditorKit.RecordAndSetHandlesColor(curveColor);
            Vector3 point;

            for (int i = 1; i < _samples.Count; i++)
            {
                point   = _samples[i];
                point.x = origin.x + point.x * scale.x;
                point.y = origin.y + (_maxValue - point.y) * scale.y;

                EditorKit.HandlesDrawAALine(last, point);
                last = point;
            }

            EditorKit.RestoreHandlesColor();
            EditorKit.DrawWireRect(rect, borderColor);
        }