Example #1
0
 public void Setup(JG.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 <Jai.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();
    }
Example #3
0
    public static void Init(JG.Gradient gradient)
    {
        GradientEditor instance = GetWindow <GradientEditor>();

        instance.Setup(gradient);
    }