UnityEditor.EyeDropper.DrawPreview C# (CSharp) Method

DrawPreview() public static method

public static DrawPreview ( Rect position ) : void
position UnityEngine.Rect
return void
        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 = 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;
            }
        }

Usage Example

示例#1
0
        private void DoColorSpaceGUI()
        {
            GUILayout.BeginHorizontal(new GUILayoutOption[0]);
            this.m_ShowColors = GUILayout.Toggle(this.m_ShowColors, ColorPicker.styles.colorToggle, EditorStyles.foldout, new GUILayoutOption[0]);
            GUI.enabled       = this.m_ShowColors;
            if (GUILayout.Button(ColorPicker.styles.colorCycle, GUIStyle.none, new GUILayoutOption[]
            {
                GUILayout.ExpandWidth(false)
            }))
            {
                this.m_OldColorBoxMode = (this.m_ColorBoxMode = (this.m_ColorBoxMode + 1) % ColorPicker.ColorBoxMode.EyeDropper);
            }
            GUI.enabled = true;
            GUILayout.EndHorizontal();
            if (this.m_ShowColors)
            {
                bool changed = GUI.changed;
                GUILayout.BeginHorizontal(new GUILayoutOption[]
                {
                    GUILayout.ExpandHeight(false)
                });
                Rect aspectRect = GUILayoutUtility.GetAspectRect(1f, ColorPicker.styles.pickerBox, new GUILayoutOption[]
                {
                    GUILayout.MinWidth(64f),
                    GUILayout.MinHeight(64f),
                    GUILayout.MaxWidth(256f),
                    GUILayout.MaxHeight(256f)
                });
                EditorGUILayout.Space();
                Rect rect = GUILayoutUtility.GetRect(8f, 32f, 64f, 128f, ColorPicker.styles.pickerBox);
                rect.height = aspectRect.height;
                GUILayout.EndHorizontal();
                GUI.changed = false;
                switch (this.m_ColorBoxMode)
                {
                case ColorPicker.ColorBoxMode.SV_H:
                    this.Slider3D(aspectRect, rect, ref this.m_S, ref this.m_V, ref this.m_H, ColorPicker.styles.pickerBox, ColorPicker.styles.thumb2D, ColorPicker.styles.thumbVert);
                    if (GUI.changed)
                    {
                        this.HSVToRGB();
                    }
                    break;

                case ColorPicker.ColorBoxMode.HV_S:
                    this.Slider3D(aspectRect, rect, ref this.m_H, ref this.m_V, ref this.m_S, ColorPicker.styles.pickerBox, ColorPicker.styles.thumb2D, ColorPicker.styles.thumbVert);
                    if (GUI.changed)
                    {
                        this.HSVToRGB();
                    }
                    break;

                case ColorPicker.ColorBoxMode.HS_V:
                    this.Slider3D(aspectRect, rect, ref this.m_H, ref this.m_S, ref this.m_V, ColorPicker.styles.pickerBox, ColorPicker.styles.thumb2D, ColorPicker.styles.thumbVert);
                    if (GUI.changed)
                    {
                        this.HSVToRGB();
                    }
                    break;

                case ColorPicker.ColorBoxMode.BG_R:
                    this.Slider3D(aspectRect, rect, ref this.m_B, ref this.m_G, ref this.m_R, ColorPicker.styles.pickerBox, ColorPicker.styles.thumb2D, ColorPicker.styles.thumbVert);
                    if (GUI.changed)
                    {
                        this.RGBToHSV();
                    }
                    break;

                case ColorPicker.ColorBoxMode.BR_G:
                    this.Slider3D(aspectRect, rect, ref this.m_B, ref this.m_R, ref this.m_G, ColorPicker.styles.pickerBox, ColorPicker.styles.thumb2D, ColorPicker.styles.thumbVert);
                    if (GUI.changed)
                    {
                        this.RGBToHSV();
                    }
                    break;

                case ColorPicker.ColorBoxMode.RG_B:
                    this.Slider3D(aspectRect, rect, ref this.m_R, ref this.m_G, ref this.m_B, ColorPicker.styles.pickerBox, ColorPicker.styles.thumb2D, ColorPicker.styles.thumbVert);
                    if (GUI.changed)
                    {
                        this.RGBToHSV();
                    }
                    break;

                case ColorPicker.ColorBoxMode.EyeDropper:
                    EyeDropper.DrawPreview(Rect.MinMaxRect(aspectRect.x, aspectRect.y, rect.xMax, aspectRect.yMax));
                    break;
                }
                GUI.changed |= changed;
            }
        }