public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
        {
            var targ = (Interval)EditorHelper.GetTargetObjectOfProperty(property);

            var   attrib             = this.fieldInfo.GetCustomAttributes(typeof(Interval.ConfigAttribute), false).Cast <Interval.ConfigAttribute>().FirstOrDefault();
            bool  reverse            = (attrib != null) ? attrib.Reverse : false;
            float minValue           = (attrib != null) ? attrib.MinValue : float.NegativeInfinity;
            float maxValue           = (attrib != null) ? attrib.MaxValue : float.PositiveInfinity;
            bool  discreteValuesOnly = (attrib != null) ? attrib.DiscreteValuesOnly : false;


            GUIContent[] subLabels;
            float        labelWidth;

            if (reverse)
            {
                subLabels  = (attrib != null) ? new GUIContent[] { EditorHelper.TempContent(attrib.MaxLabel), EditorHelper.TempContent(attrib.MinLabel) } : _defaultLabels;
                labelWidth = (attrib != null) ? attrib.LabelWidth : 30f;
                _values[1] = targ.Min;
                _values[0] = targ.Max;
            }
            else
            {
                subLabels  = (attrib != null) ? new GUIContent[] { EditorHelper.TempContent(attrib.MinLabel), EditorHelper.TempContent(attrib.MaxLabel) } : _defaultLabels;
                labelWidth = (attrib != null) ? attrib.LabelWidth : 30f;
                _values[0] = targ.Min;
                _values[1] = targ.Max;
            }

            EditorGUI.BeginProperty(position, label, property);
            EditorGUI.BeginChangeCheck();
            SPEditorGUI.MultiFloatField(position, label, subLabels, _values, labelWidth);
            if (EditorGUI.EndChangeCheck())
            {
                _values[0] = Mathf.Clamp(_values[0], minValue, maxValue);
                _values[1] = Mathf.Clamp(_values[1], minValue, maxValue);
                if (discreteValuesOnly)
                {
                    _values[0] = Mathf.Round(_values[0]);
                }
                if (discreteValuesOnly)
                {
                    _values[1] = Mathf.Round(_values[1]);
                }

                if (reverse)
                {
                    targ.SetExtents(_values[1], _values[0]);
                }
                else
                {
                    targ.SetExtents(_values[0], _values[1]);
                }
                EditorHelper.SetTargetObjectOfProperty(property, targ);
            }
            EditorGUI.EndProperty();
        }
Exemplo n.º 2
0
        public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
        {
            //EditorGUI.BeginProperty(position, label, property);
            //if(property.isExpanded)
            //{
            //    var r1 = new Rect(position.xMin, position.yMin, position.width, EditorGUIUtility.singleLineHeight);
            //    var r2 = new Rect(position.xMin, r1.yMax, position.width, EditorGUIUtility.singleLineHeight);
            //    var r3 = new Rect(position.xMin, r2.yMax, position.width, EditorGUIUtility.singleLineHeight);

            //    property.isExpanded = EditorGUI.Foldout(r1, property.isExpanded, GUIContent.none);
            //    SPEditorGUI.DefaultPropertyField(r1, property.FindPropertyRelative(PROP_WEIGHT), label);
            //    EditorGUI.indentLevel++;
            //    SPEditorGUI.DefaultPropertyField(r2, property.FindPropertyRelative(PROP_DIMINISHRATE), EditorHelper.TempContent("Diminish Rate"));
            //    SPEditorGUI.DefaultPropertyField(r3, property.FindPropertyRelative(PROP_DIMINISHPERIOD), EditorHelper.TempContent("Diminish Period Duration"));
            //    EditorGUI.indentLevel--;
            //}
            //else
            //{
            //    property.isExpanded = EditorGUI.Foldout(position, property.isExpanded, GUIContent.none);
            //    SPEditorGUI.DefaultPropertyField(position, property.FindPropertyRelative(PROP_WEIGHT), label);
            //}
            //EditorGUI.EndProperty();


            if (!this.DrawFoldout || property.isExpanded)
            {
                const float LINE2_MARGIN = 20f;
                var         r1           = new Rect(position.xMin, position.yMin, position.width, EditorGUIUtility.singleLineHeight);
                var         r2           = new Rect(position.xMin + LINE2_MARGIN, r1.yMax, Mathf.Max(position.width - LINE2_MARGIN, 0f), EditorGUIUtility.singleLineHeight);

                if (this.DrawFoldout)
                {
                    property.isExpanded = EditorGUI.Foldout(r1, property.isExpanded, GUIContent.none);
                }

                var weightProp = property.FindPropertyRelative(PROP_WEIGHT);

                _line1[0] = weightProp.floatValue;

                EditorGUI.BeginChangeCheck();
                SPEditorGUI.MultiFloatField(r1, label, _line1Labels, _line1, 50f);
                if (EditorGUI.EndChangeCheck())
                {
                    weightProp.floatValue = _line1[0];
                }

                var maxCountProp = property.FindPropertyRelative(PROP_MAXCOUNT);
                var rateProp     = property.FindPropertyRelative(PROP_DIMINISHRATE);
                var periodProp   = property.FindPropertyRelative(PROP_DIMINISHPERIOD);

                _line2[0] = maxCountProp.floatValue;
                _line2[1] = rateProp.floatValue;
                _line2[2] = periodProp.floatValue;

                EditorGUI.BeginChangeCheck();
                SPEditorGUI.MultiFloatField(r2, _line2Labels, _line2, 80f);
                if (EditorGUI.EndChangeCheck())
                {
                    maxCountProp.floatValue = DiscreteFloatPropertyDrawer.NormalizeValue(maxCountProp.floatValue, _line2[0]);
                    rateProp.floatValue     = _line2[1];
                    periodProp.floatValue   = _line2[2];
                }
            }
            else
            {
                if (this.DrawFoldout)
                {
                    property.isExpanded = EditorGUI.Foldout(position, property.isExpanded, GUIContent.none);
                }

                var weightProp = property.FindPropertyRelative(PROP_WEIGHT);
                _line1[0] = weightProp.floatValue;
                SPEditorGUI.MultiFloatField(position, label, _line1Labels, _line1, 50f);
            }
        }