Example #1
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();
    }
Example #2
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);
        }
    }
Example #3
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();
    }
Example #4
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();
        }
    }