示例#1
0
    void DrawGradientTexturePreview()
    {
        _gradientPreviewTexRect = new Rect(borderSize, borderSize, position.width - 2 * borderSize, gradientTexHeight);
        Texture2D gradientTexture = _gradient.GetTexture((int)_gradientPreviewTexRect.width, _type);

        GUI.DrawTexture(_gradientPreviewTexRect, gradientTexture);
    }
    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
    void Draw()
    {
        gradientPreviewRect = new Rect(borderSize, borderSize, position.width - borderSize * 2f, 25f);
        GUI.DrawTexture(gradientPreviewRect, gradient.GetTexture((int)gradientPreviewRect.width));

        keyRects = new Rect[gradient.KeyCount];
        for (int i = 0; i < gradient.KeyCount; i++)
        {
            CustomGradient.ColorKey key = gradient.GetKey(i);
            Rect keyRect = new Rect(gradientPreviewRect.x + gradientPreviewRect.width * key.time - keyWidth / 2f, gradientPreviewRect.yMax + borderSize, keyWidth, keyHeight);

            if (i == selectedKeyIndex)
            {
                EditorGUI.DrawRect(new Rect(keyRect.x - 2, keyRect.y - 2, keyRect.width + 4, keyRect.height + 4), Color.black);
            }
            EditorGUI.DrawRect(keyRect, key.color);
            keyRects[i] = keyRect;
        }

        Rect settingRect = new Rect(borderSize, keyRects[0].yMax + borderSize, position.width - borderSize * 2f, position.height);

        GUILayout.BeginArea(settingRect);
        EditorGUI.BeginChangeCheck();
        Color newColor = EditorGUILayout.ColorField(gradient.GetKey(selectedKeyIndex).color);

        if (EditorGUI.EndChangeCheck())
        {
            gradient.UpdateKeyColor(selectedKeyIndex, newColor);
        }
        GUILayout.EndArea();
    }
示例#4
0
    private void Draw()
    {
        gradientPreviewRect = new Rect(BORDER_SIZE, BORDER_SIZE, position.width - BORDER_SIZE * 2, 25);
        GUI.DrawTexture(gradientPreviewRect, gradient.GetTexture((int)gradientPreviewRect.width));

        keyRects = new Rect[gradient.KeyCount];
        for (int i = 0; i < gradient.KeyCount; i++)
        {
            ColorKey key     = gradient.GetKey(i);
            float    keyX    = gradientPreviewRect.x + gradientPreviewRect.width * key.Time - KEY_WIDTH / 2f;
            float    keyY    = gradientPreviewRect.yMax + BORDER_SIZE;
            Rect     keyRect = new Rect(keyX, keyY, KEY_WIDTH, KEY_HEIGHT);

            if (i == selectedKeyIndex)
            {
                EditorGUI.DrawRect(new Rect(keyRect.x - 2, keyRect.y - 2, keyRect.width + 4, keyRect.height + 4), Color.black);
            }
            EditorGUI.DrawRect(keyRect, key.Col);
            keyRects[i] = keyRect;
        }

        Rect settingsRect = new Rect(BORDER_SIZE, keyRects[0].yMax + BORDER_SIZE, position.width - BORDER_SIZE * 2, position.height - BORDER_SIZE * 9);

        GUILayout.BeginArea(settingsRect);
        EditorGUI.BeginChangeCheck();
        Color newCol = EditorGUILayout.ColorField(gradient.GetKey(selectedKeyIndex).Col);

        if (EditorGUI.EndChangeCheck())
        {
            gradient.UpdateKeyColor(selectedKeyIndex, newCol);
        }
        gradient.blendMode      = (BlendMode)EditorGUILayout.EnumPopup("Blend Mode", gradient.blendMode);
        gradient.randomizeColor = EditorGUILayout.Toggle("Randmize Color", gradient.randomizeColor);
        GUILayout.EndArea();
    }
示例#5
0
    void Draw()
    {
        gradientPreviewRect = new Rect(borderSize, borderSize, position.width - borderSize * 2, 25);
        GUI.DrawTexture(gradientPreviewRect, gradient.GetTexture((int)gradientPreviewRect.width));

        keyRects = new Rect[gradient.NumKeys];
        for (int i = 0; i < gradient.NumKeys; i++)
        {
            CustomGradient.ColourKey key = gradient.GetKey(i);
            Rect keyRect = new Rect(gradientPreviewRect.x + gradientPreviewRect.width * key.Time - keyWidth / 2f, gradientPreviewRect.yMax + borderSize, keyWidth, keyHeight);
            if (i == selectedKeyIndex)
            {
                EditorGUI.DrawRect(new Rect(keyRect.x - 2, keyRect.y - 2, keyRect.width + 4, keyRect.height + 4), Color.black);
            }
            EditorGUI.DrawRect(keyRect, key.Colour);
            keyRects[i] = keyRect;
        }

        Rect settingsRect = new Rect(borderSize, keyRects[0].yMax + borderSize, position.width - borderSize * 2, position.height);

        GUILayout.BeginArea(settingsRect);
        EditorGUI.BeginChangeCheck();
        Color newColour = EditorGUILayout.ColorField(gradient.GetKey(selectedKeyIndex).Colour);

        if (EditorGUI.EndChangeCheck())
        {
            gradient.UpdateKeyColour(selectedKeyIndex, newColour);
        }
        gradient.blendMode       = (CustomGradient.BlendMode)EditorGUILayout.EnumPopup("Blend mode", gradient.blendMode);
        gradient.randomizeColour = EditorGUILayout.Toggle("Randomize colour", gradient.randomizeColour);
        GUILayout.EndArea();
    }
示例#6
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;
        }
    }
示例#7
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();
    }
示例#8
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);
                }
            }
        }
    }
示例#9
0
    override protected void Draw()
    {
        GUI.DrawTexture(gradientPreviewRect, gradient.GetTexture((int)gradientPreviewRect.width));

        keyRects = new Rect[gradient.KeyCount()];

        for (int i = 0; i < gradient.KeyCount(); i++)
        {
            CustomGradient.ColourKey key = gradient.GetKey(i);
            Rect keyRect = new Rect(gradientPreviewRect.x + gradientPreviewRect.width * key.Time - keyWidth / 2f, gradientPreviewRect.yMax + borderSize, keyWidth, keyHeight);

            if (i == selectedKeyIndex)
            {
                EditorGUI.DrawRect(new Rect(keyRect.x - 2, keyRect.y - 2, keyRect.width + 4, keyRect.height + 4), Color.black);
            }
            else
            {
                EditorGUI.DrawRect(new Rect(keyRect.x - 1, keyRect.y - 1, keyRect.width + 2, keyRect.height + 2), Color.grey);
            }

            EditorGUI.DrawRect(keyRect, key.Colour);
            keyRects[i] = keyRect;
        }

        Rect settingsRect = new Rect(borderSize, gradientPreviewRect.yMax + keyHeight + borderSize * 2, gradientPreviewRect.width, position.height);

        GUILayout.BeginArea(settingsRect);

        EditorGUI.BeginChangeCheck();
        Color newColour = EditorGUILayout.ColorField(gradient.GetKey(selectedKeyIndex).Colour);

        if (EditorGUI.EndChangeCheck())
        {
            gradient.UpdateKeyColour(selectedKeyIndex, newColour);
        }

        gradient.blendMode = (CustomGradient.BlendMode)EditorGUILayout.EnumPopup("Blend Mode", gradient.blendMode);

        GUILayout.EndArea();
    }
示例#10
0
    public void OnGUI()
    {
        Event guiEvent            = Event.current;
        Rect  gradientPreviewRect = new Rect(borderSize, borderSize, position.width - borderSize * 2, 25);

        GUI.DrawTexture(gradientPreviewRect, gradient.GetTexture((int)gradientPreviewRect.width, (int)gradientPreviewRect.height));

        for (int i = 0; i < gradient.NumKeys(); i++)
        {
            CustomGradient.ColourKey key = gradient.GetKey(i);
            Rect keyRect = new Rect(gradientPreviewRect.x + gradientPreviewRect.width * key.Time - keyWidth / 2f, gradientPreviewRect.yMax + borderSize, keyWidth, keyHeight);
            EditorGUI.DrawRect(keyRect, key.Colour);
        }

        if (guiEvent.type == EventType.MouseDown && guiEvent.button == 0)
        {
            Color randomColor = new Color(Random.value, Random.value, Random.value);
            float keyTime     = Mathf.InverseLerp(gradientPreviewRect.x, gradientPreviewRect.xMax, guiEvent.mousePosition.x);
            gradient.AddKey(randomColor, keyTime);
            Repaint();
        }
    }
示例#11
0
    private void Draw()
    {
        _gradientPreviewRect = new Rect(BorderSize, BorderSize, position.width - (BorderSize * 2), gradientPreviewRectHeight);
        GUI.DrawTexture(_gradientPreviewRect, _gradient.GetTexture((int)_gradientPreviewRect.width));
        _keyRects = new Rect[_gradient.NumKeys];

        for (int i = 0; i < _gradient.NumKeys; i++)
        {
            CustomGradient.ColorKey key = _gradient.GetKey(i);
            Rect keyRect = new Rect(_gradientPreviewRect.x + (_gradientPreviewRect.width * key.Time) - (_keyWidth / 2f),
                                    _gradientPreviewRect.yMax + BorderSize, _keyWidth, _keyHeight);

            if (i == _selectedKeyIndex)
            {
                EditorGUI.DrawRect(new Rect(keyRect.x - 3, keyRect.y - 3, keyRect.width + 6, keyRect.height + 6), Color.black);
            }

            EditorGUI.DrawRect(keyRect, key.Color);
            _keyRects[i] = keyRect;
        }

        Rect settingsRect = new Rect(BorderSize, _keyRects[0].yMax + BorderSize,
                                     position.width - (BorderSize * 2), position.height);

        GUILayout.BeginArea(settingsRect);
        EditorGUI.BeginChangeCheck();
        Color newColor = EditorGUILayout.ColorField(_gradient.GetKey(_selectedKeyIndex).Color);

        if (EditorGUI.EndChangeCheck())
        {
            _gradient.UpdateKeyColor(_selectedKeyIndex, newColor);
        }
        _gradient.blendMode      = (CustomGradient.BlendMode)EditorGUILayout.EnumPopup("Blend Mode", _gradient.blendMode);
        _gradient.randomizeColor = EditorGUILayout.Toggle("Randomize Color", _gradient.randomizeColor);
        GUILayout.EndArea();
    }
示例#12
0
    private void OnGUI()
    {
        Rect r = new Rect(borderSize, borderSize, position.width - borderSize * 2, 32);

        GUI.DrawTexture(r, gradient.GetTexture((int)r.width));

        keyRects = new Rect[gradient.KeysCount];
        for (int i = 0; i < gradient.KeysCount; i++)
        {
            var   key     = gradient.GetKey(i);
            float x       = r.x + r.width * key.Time - keySize.x / 2f;
            float y       = r.yMax + borderSize;
            Rect  keyRect = new Rect(new Vector2(x, y), keySize);

            if (i == selectedKey)
            {
                var pos     = new Vector2(x, y) - Vector2.one * 2;
                var size    = keySize + Vector2.one * 4;
                var outline = new Rect(pos, size);
                EditorGUI.DrawRect(outline, Color.black);
            }

            EditorGUI.DrawRect(keyRect, key.Color);
            keyRects[i] = keyRect;
        }

        Event e = Event.current;

        if (e.button == 0)
        {
            if (e.type == EventType.MouseDown)
            {
                for (int i = 0; i < keyRects.Length; i++)
                {
                    if (keyRects[i].Contains(e.mousePosition))
                    {
                        mouseIsOverKey = true;
                        selectedKey    = i;
                        needRepaint    = true;
                        break;
                    }
                }

                if (mouseIsOverKey)
                {
                }
                else
                {
                    var   c    = new Color(Random.value, Random.value, Random.value);
                    float time = Mathf.InverseLerp(r.x, r.xMax, e.mousePosition.x);
                    selectedKey    = gradient.AddKey(c, time);
                    mouseIsOverKey = true;
                    needRepaint    = true;
                }
            }
            else if (e.type == EventType.MouseUp)
            {
                mouseIsOverKey = false;
            }
            else if (e.type == EventType.MouseDrag)
            {
                if (mouseIsOverKey)
                {
                }
            }
        }

        if (needRepaint)
        {
            Repaint();
            needRepaint = false;
        }
    }
示例#13
0
 private void Update()
 {
     // Debug.Log(renderer.bounds.size.x);
     renderer.material.SetTexture("_MainTex", gradient.GetTexture(300));
 }