Hey there!
I’ve tried my hands at creating something like this. If you haven’t used photoshop and don’t understand what’s happening from looking at the pictures I’ll try to explain it:
There are 3 sliders. Red, green and blue, all of them have a gradient applied to them from Color(0, 0, 0) to COlor(red, green, blue). They also each control the value of their color, so I want the slider to function as a slider would and simply change the background image in real-time.
Here’s what I tried (with horrible results)
Texture2D UpdateSliderTexture(Texture2D texture)
{
Texture2D returnTexture = texture;
for (int y = 0; y < 8; y++)
{
for (int x = 0; x < 255; x++)
{
returnTexture.SetPixel(x, y, new Color(colorR * x, colorG * x, colorB * x));
}
}
returnTexture.Apply();
return returnTexture;
}
Horrible as in it freezes. The documentation told me that Apply() is expensive but I don’t know how else I’d go about doing this.
Any ideas? Here’s the slider code in case you’d like to know:
colorR = GUI.HorizontalSlider(new Rect(16, 0, 255, 16), colorR, 0, 255, colorSliderStyle, colorSliderThumb);
I made a gif just to clarify: http://i.imgur.com/LshWC.gif
Edit: I also fixed the broken code… Sorry for the confusion