Esempio n. 1
0
        // 绘制选中后控制点时的控件
        void DrawBackControlPointUI(Rect rect)
        {
            _lineRect.Set(rect.xMax + _toolBarHorizontalInterval, rect.y + (rect.height - _toolBarLineHeight) * 0.5f, _positionWidth, _toolBarLineHeight);

            EditorGUI.BeginChangeCheck();
            _back = EditorGUI.Vector3Field(_lineRect, GUIContent.none, GetBackTangent(_selectedItem, Space.Self));
            if (EditorGUI.EndChangeCheck())
            {
                Undo.RecordObject(this, undoBackControlPoint);
                SetBackTangent(_selectedItem, _back, Space.Self);
                EditorUtility.SetDirty(this);
            }

            // 前一个
            rect.Set(_lineRect.xMax + _toolBarHorizontalInterval, rect.y + (rect.height - _toolBarButtonHeight) * 0.5f, _toolBarButtonWidth, _toolBarButtonHeight);

            if (GUI.Button(rect, EditorKit.GlobalContent(null, EditorAssets.prevTexture, "Previous back control point"), EditorKit.buttonLeftStyle))
            {
                _selectedItem = (_selectedItem == 0) ? (nodeCount - 1) : (_selectedItem - 1);
            }

            // 后一个
            rect.x = rect.xMax;

            if (GUI.Button(rect, EditorKit.GlobalContent(null, EditorAssets.nextTexture, "Next back control point"), EditorKit.buttonRightStyle))
            {
                _selectedItem = (_selectedItem == nodeCount - 1) ? 0 : (_selectedItem + 1);
            }
        }
Esempio n. 2
0
        // 绘制选中路径段时的控件
        void DrawSplineUI(Rect rect)
        {
            _lineRect.Set(rect.xMax + _toolBarHorizontalInterval, rect.y + (rect.height - _toolBarLineHeight) * 0.5f, _tensionWidth, _toolBarLineHeight);

            // Tension

            EditorGUI.BeginChangeCheck();
            EditorKit.RecordAndSetLabelWidth(_tensionLabelWidth);
            float tension = EditorGUI.FloatField(_lineRect, "Tension", GetTension(_selectedItem));

            EditorKit.RestoreLabelWidth();
            if (EditorGUI.EndChangeCheck())
            {
                Undo.RecordObject(this, "Tension");
                SetTension(_selectedItem, tension);
                EditorUtility.SetDirty(this);
            }

            // Insert Node

            rect.Set(_lineRect.xMax + _toolBarHorizontalInterval, rect.y + (rect.height - _toolBarButtonHeight) * 0.5f, _toolBarButtonWidth, _toolBarButtonHeight);

            if (GUI.Button(rect, EditorKit.GlobalContent(null, EditorAssets.insertNodeTexture, "Insert node"), EditorKit.buttonStyle))
            {
                Undo.RecordObject(this, "Insert Node");

                _selectedTool             = 2;
                _selectionType            = SelectionType.MiddleControlPoint;
                InsertNode(_selectedItem += 1);

                EditorUtility.SetDirty(this);

                return;
            }

            // 前一个

            rect.x = rect.xMax + _toolBarHorizontalInterval;

            if (GUI.Button(rect, EditorKit.GlobalContent(null, EditorAssets.prevTexture, "Previous segment"), EditorKit.buttonLeftStyle))
            {
                _selectedItem = (_selectedItem == 0) ? (segmentCount - 1) : (_selectedItem - 1);
            }

            // 后一个

            rect.x = rect.xMax;

            if (GUI.Button(rect, EditorKit.GlobalContent(null, EditorAssets.nextTexture, "Next segment"), EditorKit.buttonRightStyle))
            {
                _selectedItem = (_selectedItem == segmentCount - 1) ? 0 : (_selectedItem + 1);
            }
        }
Esempio n. 3
0
        protected static void ColorRGBField(SerializedProperty toggle, SerializedProperty from, SerializedProperty to, bool hdr)
        {
            _labelWidth = EditorGUIUtility.labelWidth;

            _rect       = EditorGUILayout.GetControlRect();
            _lineWidth  = _rect.width;
            _fieldWidth = (_lineWidth * (1f - _intervalRatio - _intervalRatio - _toggleRatio) - _fromLabelWidth - _toLabelWidth) * 0.5f;

            _rect.width      = _lineWidth * _toggleRatio;
            toggle.boolValue = EditorGUI.ToggleLeft(_rect, "RGB", toggle.boolValue);

            EditorGUIUtility.labelWidth = _fromLabelWidth;
            _rect.x     = _rect.xMax + _lineWidth * _intervalRatio;
            _rect.width = _fieldWidth + _fromLabelWidth;

#if UNITY_5_3_OR_NEWER
            if (hdr)
            {
                from.colorValue = EditorGUI.ColorField(_rect, EditorKit.GlobalContent("From"), from.colorValue, true, true, true, EditorKit.colorPickerHDRConfig);
            }
            else
#endif
            {
                from.colorValue = EditorGUI.ColorField(_rect, "From", from.colorValue);
            }

            EditorGUIUtility.labelWidth = _toLabelWidth;
            _rect.x     = _rect.xMax + _lineWidth * _intervalRatio;
            _rect.width = _fieldWidth + _toLabelWidth;

#if UNITY_5_3_OR_NEWER
            if (hdr)
            {
                to.colorValue = EditorGUI.ColorField(_rect, EditorKit.GlobalContent("To"), to.colorValue, true, true, true, EditorKit.colorPickerHDRConfig);
            }
            else
#endif
            {
                to.colorValue = EditorGUI.ColorField(_rect, "To", to.colorValue);
            }

            EditorGUIUtility.labelWidth = _labelWidth;
        }
Esempio n. 4
0
        protected override void DrawExtraFields()
        {
            EditorGUILayout.PropertyField(_colorModeProperty);

            if (colorMode == ColorMode.Gradient)
            {
                EditorGUILayout.PropertyField(_gradientProperty);
            }
            else
            {
                EditorGUI.BeginChangeCheck();
                EditorGUILayout.PropertyField(_hdrProperty, EditorKit.GlobalContent("HDR"));
                if (EditorGUI.EndChangeCheck() && !_hdrProperty.boolValue)
                {
                    if (_from.maxColorComponent > 1f)
                    {
                        var max = _from.maxColorComponent;
                        var c   = new Color(_from.r / max, _from.g / max, _from.b / max, _from.a);
                        _fromProperty.colorValue = c;
                    }
                    if (_to.maxColorComponent > 1f)
                    {
                        var max = _to.maxColorComponent;
                        var c   = new Color(_to.r / max, _to.g / max, _to.b / max, _to.a);
                        _toProperty.colorValue = c;
                    }
                }

#if !UNITY_5_3_OR_NEWER
                if (hdr)
                {
                    EditorGUILayout.HelpBox("HDR color picker requires Unity 5.3 or higher.", MessageType.Info, false);
                }
#endif

                ColorRGBField(_toggleRGBProperty, _fromProperty, _toProperty, hdr);
                ClampedFloatChannelField(_toggleAlphaProperty, "A", _fromAlphaProperty, _toAlphaProperty, 0f, 1f);
            }
        }
Esempio n. 5
0
        // 绘制选中中控制点时的控件
        void DrawMiddleControlPointUI(Rect rect)
        {
            // Position

            _lineRect.Set(rect.xMax + _toolBarHorizontalInterval, rect.y + (rect.height - _toolBarLineHeight) * 0.5f, _positionWidth, _toolBarLineHeight);

            EditorGUI.BeginChangeCheck();
            _middle = EditorGUI.Vector3Field(_lineRect, GUIContent.none, GetMiddleControlPoint(_selectedItem, Space.Self));
            if (EditorGUI.EndChangeCheck())
            {
                Undo.RecordObject(this, undoMiddleControlPoint);
                SetMiddleControlPoint(_selectedItem, _middle, Space.Self);
                EditorUtility.SetDirty(this);
            }

            // Broken

            _lineRect.x     = _lineRect.xMax + _toolBarHorizontalInterval;
            _lineRect.width = _brokenWidth;

            EditorGUI.BeginChangeCheck();
            bool broken = EditorGUI.ToggleLeft(_lineRect, "Broken", IsNodeBroken(_selectedItem));

            if (EditorGUI.EndChangeCheck())
            {
                Undo.RecordObject(this, "Broken");
                SetNodeBroken(_selectedItem, broken);
                EditorUtility.SetDirty(this);
            }

            // Insert Back

            rect.Set(_lineRect.xMax + _toolBarHorizontalInterval, rect.y + (rect.height - _toolBarButtonHeight) * 0.5f, _toolBarButtonWidth, _toolBarButtonHeight);

            if (GUI.Button(rect, EditorKit.GlobalContent(null, EditorAssets.insertNodeBackTexture, "Insert Back"), EditorKit.buttonLeftStyle))
            {
                Undo.RecordObject(this, "Insert Node");
                InsertNode(_selectedItem);
                EditorUtility.SetDirty(this);

                return;
            }

            // Insert Forward

            rect.x = rect.xMax;

            if (GUI.Button(rect, EditorKit.GlobalContent(null, EditorAssets.insertNodeForwardTexture, "Insert Forward"), EditorKit.buttonRightStyle))
            {
                Undo.RecordObject(this, "Insert Node");
                InsertNode(_selectedItem += 1);
                EditorUtility.SetDirty(this);

                return;
            }

            // Remove Node

            rect.x = rect.xMax + _toolBarHorizontalInterval;

            EditorGUI.BeginDisabledGroup(nodeCount <= 2);

            if (GUI.Button(rect, EditorKit.GlobalContent(null, EditorAssets.removeNodeTexture, "Remove node"), EditorKit.buttonStyle))
            {
                Undo.RecordObject(this, "Remove Node");
                RemoveNode(_selectedItem);
                EditorUtility.SetDirty(this);

                return;
            }

            EditorGUI.EndDisabledGroup();

            // 前一个

            rect.x = rect.xMax + _toolBarHorizontalInterval;

            if (GUI.Button(rect, EditorKit.GlobalContent(null, EditorAssets.prevTexture, "Previous middle control point"), EditorKit.buttonLeftStyle))
            {
                _selectedItem = (_selectedItem == 0) ? (nodeCount - 1) : (_selectedItem - 1);
            }

            // 后一个

            rect.x = rect.xMax;

            if (GUI.Button(rect, EditorKit.GlobalContent(null, EditorAssets.nextTexture, "Next middle control point"), EditorKit.buttonRightStyle))
            {
                _selectedItem = (_selectedItem == nodeCount - 1) ? 0 : (_selectedItem + 1);
            }
        }