Ejemplo n.º 1
0
        void DoDrawGizmos()
        {
            _pathMatrix.SetTRS(transform.position, transform.rotation, new Vector3(_worldScale, _worldScale, _worldScale));
            EditorKit.RecordAndSetHandlesMatrix(ref _pathMatrix);

            // 绘制路径

            int highlight = _currentEditing == this ? highlightSplineIndex : -1;

            for (int i = 0; i < _localSegments.Count; i++)
            {
                _localSegments[i].Draw(highlight == i ? _highlightColor : _normalColor, _splineWidth);
            }

            // 绘制箭头

            EditorKit.RecordAndSetHandlesColor(_highlightColor);

            Vector3 point    = _localSegments[_localSegments.Count - 1].GetPoint(1f);
            float   scale    = HandleUtility.GetHandleSize(point) / Mathf.Abs(_worldScale);
            Vector3 vector   = new Vector3(0.08f, 0f, -0.24f) * scale;
            var     rotation = Quaternion.LookRotation(_localSegments[_localSegments.Count - 1].GetTangent(1f), Vector3.up);

            Handles.DrawLine(point, point + rotation * vector);
            vector.x = -vector.x;
            Handles.DrawLine(point, point + rotation * vector);

            EditorKit.RestoreHandlesColor();

            EditorKit.RestoreHandlesMatrix();
        }
Ejemplo n.º 2
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);
        }