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();
    }
Exemple #2
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();
    }
Exemple #3
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();
    }
Exemple #4
0
    private void DrawGradient(ControlState state, Rect curveArea)
    {
        gradientPreviewRect = new Rect(0, 0, curveArea.width, GRADIENT_HEIGHT);
        Texture2D texture = GetTexture(state, curveArea);

        GUI.DrawTexture(gradientPreviewRect, texture);

        //draw gradientkey
        keyRects = new Rect[gradient.NumKeys];
        for (int i = 0; i < gradient.NumKeys; i++)
        {
            CustomGradient.ColourKey key = gradient.GetKey(i);
            Rect keyRect = new Rect(state.translation.x + state.scale.x * key.Time - keyWidth / 2f, gradientPreviewRect.yMax, keyWidth, keyHeight);
            GUI.color = key.Colour;
            if (i == selectedKeyIndex)
            {
                //GUI.color = Color.white;
                GUI.color = key.Colour;
                GUI.DrawTexture(keyRect, colorHandleHighlight);
            }
            else
            {
                GUI.DrawTexture(keyRect, colorHandle);
            }
            //EditorGUI.ColorField(keyRect, key.Colour);
            keyRects[i] = keyRect;
        }

        Rect settingsRect = new Rect(0, GRADIENT_HEIGHT, 50, 20);

        EditorGUI.BeginChangeCheck();
        Color newColour = new Color();

        if (selectedKeyIndex != -1)
        {
            newColour = EditorGUI.ColorField(settingsRect, gradient.GetKey(selectedKeyIndex).Colour);
        }

        if (EditorGUI.EndChangeCheck())
        {
            gradient.UpdateKeyColour(selectedKeyIndex, newColour);
        }
    }
Exemple #5
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();
    }
Exemple #6
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();
    }
Exemple #7
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();
        }
    }
Exemple #8
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;
        }
    }