Beispiel #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);
        }
Beispiel #2
0
        // 绘制 Node 控件
        void DrawNodeControls(bool edit)
        {
            _count = nodeCount;

            for (int i = 0; i < _count; i++)
            {
                // 获取控制点位置
                _back    = GetBackControlPoint(i);
                _forward = GetForwardControlPoint(i);
                _middle  = GetMiddleControlPoint(i);

                // 绘制切线
                Handles.color = _controlLineColor;
                EditorKit.HandlesDrawAALine(_back, _middle);
                EditorKit.HandlesDrawAALine(_forward, _middle);

                // 绘制后控制点

                EditorGUI.BeginChangeCheck();
                EditorKit.BeginHotControlChangeCheck();

                if (_selectionType == SelectionType.BackControlPoint && _selectedItem == i)
                {
                    Handles.color = _capSelectedColor;
                }
                else
                {
                    Handles.color = _capNormalColor;
                }

                _handleSize = HandleUtility.GetHandleSize(_back) * _controlPointCapSize;
                _back       = Handles.FreeMoveHandle(_back, _identityQuaternion, _handleSize, _zeroVector3, Handles.DotCap);

                // 更新选择
                if (EditorKit.EndHotControlChangeCheck() == HotControlEvent.MouseDown)
                {
                    _selectionType = SelectionType.BackControlPoint;
                    _selectedItem  = i;
                }

                // 修改后控制点
                if (EditorGUI.EndChangeCheck() && edit)
                {
                    Undo.RecordObject(this, undoBackControlPoint);
                    SetBackControlPoint(i, _back);
                    EditorUtility.SetDirty(this);
                }

                // 绘制中控制点

                EditorGUI.BeginChangeCheck();
                EditorKit.BeginHotControlChangeCheck();

                if (_selectionType == SelectionType.MiddleControlPoint && _selectedItem == i)
                {
                    Handles.color = _capSelectedColor;
                }
                else
                {
                    Handles.color = _capNormalColor;
                }

                _handleSize = HandleUtility.GetHandleSize(_middle) * _controlPointCapSize;
                _middle     = Handles.FreeMoveHandle(_middle, _identityQuaternion, _handleSize, _zeroVector3, Handles.DotCap);

                // 更新选择
                if (EditorKit.EndHotControlChangeCheck() == HotControlEvent.MouseDown)
                {
                    _selectionType = SelectionType.MiddleControlPoint;
                    _selectedItem  = i;
                }

                // 修改中控制点
                if (EditorGUI.EndChangeCheck() && edit)
                {
                    Undo.RecordObject(this, undoMiddleControlPoint);
                    SetMiddleControlPoint(i, _middle);
                    EditorUtility.SetDirty(this);
                }

                // 绘制前控制点

                EditorGUI.BeginChangeCheck();
                EditorKit.BeginHotControlChangeCheck();

                if (_selectionType == SelectionType.ForwardControlPoint && _selectedItem == i)
                {
                    Handles.color = _capSelectedColor;
                }
                else
                {
                    Handles.color = _capNormalColor;
                }

                _handleSize = HandleUtility.GetHandleSize(_forward) * _controlPointCapSize;
                _forward    = Handles.FreeMoveHandle(_forward, _identityQuaternion, _handleSize, _zeroVector3, Handles.DotCap);

                // 更新选择
                if (EditorKit.EndHotControlChangeCheck() == HotControlEvent.MouseDown)
                {
                    _selectionType = SelectionType.ForwardControlPoint;
                    _selectedItem  = i;
                }

                // 修改前控制点
                if (EditorGUI.EndChangeCheck() && edit)
                {
                    Undo.RecordObject(this, undoForwardControlPoint);
                    SetForwardControlPoint(i, _forward);
                    EditorUtility.SetDirty(this);
                }
            }
        }
Beispiel #3
0
		protected override void DrawKeyValueInScene(Vector3 position, Quaternion value, float handleSize)
		{
			if (_space == RotationSpace.Path) value = path.TransformRotation(value);
			EditorKit.HandlesDrawAALine(position, position + handleSize * (value * Vector3.up));
			Handles.ArrowCap(0, position, value, handleSize);
		}