团结:将颜色梯度应用于UI图像

发布于 2025-02-11 08:05:40 字数 1425 浏览 0 评论 0原文

我在Unity中使用颜色梯度

            Gradient gradient = new Gradient();
            GradientColorKey[] gck = new GradientColorKey[5];
            float rgb = 255;

            gck[0].color = new Color(65 / rgb, 105 / rgb, 255 / rgb); 
            gck[0].time = 0f;
            gck[1].color = new Color(135 / rgb, 206 / rgb, 250 / rgb);
            gck[1].time = .25f;
            gck[2].color = new Color(60 / rgb, 179 / rgb, 113 / rgb); 
            gck[2].time = 0.50F;
            gck[3].color = new Color(255 / rgb, 230 / rgb, 0);  
            gck[3].time = 0.75F;
            gck[4].color = new Color(180 / rgb, 0, 0); 
            gck[4].time = 1f;

            GradientAlphaKey[] alphaKey = new GradientAlphaKey[2];
            alphaKey[0].alpha = 1.0f;
            alphaKey[0].time = 0.0f;
            alphaKey[1].alpha = 0.0f;
            alphaKey[1].time = 1.0f;
            gradient.SetKeys(gck, alphaKey);

是一个示例,它们始终是尺寸5,但是在运行时用户可以更改颜色值。

现在,我想让我们这个梯度为UI映像着色,以便用户可以看到他创建的当前梯度。目前,使用5张图像,每张图像上有5种颜色之一:

但它应该是一个图像,看起来像这样: ”在此处输入图像说明“

有没有办法做到这一点?

谢谢!

I'm using a color gradient in Unity

            Gradient gradient = new Gradient();
            GradientColorKey[] gck = new GradientColorKey[5];
            float rgb = 255;

            gck[0].color = new Color(65 / rgb, 105 / rgb, 255 / rgb); 
            gck[0].time = 0f;
            gck[1].color = new Color(135 / rgb, 206 / rgb, 250 / rgb);
            gck[1].time = .25f;
            gck[2].color = new Color(60 / rgb, 179 / rgb, 113 / rgb); 
            gck[2].time = 0.50F;
            gck[3].color = new Color(255 / rgb, 230 / rgb, 0);  
            gck[3].time = 0.75F;
            gck[4].color = new Color(180 / rgb, 0, 0); 
            gck[4].time = 1f;

            GradientAlphaKey[] alphaKey = new GradientAlphaKey[2];
            alphaKey[0].alpha = 1.0f;
            alphaKey[0].time = 0.0f;
            alphaKey[1].alpha = 0.0f;
            alphaKey[1].time = 1.0f;
            gradient.SetKeys(gck, alphaKey);

The Gradient is an example, they are always size 5 but the color values can be changed by the user during runtime.

Now I want to us this gradient to color an UI Image so that the user can see the current gradient he created. Currently it looks like this using 5 images each colored with one of the 5 colors:
enter image description here

But it should be one image and look like this: enter image description here

Is there a way to do this?

Thanks!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文