public static void DrawPreview(Rect position) { if (Event.current.type != EventType.Repaint) { return; } if (EyeDropper.styles == null) { EyeDropper.styles = new EyeDropper.Styles(); } Texture2D texture2D = EyeDropper.get.m_Preview; int num1 = (int)Mathf.Ceil(position.width / 10f); int num2 = (int)Mathf.Ceil(position.height / 10f); if ((Object)texture2D == (Object)null) { EyeDropper.get.m_Preview = texture2D = ColorPicker.MakeTexture(num1, num2); texture2D.filterMode = UnityEngine.FilterMode.Point; } if (texture2D.width != num1 || texture2D.height != num2) { texture2D.Resize(num1, num2); } Vector2 screenPoint = GUIUtility.GUIToScreenPoint(Event.current.mousePosition); Vector2 pixelPos = screenPoint - new Vector2((float)(num1 / 2), (float)(num2 / 2)); texture2D.SetPixels(InternalEditorUtility.ReadScreenPixel(pixelPos, num1, num2), 0); texture2D.Apply(true); Graphics.DrawTexture(position, (Texture)texture2D); float width = position.width / (float)num1; GUIStyle dropperVerticalLine = EyeDropper.styles.eyeDropperVerticalLine; float x = position.x; while ((double)x < (double)position.xMax) { Rect position1 = new Rect(Mathf.Round(x), position.y, width, position.height); dropperVerticalLine.Draw(position1, false, false, false, false); x += width; } float height = position.height / (float)num2; GUIStyle dropperHorizontalLine = EyeDropper.styles.eyeDropperHorizontalLine; float y = position.y; while ((double)y < (double)position.yMax) { Rect position1 = new Rect(position.x, Mathf.Floor(y), position.width, height); dropperHorizontalLine.Draw(position1, false, false, false, false); y += height; } Rect position2 = new Rect((screenPoint.x - pixelPos.x) * width + position.x, (screenPoint.y - pixelPos.y) * height + position.y, width, height); EyeDropper.styles.eyeDropperPickedPixel.Draw(position2, false, false, false, false); }
public static void DrawPreview(Rect position) { if (Event.current.type != EventType.Repaint) { return; } if (EyeDropper.styles == null) { EyeDropper.styles = new EyeDropper.Styles(); } GL.sRGBWrite = (QualitySettings.activeColorSpace == ColorSpace.Linear); Texture2D texture2D = EyeDropper.get.m_Preview; int num = (int)Mathf.Ceil(position.width / 10f); int num2 = (int)Mathf.Ceil(position.height / 10f); if (texture2D == null) { texture2D = (EyeDropper.get.m_Preview = ColorPicker.MakeTexture(num, num2)); texture2D.filterMode = FilterMode.Point; } if (texture2D.width != num || texture2D.height != num2) { texture2D.Resize(num, num2); } Vector2 a = GUIUtility.GUIToScreenPoint(Event.current.mousePosition); Vector2 pixelPos = a - new Vector2((float)(num / 2), (float)(num2 / 2)); texture2D.SetPixels(InternalEditorUtility.ReadScreenPixel(pixelPos, num, num2), 0); texture2D.Apply(true); Graphics.DrawTexture(position, texture2D); float num3 = position.width / (float)num; GUIStyle gUIStyle = EyeDropper.styles.eyeDropperVerticalLine; for (float num4 = position.x; num4 < position.xMax; num4 += num3) { Rect position2 = new Rect(Mathf.Round(num4), position.y, num3, position.height); gUIStyle.Draw(position2, false, false, false, false); } float num5 = position.height / (float)num2; gUIStyle = EyeDropper.styles.eyeDropperHorizontalLine; for (float num6 = position.y; num6 < position.yMax; num6 += num5) { Rect position3 = new Rect(position.x, Mathf.Floor(num6), position.width, num5); gUIStyle.Draw(position3, false, false, false, false); } Rect position4 = new Rect((a.x - pixelPos.x) * num3 + position.x, (a.y - pixelPos.y) * num5 + position.y, num3, num5); EyeDropper.styles.eyeDropperPickedPixel.Draw(position4, false, false, false, false); GL.sRGBWrite = false; }
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); }
public static void DrawPreview(Rect position) { if (Event.current.type == EventType.Repaint) { if (styles == null) { styles = new Styles(); } GL.sRGBWrite = QualitySettings.activeColorSpace == ColorSpace.Linear; Texture2D preview = get.m_Preview; int width = (int)Mathf.Ceil(position.width / 10f); int height = (int)Mathf.Ceil(position.height / 10f); if (preview == null) { get.m_Preview = preview = ColorPicker.MakeTexture(width, height); preview.filterMode = UnityEngine.FilterMode.Point; } if ((preview.width != width) || (preview.height != height)) { preview.Resize(width, height); } Vector2 vector = GUIUtility.GUIToScreenPoint(Event.current.mousePosition); Vector2 pixelPos = vector - new Vector2((float)(width / 2), (float)(height / 2)); preview.SetPixels(InternalEditorUtility.ReadScreenPixel(pixelPos, width, height), 0); preview.Apply(true); Graphics.DrawTexture(position, preview); float num3 = position.width / ((float)width); GUIStyle eyeDropperVerticalLine = styles.eyeDropperVerticalLine; for (float i = position.x; i < position.xMax; i += num3) { Rect rect = new Rect(Mathf.Round(i), position.y, num3, position.height); eyeDropperVerticalLine.Draw(rect, false, false, false, false); } float num5 = position.height / ((float)height); eyeDropperVerticalLine = styles.eyeDropperHorizontalLine; for (float j = position.y; j < position.yMax; j += num5) { Rect rect2 = new Rect(position.x, Mathf.Floor(j), position.width, num5); eyeDropperVerticalLine.Draw(rect2, false, false, false, false); } Rect rect3 = new Rect(((vector.x - pixelPos.x) * num3) + position.x, ((vector.y - pixelPos.y) * num5) + position.y, num3, num5); styles.eyeDropperPickedPixel.Draw(rect3, false, false, false, false); GL.sRGBWrite = false; } }
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); }