Esempio n. 1
0
    public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
    {
        position = Begin(position, property, label);

        if (property.type == "UInt8")
        {
            string buttonLabel = ((ButtonAttribute)attribute).label;
            if (string.IsNullOrEmpty(buttonLabel))
            {
                buttonLabel = label.text;
            }
            string   buttonPressedMethodName = ((ButtonAttribute)attribute).methodName;
            string   buttonIndexVariableName = ((ButtonAttribute)attribute).indexVariableName;
            GUIStyle buttonStyle             = ((ButtonAttribute)attribute).style;

            position = AttributeUtility.BeginIndentation(position);

            if (noFieldLabel)
            {
                buttonLabel = "";
            }

            bool pressed;
            if (buttonStyle != null)
            {
                pressed = GUI.Button(position, buttonLabel, buttonStyle);
            }
            else
            {
                pressed = GUI.Button(position, buttonLabel);
            }

            AttributeUtility.EndIndentation();

            if (pressed)
            {
                if (!string.IsNullOrEmpty(buttonIndexVariableName))
                {
                    property.serializedObject.FindProperty(buttonIndexVariableName).intValue = index;
                }
                if (!string.IsNullOrEmpty(buttonPressedMethodName))
                {
                    ((MonoBehaviour)property.serializedObject.targetObject).Invoke(buttonPressedMethodName, 0);
                }
                EditorUtility.SetDirty(property.serializedObject.targetObject);
            }
            property.boolValue = pressed;
        }
        else
        {
            EditorGUI.LabelField(position, "Button variable must be of type boolean.");
        }

        End(property);
    }
Esempio n. 2
0
    public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
    {
        position = base.Initialize(position, label);

        float  x        = property.FindPropertyRelative("x").floatValue;
        float  y        = property.FindPropertyRelative("y").floatValue;
        float  min      = 0;
        float  max      = 0;
        string minLabel = ((MinMaxSliderAttribute)attribute).minLabel;
        string maxLabel = ((MinMaxSliderAttribute)attribute).maxLabel;

        if (property.FindPropertyRelative("z") != null)
        {
            min = property.FindPropertyRelative("z").floatValue;
        }
        else
        {
            min = ((MinMaxSliderAttribute)attribute).min;
        }
        if (property.FindPropertyRelative("w") != null)
        {
            max = property.FindPropertyRelative("w").floatValue;
        }
        else
        {
            max = ((MinMaxSliderAttribute)attribute).max;
        }

        position = AttributeUtility.BeginIndentation(position);

        float width = position.width;

        position.width = width / 4;
        if (!noFieldLabel && !string.IsNullOrEmpty(minLabel) && width / 8 >= 16)
        {
            position.width = width / 8;
            EditorGUI.LabelField(position, minLabel);
            position.x += position.width;
            x           = EditorGUI.FloatField(position, x);
        }
        else
        {
            x = EditorGUI.FloatField(position, x);
        }
        position.x += position.width + 2;

        position.width = width / 2;
        EditorGUI.MinMaxSlider(position, ref x, ref y, min, max);

        position.x    += position.width + 2;
        position.width = width / 4;
        if (!noFieldLabel && !string.IsNullOrEmpty(maxLabel) && width / 8 >= 16)
        {
            position.width = width / 8;
            GUIStyle style = new GUIStyle(EditorStyles.label);
            style.alignment = TextAnchor.MiddleRight;
            y           = EditorGUI.FloatField(position, y);
            position.x += position.width;
            EditorGUI.LabelField(position, maxLabel, style);
        }
        else
        {
            y = EditorGUI.FloatField(position, y);
        }
        AttributeUtility.EndIndentation();

        property.FindPropertyRelative("x").floatValue = Mathf.Clamp(x, min, y);
        property.FindPropertyRelative("y").floatValue = Mathf.Clamp(y, x, max);
    }
Esempio n. 3
0
    public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
    {
        position = base.Initialize(position, label);

        float  x     = property.FindPropertyRelative("x").floatValue;
        float  y     = property.FindPropertyRelative("y").floatValue;
        float  z     = 0;
        float  w     = 0;
        string xName = ((SingleLineVectorAttribute)attribute).x;
        string yName = ((SingleLineVectorAttribute)attribute).y;
        string zName = ((SingleLineVectorAttribute)attribute).z;
        string wName = ((SingleLineVectorAttribute)attribute).w;

        int nbOfFields = 2;

        if (property.FindPropertyRelative("z") != null)
        {
            nbOfFields += 1;
            z           = property.FindPropertyRelative("z").floatValue;
        }
        if (property.FindPropertyRelative("w") != null)
        {
            nbOfFields += 1;
            w           = property.FindPropertyRelative("w").floatValue;
        }

        position = AttributeUtility.BeginIndentation(position);

        float width = position.width;

        position.width /= nbOfFields;
        EditorGUIUtility.labelWidth = width / (nbOfFields * 2);

        if (noFieldLabel)
        {
            x = EditorGUI.FloatField(position, x);
        }
        else
        {
            x = EditorGUI.FloatField(position, xName, x);
        }
        property.FindPropertyRelative("x").floatValue = x;

        position.x += position.width;
        if (noFieldLabel)
        {
            y = EditorGUI.FloatField(position, y);
        }
        else
        {
            y = EditorGUI.FloatField(position, yName, y);
        }
        property.FindPropertyRelative("y").floatValue = y;

        if (property.FindPropertyRelative("z") != null)
        {
            position.x += position.width;
            if (noFieldLabel)
            {
                z = EditorGUI.FloatField(position, z);
            }
            else
            {
                z = EditorGUI.FloatField(position, zName, z);
            }
            property.FindPropertyRelative("z").floatValue = z;
        }
        if (property.FindPropertyRelative("w") != null)
        {
            position.x += position.width;
            if (noFieldLabel)
            {
                w = EditorGUI.FloatField(position, w);
            }
            else
            {
                w = EditorGUI.FloatField(position, wName, w);
            }
            property.FindPropertyRelative("w").floatValue = w;
        }
        AttributeUtility.EndIndentation();
    }