示例#1
0
    public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
    {
        Event guiEvent = Event.current;

        CustomGradient gradient = (CustomGradient)fieldInfo.GetValue(property.serializedObject.targetObject);

        float labelWidth = EditorGUIUtility.labelWidth;

        Rect labelRect         = new Rect(position.x, position.y, labelWidth, position.height);
        Rect gradientRect      = new Rect(position.x + labelWidth, position.y, position.width - labelWidth, position.height);
        Rect gradientInnerRect = new Rect(gradientRect.x + gradientPadding, gradientRect.y + gradientPadding, gradientRect.width - gradientPadding * 2, gradientRect.height - gradientPadding * 2);

        switch (guiEvent.type)
        {
        case EventType.Repaint:

            GUI.Label(labelRect, label);

            GUIStyle gradientStyle = new GUIStyle();
            gradientStyle.normal.background = gradient.GetTexture((int)gradientRect.width);

            GUI.TextField(gradientRect, "");
            GUI.Label(gradientInnerRect, GUIContent.none, gradientStyle);

            break;

        case EventType.MouseDown:
            if (guiEvent.button == 0 && gradientRect.Contains(guiEvent.mousePosition))
            {
                GradientEditorWindow editor = EditorWindow.GetWindow <GradientEditorWindow>();
                editor.SetGradient(gradient);
            }
            break;
        }
    }
    public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
    {
        Event guiEvent = Event.current;

        CustomGradient gradient = (CustomGradient)fieldInfo.GetValue(property.serializedObject.targetObject);

        float labelWidth  = GUI.skin.label.CalcSize(label).x + 5;
        Rect  textureRect = new Rect(position.x + labelWidth, position.y, position.width - labelWidth, position.height);

        if (guiEvent.type == EventType.Repaint)
        {
            GUI.Label(position, label);
            GUIStyle gradientStyle = new GUIStyle();
            gradientStyle.normal.background = gradient.GetTexture((int)position.width);
            GUI.Label(textureRect, GUIContent.none, gradientStyle);
        }
        else
        {
            // Check if gradient is clicked
            if (guiEvent.type == EventType.MouseDown && guiEvent.button == 0)
            {
                if (textureRect.Contains(guiEvent.mousePosition))
                {
                    // Open editor window
                    GradientEditor window = EditorWindow.GetWindow <GradientEditor>();
                    window.SetGradient(gradient);
                }
            }
        }
    }
示例#3
0
    public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
    {
        Event guiEvent = Event.current;

        EditorGUI.BeginProperty(position, label, property);
        position = EditorGUI.PrefixLabel(position, GUIUtility.GetControlID(FocusType.Passive), label);

        CustomGradient gradient = GetDataObject(property) as CustomGradient;

        if (gradient == null)
        {
            return;
        }
        Rect textureRect = new Rect(position.x, position.y, position.width, position.height);

        if (guiEvent.type == EventType.Repaint)
        {
            GUIStyle gradientStyle = new GUIStyle();
            gradientStyle.normal.background = gradient.GetTexture((int)position.width);
            GUI.Label(textureRect, GUIContent.none, gradientStyle);
        }
        else
        {
            if (guiEvent.type == EventType.MouseDown && guiEvent.button == 0)
            {
                if (textureRect.Contains(guiEvent.mousePosition))
                {
                    GradientEditor window = EditorWindow.GetWindow <GradientEditor>();
                    window.SetGradient(gradient);
                }
            }
        }

        EditorGUI.EndProperty();
    }
示例#4
0
    /*
     * public override float GetPropertyHeight(SerializedProperty property, GUIContent label)
     * {
     *  //return base.GetPropertyHeight(property, label);
     *  return customHeightInPixels;
     * }
     */

    public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
    {
        //base.OnGUI(position, property, label);

        Event          guiEvent = Event.current;
        CustomGradient gradient = (CustomGradient)fieldInfo.GetValue(property.serializedObject.targetObject);

        Rect labelRect = new Rect(position);

        labelRect.width = EditorGUIUtility.labelWidth;

        Rect textureRect = new Rect(position);

        textureRect.width -= EditorGUIUtility.labelWidth;
        textureRect.x     += EditorGUIUtility.labelWidth;

        if (guiEvent.type == EventType.Repaint)
        {
            GUI.DrawTexture(textureRect, gradient.GetTexture((int)position.width));
            GUI.Label(position, label.text);

            // Workaround for background glitches (when moving cursor)
            // Doesn't appear to happen on 2019.3.0a4
#if !UNITY_2019_3_OR_NEWER
            GUIStyle gradientStyle = new GUIStyle();
            gradientStyle.normal.background = gradient.GetTexture((int)position.width);
            GUI.Label(textureRect, GUIContent.none, gradientStyle);
#endif
        }
        else
        {
            if (guiEvent.type == EventType.MouseDown && guiEvent.button == 0)
            {
                if (textureRect.Contains(guiEvent.mousePosition))
                {
                    GradientEditor window = EditorWindow.GetWindow <GradientEditor>();
                    window.SetGradient(gradient);
                }
            }
        }
    }
示例#5
0
 public void SetGradient(CustomGradient gradient)
 {
     this.gradient = gradient;
 }
示例#6
0
 public void SetGradient(CustomGradient g)
 {
     gradient = g;
 }
示例#7
0
 public void SetGradient(CustomGradient gradient)
 {
     _gradient = gradient;
 }