public void Setup(KR.Graphics.Gradient gradient)
 {
     this.gradient = gradient;
     for (int i = 0; i < gradient.keys.Count; i++)
     {
         foldouts.Add(false);
     }
 }
    void DrawGradientTexture(SerializedProperty property)
    {
        if (instance == null)
        {
            instance = PropertyDrawerMethods.GetActualObjectForSerializedProperty <KR.Graphics.Gradient>(fieldInfo, property);
        }

        if (previewTexture == null)
        {
            previewTexture = new Texture2D(256, 8);
        }

        int width  = previewTexture.width;
        int height = previewTexture.height;

        Color[] colors = new Color[width * height];

        Color bgColor = Color.clear;

        for (int i = 0; i < width; i++)
        {
            float t = Mathf.Clamp01(((float)i) / ((float)width));

            Color color = instance.Evaluate(t);

            colors[i]             = color * (color.a) + bgColor * (1f - color.a);
            colors[i + width * 4] = color * (color.a) + bgColor * (1f - color.a);
        }

        for (int L = 0; L < height; L += 4)
        {
            for (int l = 0; l < 4; l++)
            {
                if ((L % height / 2) < 4)
                {
                    System.Array.Copy(colors, 0, colors, L * width + l * width, width);
                }
                else
                {
                    System.Array.Copy(colors, width * 4, colors, L * width + l * width, width);
                }
            }
        }

        previewTexture.SetPixels(0, 0, width, height, colors);
        previewTexture.Apply();
    }
    public static void Init(KR.Graphics.Gradient gradient)
    {
        GradientEditor instance = GetWindow <GradientEditor>();

        instance.Setup(gradient);
    }