protected static void FromToFieldLayout(string label, ref float from, ref float to, out bool fromChanged, out bool toChanged)
        {
            var   rect       = EditorGUILayout.GetControlRect();
            float labelWidth = EditorGUIUtility.labelWidth;

            var fromRect = new Rect(rect.x + labelWidth, rect.y, (rect.width - labelWidth) / 2 - 2, rect.height);
            var toRect   = new Rect(rect.xMax - fromRect.width, fromRect.y, fromRect.width, fromRect.height);

            rect.width = labelWidth - 8;

            // new GUIContent
            var content = new GUIContent();

            content.text = label;
            EditorGUI.LabelField(rect, content);

            rect.width = EditorStyles.label.CalcSize(content).x;
            float delta = EditorEx.DragValue(rect, 0, 0.01f);

            using (new LabelWidthScope(14)) {
                float newFrom = EditorGUI.FloatField(fromRect, "F", from + delta);
                float newTo   = EditorGUI.FloatField(toRect, "T", to + delta);

                fromChanged = from != newFrom;
                from        = newFrom;

                toChanged = to != newTo;
                to        = newTo;
            }
        }
Esempio n. 2
0
        public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
        {
            position = EditorGUI.PrefixLabel(position, label);

            var typeProp     = property.FindPropertyRelative("type");
            int type         = typeProp.intValue;
            var strengthProp = property.FindPropertyRelative("strength");

            var image = (Texture2D)EditorGUIUtility.Load("Builtin Skins/DarkSkin/Images/pane options.png");

            var btnRect = new Rect(position.x + 1, position.y + 2, image.width, image.height);

            using (var scope = new ChangeCheckScope(null)) {
                EditorGUIUtility.AddCursorRect(btnRect, MouseCursor.Arrow);

                System.Enum newType;
                if (fieldInfo.FieldType == typeof(CustomizableInterpolator))
                {
                    newType = EditorGUI.EnumPopup(btnRect, GUIContent.none, (CustomizableInterpolator.Type)type, ButtonStyle);
                }
                else
                {
                    newType = EditorGUI.EnumPopup(btnRect, GUIContent.none, (Interpolator.Type)type, ButtonStyle);
                }

                if (scope.Changed)
                {
                    typeProp.intValue       = type = (int)(CustomizableInterpolator.Type)newType;
                    strengthProp.floatValue = .5f;
                }
            }

            if ((CustomizableInterpolator.Type)type == CustomizableInterpolator.Type.CustomCurve)
            {
                EditorGUIUtility.AddCursorRect(position, MouseCursor.Zoom);
                EditorGUI.PropertyField(position, property.FindPropertyRelative("customCurve"), GUIContent.none);
            }
            else
            {
                bool drawStrength;

                switch ((CustomizableInterpolator.Type)type)
                {
                case CustomizableInterpolator.Type.Linear:
                case CustomizableInterpolator.Type.Parabolic:
                case CustomizableInterpolator.Type.Sine:
                    drawStrength = false;
                    break;

                default:
                    strengthProp.floatValue = Mathf.Clamp01(EditorEx.DragValue(position, strengthProp.floatValue, .01f));
                    drawStrength            = true;
                    break;
                }

                if (Event.current.type == EventType.Repaint)
                {
                    Sample(type, strengthProp.floatValue, Mathf.Min((int)position.width, 256), .002f);
                    DrawCurve(position, drawStrength);
                }
            }

            var content = new GUIContent();

            content.image = image;
            EditorGUI.LabelField(btnRect, content, GUIStyle.none);
        }