public override void OnGUI(Rect pos, SerializedProperty prop, GUIContent label)
    {
        label = EditorGUI.BeginProperty(pos, label, prop);

        // Draw label
        pos = EditorGUI.PrefixLabel(pos, GUIUtility.GetControlID(FocusType.Passive), label);

        // Don't make child fields be indented
        var indent = EditorGUI.indentLevel;

        EditorGUI.indentLevel = 0;

        float colorWidth = (pos.width - hexFieldWidth - spacing - alphaFieldWidth - spacing);

        Color32 color  = prop.colorValue;
        Color32 color2 = EditorGUI.ColorField(new Rect(pos.x, pos.y, colorWidth, pos.height), prop.colorValue);

        if (!color2.Equals(color))
        {
            prop.colorValue = color = color2;
        }

        string colorString = EditorGUI.TextField(new Rect((pos.x + colorWidth + spacing), pos.y, hexFieldWidth, pos.height), CommonColorBuffer.ColorToString(color));

        try
        {
            color2 = CommonColorBuffer.StringToColor(colorString);

            if (!color2.Equals(color))
            {
                prop.colorValue = color = color2;
            }
        }
        catch { }


        float newAlpha = EditorGUI.Slider(new Rect((pos.x + colorWidth + hexFieldWidth + (spacing * 2f)), pos.y, alphaFieldWidth, pos.height), prop.colorValue.a, 0f, 1f);

        if (!newAlpha.Equals(prop.colorValue.a))
        {
            prop.colorValue = new Color(prop.colorValue.r, prop.colorValue.g, prop.colorValue.b, newAlpha);
        }

        // Set indent back to what it was
        EditorGUI.indentLevel = indent;

        EditorGUI.EndProperty();
    }
    public override void OnGUI(Rect pos, SerializedProperty prop, GUIContent label)
    {
        label = EditorGUI.BeginProperty(pos, label, prop);

        // Draw label
        pos = EditorGUI.PrefixLabel(pos, GUIUtility.GetControlID(FocusType.Passive), label);

        // Don't make child fields be indented
        var indent = EditorGUI.indentLevel;

        EditorGUI.indentLevel = 0;

        Color32 color  = prop.colorValue;
        Color32 color2 = EditorGUI.ColorField(new Rect(pos.x, pos.y, (pos.width - textFieldWidth - spacing), pos.height), prop.colorValue);

        if (!color2.Equals(color))
        {
            prop.colorValue = color = color2;
        }

        string colorString = EditorGUI.TextField(new Rect((pos.x + (pos.width - textFieldWidth) + spacing), pos.y, (textFieldWidth - spacing - 5f), pos.height), CommonColorBuffer.ColorToString(color));

        try
        {
            color2 = CommonColorBuffer.StringToColor(colorString);
            if (!color2.Equals(color))
            {
                prop.colorValue = color = color2;
            }
        }
        catch
        {
        }

        // Set indent back to what it was
        EditorGUI.indentLevel = indent;

        EditorGUI.EndProperty();
    }
Esempio n. 3
0
 public static Color GetColor(UIItemQuality quality)
 {
     return(CommonColorBuffer.StringToColor(GetHexColor(quality)));
 }