Ejemplo n.º 1
0
        public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
        {
            PropertyDrawerHelper.LoadAttributeTooltip(this, label);

            // Bugged Unity... hacks :(
            if (!property.type.EndsWith("Bounds"))
            {
                return;
            }

            Rect labelPosition = new Rect(position);
            Rect minPosition   = new Rect(position);
            Rect maxPosition   = new Rect(position);

            labelPosition.width = EditorGUIUtility.labelWidth;
            minPosition.x       = labelPosition.xMax;
            minPosition.width   = (minPosition.width - labelPosition.width) * 0.5f;
            maxPosition.x       = labelPosition.xMax + minPosition.width;
            maxPosition.width   = minPosition.width;

            EditorGUI.LabelField(labelPosition, label);

            SerializedProperty max = property.GetMemberProperty <IntBounds>(b => b.Max);
            SerializedProperty min = property.GetMemberProperty <IntBounds>(b => b.Min);

            EditorHelper.BeginChangeLabelWidth(32.0f);
            EditorHelper.BeginChangeIndentLevel(0);

            EditorGUI.BeginChangeCheck();
            DelayedPropertyField(minPosition, min);
            DelayedPropertyField(maxPosition, max);
            if (EditorGUI.EndChangeCheck())
            {
                min.serializedObject.ApplyModifiedProperties();
                max.serializedObject.ApplyModifiedProperties();

                var validatable = SerializedPropertyHelper.GetValue(fieldInfo, property) as IValidatable;
                validatable.Validate();

                min.serializedObject.Update();
                max.serializedObject.Update();
            }

            EditorHelper.EndChangeIndentLevel();
            EditorHelper.EndChangeLabelWidth();
        }
Ejemplo n.º 2
0
        public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
        {
            PropertyDrawerHelper.LoadAttributeTooltip(this, label);

            // Bugged Unity... hacks :(
            if (!property.type.StartsWith("Modifiable"))
            {
                return;
            }

            Rect labelPosition    = position.Left(EditorGUIUtility.labelWidth);
            Rect fieldsPosition   = position.Right(-EditorGUIUtility.labelWidth);
            Rect originalPosition = fieldsPosition.Left(fieldsPosition.width * 0.5f);
            Rect modifiedPosition = fieldsPosition.Right(-fieldsPosition.width * 0.5f);

            EditorGUI.LabelField(labelPosition, label);

            SerializedProperty originalValue = property.GetMemberProperty <ModifiableInt>(m => m.OriginalValue);
            SerializedProperty modifiedValue = property.GetMemberProperty <ModifiableInt>(m => m.ModifiedValue);

            EditorHelper.BeginChangeLabelWidth(56.0f);
            EditorHelper.BeginChangeIndentLevel(0);

            EditorGUI.BeginChangeCheck();
            EditorGUI.PropertyField(originalPosition, originalValue, new GUIContent("Original"));
            bool modified = EditorGUI.EndChangeCheck();

            EditorGUI.BeginDisabledGroup(true);
            EditorGUI.PropertyField(modifiedPosition, modifiedValue, new GUIContent("Modified"));
            EditorGUI.EndDisabledGroup();

            EditorHelper.EndChangeIndentLevel();
            EditorHelper.EndChangeLabelWidth();

            if (modified)
            {
                originalValue.serializedObject.ApplyModifiedProperties();
                modifiedValue.serializedObject.ApplyModifiedProperties();

                var modifiable = SerializedPropertyHelper.GetValue(fieldInfo, property) as IModifiable;
                modifiable.UpdateModifiedValues();

                originalValue.serializedObject.Update();
                modifiedValue.serializedObject.Update();
            }
        }