void RegenerateSVTexture() { h = Picker.H; if (image.texture != null) { DestroyImmediate(image.texture); } var texture = new Texture2D(100, 100, TextureFormat.RGB24, false); texture.filterMode = FilterMode.Point; texture.hideFlags = HideFlags.DontSave; for (int s = 0; s < 100; s++) { var colors = new Color32[100]; for (int v = 0; v < 100; v++) { colors[v] = ColorHelper.Hsv2Rgb(h, s / 100.0f, v / 100.0f); } texture.SetPixels32(s, 0, 1, 100, colors); } texture.Apply(); image.texture = texture; }
void OnHsvChanged() { _currentColor = ColorHelper.Hsv2Rgb(_hue, _saturation, _value); _currentColor.a = _alpha; _currentHsvColor = new HsvColor(_hue, _saturation, _value); _red = _currentColor.r; _green = _currentColor.g; _blue = _currentColor.b; if (OnColorChangedEvent != null) { OnColorChangedEvent(); } }
void RegenerateTexture() { Color32 baseColor = Picker.CurrentColor; float h = Picker.H; float s = Picker.S; float v = Picker.V; Texture2D texture; Color32[] colors; bool vertical = direction == Slider.Direction.BottomToTop || direction == Slider.Direction.TopToBottom; bool inverted = direction == Slider.Direction.TopToBottom || direction == Slider.Direction.RightToLeft; int size; switch (Type) { case ColorParamType.R: case ColorParamType.G: case ColorParamType.B: case ColorParamType.A: size = 255; break; case ColorParamType.H: size = 360; break; case ColorParamType.S: case ColorParamType.V: size = 100; break; default: throw new System.NotImplementedException(""); } texture = vertical ? new Texture2D(1, size, TextureFormat.RGB24, false) : new Texture2D(size, 1, TextureFormat.RGB24, false); texture.filterMode = FilterMode.Point; texture.hideFlags = HideFlags.DontSave; colors = new Color32[size]; switch (Type) { case ColorParamType.R: for (byte i = 0; i < size; i++) { colors[inverted ? size - 1 - i : i] = new Color32(i, baseColor.g, baseColor.b, 255); } break; case ColorParamType.G: for (byte i = 0; i < size; i++) { colors[inverted ? size - 1 - i : i] = new Color32(baseColor.r, i, baseColor.b, 255); } break; case ColorParamType.B: for (byte i = 0; i < size; i++) { colors[inverted ? size - 1 - i : i] = new Color32(baseColor.r, baseColor.g, i, 255); } break; case ColorParamType.A: for (byte i = 0; i < size; i++) { colors[inverted ? size - 1 - i : i] = new Color32(i, i, i, 255); } break; case ColorParamType.H: for (int i = 0; i < size; i++) { colors[inverted ? size - 1 - i : i] = ColorHelper.Hsv2Rgb((float)i / size, 1, 1); } break; case ColorParamType.S: for (int i = 0; i < size; i++) { colors[inverted ? size - 1 - i : i] = ColorHelper.Hsv2Rgb(h, (float)i / size, v); } break; case ColorParamType.V: for (int i = 0; i < size; i++) { colors[inverted ? size - 1 - i : i] = ColorHelper.Hsv2Rgb(h, s, (float)i / size); } break; default: throw new System.NotImplementedException(""); } texture.SetPixels32(colors); texture.Apply(); if (image.texture != null) { DestroyImmediate(image.texture); } image.texture = texture; switch (direction) { case Slider.Direction.BottomToTop: case Slider.Direction.TopToBottom: image.uvRect = new Rect(0, 0, 2, 1); break; case Slider.Direction.LeftToRight: case Slider.Direction.RightToLeft: image.uvRect = new Rect(0, 0, 1, 2); break; } }