private static Texture2D Update1DSlider(Texture2D tex, int xSize, float const1, float const2, ref float oldConst1, ref float oldConst2, int idx, bool hsvSpace) { if (!tex || const1 != oldConst1 || const2 != oldConst2) { if (!tex) { tex = ColorPicker.MakeTexture(xSize, 2); } Color[] array = new Color[xSize * 2]; Color black = Color.black; Color black2 = Color.black; switch (idx) { case 0: black = new Color(0f, const1, const2, 1f); black2 = new Color(1f, 0f, 0f, 0f); break; case 1: black = new Color(const1, 0f, const2, 1f); black2 = new Color(0f, 1f, 0f, 0f); break; case 2: black = new Color(const1, const2, 0f, 1f); black2 = new Color(0f, 0f, 1f, 0f); break; case 3: black = new Color(0f, 0f, 0f, 1f); black2 = new Color(1f, 1f, 1f, 0f); break; } ColorPicker.FillArea(xSize, 2, array, black, black2, new Color(0f, 0f, 0f, 0f)); if (hsvSpace) { ColorPicker.HSVToRGBArray(array); } oldConst1 = const1; oldConst2 = const2; tex.SetPixels(array); tex.Apply(); } return(tex); }
private void DrawColorSpaceBox(Rect colorBoxRect, float constantValue) { if (Event.current.type != EventType.Repaint) { return; } if (this.m_ColorBoxMode != (ColorPicker.ColorBoxMode) this.m_TextureColorBoxMode) { int num = 8; int num2; if (this.m_ColorBoxMode == ColorPicker.ColorBoxMode.HV_S || this.m_ColorBoxMode == ColorPicker.ColorBoxMode.HS_V) { num2 = 64; } else { num2 = 8; } if (this.m_ColorBox == null) { this.m_ColorBox = ColorPicker.MakeTexture(num2, num); } if (this.m_ColorBox.width != num2 || this.m_ColorBox.height != num) { this.m_ColorBox.Resize(num2, num); } } if (this.m_ColorBoxMode != (ColorPicker.ColorBoxMode) this.m_TextureColorBoxMode || this.m_LastConstant != constantValue) { this.m_Colors = this.m_ColorBox.GetPixels(0); int width = this.m_ColorBox.width; int height = this.m_ColorBox.height; switch (this.m_ColorBoxMode) { case ColorPicker.ColorBoxMode.SV_H: ColorPicker.FillArea(width, height, this.m_Colors, new Color(this.m_H, 0f, 0f, 1f), new Color(0f, 1f, 0f, 0f), new Color(0f, 0f, 1f, 0f)); ColorPicker.HSVToRGBArray(this.m_Colors); break; case ColorPicker.ColorBoxMode.HV_S: ColorPicker.FillArea(width, height, this.m_Colors, new Color(0f, this.m_S, 0f, 1f), new Color(1f, 0f, 0f, 0f), new Color(0f, 0f, 1f, 0f)); ColorPicker.HSVToRGBArray(this.m_Colors); break; case ColorPicker.ColorBoxMode.HS_V: ColorPicker.FillArea(width, height, this.m_Colors, new Color(0f, 0f, this.m_V, 1f), new Color(1f, 0f, 0f, 0f), new Color(0f, 1f, 0f, 0f)); ColorPicker.HSVToRGBArray(this.m_Colors); break; case ColorPicker.ColorBoxMode.BG_R: ColorPicker.FillArea(width, height, this.m_Colors, new Color(this.m_R, 0f, 0f, 1f), new Color(0f, 0f, 1f, 0f), new Color(0f, 1f, 0f, 0f)); break; case ColorPicker.ColorBoxMode.BR_G: ColorPicker.FillArea(width, height, this.m_Colors, new Color(0f, this.m_G, 0f, 1f), new Color(0f, 0f, 1f, 0f), new Color(1f, 0f, 0f, 0f)); break; case ColorPicker.ColorBoxMode.RG_B: ColorPicker.FillArea(width, height, this.m_Colors, new Color(0f, 0f, this.m_B, 1f), new Color(1f, 0f, 0f, 0f), new Color(0f, 1f, 0f, 0f)); break; } if (QualitySettings.activeColorSpace == ColorSpace.Linear) { ColorPicker.LinearToGammaArray(this.m_Colors); } this.m_ColorBox.SetPixels(this.m_Colors, 0); this.m_ColorBox.Apply(true); this.m_LastConstant = constantValue; this.m_TextureColorBoxMode = (int)this.m_ColorBoxMode; } Graphics.DrawTexture(colorBoxRect, this.m_ColorBox, new Rect(0.5f / (float)this.m_ColorBox.width, 0.5f / (float)this.m_ColorBox.height, 1f - 1f / (float)this.m_ColorBox.width, 1f - 1f / (float)this.m_ColorBox.height), 0, 0, 0, 0, Color.grey); }
private void DrawColorSlider(Rect colorSliderRect, Vector2 constantValues) { if (Event.current.type != EventType.Repaint) { return; } if (this.m_ColorBoxMode != (ColorPicker.ColorBoxMode) this.m_TextureColorSliderMode) { int num = (int)this.m_ColorSliderSize; int num2; if (this.m_ColorBoxMode == ColorPicker.ColorBoxMode.SV_H) { num2 = 64; } else { num2 = (int)this.m_ColorSliderSize; } if (this.m_ColorSlider == null) { this.m_ColorSlider = ColorPicker.MakeTexture(num, num2); } if (this.m_ColorSlider.width != num || this.m_ColorSlider.height != num2) { this.m_ColorSlider.Resize(num, num2); } } if (this.m_ColorBoxMode != (ColorPicker.ColorBoxMode) this.m_TextureColorSliderMode || constantValues != this.m_LastConstantValues) { Color[] pixels = this.m_ColorSlider.GetPixels(0); int width = this.m_ColorSlider.width; int height = this.m_ColorSlider.height; switch (this.m_ColorBoxMode) { case ColorPicker.ColorBoxMode.SV_H: ColorPicker.FillArea(width, height, pixels, new Color(0f, 1f, 1f, 1f), new Color(0f, 0f, 0f, 0f), new Color(1f, 0f, 0f, 0f)); ColorPicker.HSVToRGBArray(pixels); break; case ColorPicker.ColorBoxMode.HV_S: ColorPicker.FillArea(width, height, pixels, new Color(this.m_H, 0f, Mathf.Max(this.m_V, 0.3f), 1f), new Color(0f, 0f, 0f, 0f), new Color(0f, 1f, 0f, 0f)); ColorPicker.HSVToRGBArray(pixels); break; case ColorPicker.ColorBoxMode.HS_V: ColorPicker.FillArea(width, height, pixels, new Color(this.m_H, this.m_S, 0f, 1f), new Color(0f, 0f, 0f, 0f), new Color(0f, 0f, 1f, 0f)); ColorPicker.HSVToRGBArray(pixels); break; case ColorPicker.ColorBoxMode.BG_R: ColorPicker.FillArea(width, height, pixels, new Color(0f, this.m_G, this.m_B, 1f), new Color(0f, 0f, 0f, 0f), new Color(1f, 0f, 0f, 0f)); break; case ColorPicker.ColorBoxMode.BR_G: ColorPicker.FillArea(width, height, pixels, new Color(this.m_R, 0f, this.m_B, 1f), new Color(0f, 0f, 0f, 0f), new Color(0f, 1f, 0f, 0f)); break; case ColorPicker.ColorBoxMode.RG_B: ColorPicker.FillArea(width, height, pixels, new Color(this.m_R, this.m_G, 0f, 1f), new Color(0f, 0f, 0f, 0f), new Color(0f, 0f, 1f, 0f)); break; } if (QualitySettings.activeColorSpace == ColorSpace.Linear) { ColorPicker.LinearToGammaArray(pixels); } this.m_ColorSlider.SetPixels(pixels, 0); this.m_ColorSlider.Apply(true); } Graphics.DrawTexture(colorSliderRect, this.m_ColorSlider, new Rect(0.5f / (float)this.m_ColorSlider.width, 0.5f / (float)this.m_ColorSlider.height, 1f - 1f / (float)this.m_ColorSlider.width, 1f - 1f / (float)this.m_ColorSlider.height), 0, 0, 0, 0, Color.grey); }