private static Sprite GetLinearGradientTexture(Rect rect, LinearGradient linearGradient)
        {
            Texture2D texture = GetTexture(rect);

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

            for (int x = 0; x < texture.width; x++)
            {
                for (int y = 0; y < texture.height; y++)
                {
                    int i = Utility.GetIndex(x, y, texture.width);

                    float xPercentage = (float)x / (float)texture.width;
                    float yPercentage = (float)y / (float)texture.height;

                    colors[i] = Utility.GetColor(new Vector2(xPercentage, yPercentage), linearGradient);
                }
            }

            texture.SetPixels(colors);
            texture.Apply();

            return(ToSprite(texture));
        }
Exemple #2
0
        /*private static Color GetColor(Vector2 position, RadialGradientBrush brush)
         * {
         *  Vector2 radial = brush.GradientOrigin.ToVector();
         *
         *  Vector2 delta = radial - position;
         *
         *  delta.X /= (float)brush.RadiusX;
         *  delta.Y /= (float)brush.RadiusY;
         *
         *  return GetColor(delta.Length(), brush);
         * }*/
        private static Color GetColor(Vector2 position, LinearGradient gradient)
        {
            float offset = PerpendicularDistance(gradient.StartPoint, gradient.EndPoint, position);

            return(gradient.Brush.Evaluate(offset));
        }