Unity Slider 实现多段颜色
1 public Slider slider; 2 public Image bg; 3 const int W = 256; 4 const int H = 256; 5 void Start () { 6 var hueTex = new Texture2D(256, 256); 7 var color = Color.red; 8 for (int w = 0; w < W; w++) 9 { 10 for (int h = 0; h < H; h++) 11 { 12 hueTex.SetPixel(w,h,color); 13 } 14 if (w % 30 == 0) 15 { 16 color = new Color(Random.Range(0, 255) / 255f, Random.Range(0, 255) / 255f, Random.Range(1, 255) / 255f, 1); 17 } 18 } 19 hueTex.Apply(); 20 bg.sprite = Sprite.Create(hueTex, new Rect(0, 0, W, H), Vector2.zero * 0.5f); 21 }