UnityEditor.PreviewResizer.PixelPreciseCollapsibleSlider C# (CSharp) Method

PixelPreciseCollapsibleSlider() public static method

public static PixelPreciseCollapsibleSlider ( int id, Rect position, float value, float min, float max, bool &expanded ) : float
id int
position UnityEngine.Rect
value float
min float
max float
expanded bool
return float
        public static float PixelPreciseCollapsibleSlider(int id, Rect position, float value, float min, float max, ref bool expanded)
        {
            Event current = Event.current;
            switch (current.GetTypeForControl(id))
            {
                case EventType.MouseDown:
                    if (((GUIUtility.hotControl == 0) && (current.button == 0)) && position.Contains(current.mousePosition))
                    {
                        GUIUtility.hotControl = id;
                        s_MouseDownLocation = current.mousePosition.y;
                        s_MouseDownValue = value;
                        s_MouseDragged = false;
                        current.Use();
                    }
                    return value;

                case EventType.MouseUp:
                    if (GUIUtility.hotControl == id)
                    {
                        GUIUtility.hotControl = 0;
                        if (!s_MouseDragged)
                        {
                            expanded = !expanded;
                        }
                        current.Use();
                    }
                    return value;

                case EventType.MouseMove:
                case EventType.KeyDown:
                case EventType.KeyUp:
                case EventType.ScrollWheel:
                    return value;

                case EventType.MouseDrag:
                    if (GUIUtility.hotControl == id)
                    {
                        value = Mathf.Clamp((current.mousePosition.y - s_MouseDownLocation) + s_MouseDownValue, min, max - 1f);
                        GUI.changed = true;
                        s_MouseDragged = true;
                        current.Use();
                    }
                    return value;

                case EventType.Repaint:
                    if (GUIUtility.hotControl == 0)
                    {
                        EditorGUIUtility.AddCursorRect(position, MouseCursor.SplitResizeUpDown);
                    }
                    if (GUIUtility.hotControl == id)
                    {
                        EditorGUIUtility.AddCursorRect(new Rect(position.x, position.y - 100f, position.width, position.height + 200f), MouseCursor.SplitResizeUpDown);
                    }
                    return value;
            }
            return value;
        }

Usage Example

        public float ResizeHandle(Rect windowPosition, float minSize, float minRemainingSize, float resizerHeight, Rect dragRect)
        {
            if (Mathf.Abs(this.m_CachedPref) < minSize)
            {
                this.m_CachedPref = minSize * Mathf.Sign(this.m_CachedPref);
            }
            float num      = windowPosition.height - minRemainingSize;
            bool  flag     = GUIUtility.hotControl == this.id;
            float num2     = (!flag) ? Mathf.Max(0f, this.m_CachedPref) : PreviewResizer.s_DraggedPreviewSize;
            bool  flag2    = this.m_CachedPref > 0f;
            float num3     = Mathf.Abs(this.m_CachedPref);
            Rect  position = new Rect(0f, windowPosition.height - num2 - resizerHeight, windowPosition.width, resizerHeight);

            if (dragRect.width != 0f)
            {
                position.x     = dragRect.x;
                position.width = dragRect.width;
            }
            bool flag3 = flag2;

            num2 = -PreviewResizer.PixelPreciseCollapsibleSlider(this.id, position, -num2, -num, 0f, ref flag2);
            num2 = Mathf.Min(num2, num);
            flag = (GUIUtility.hotControl == this.id);
            if (flag)
            {
                PreviewResizer.s_DraggedPreviewSize = num2;
            }
            if (num2 < minSize)
            {
                num2 = ((num2 >= minSize * 0.5f) ? minSize : 0f);
            }
            if (flag2 != flag3)
            {
                num2 = ((!flag2) ? 0f : num3);
            }
            flag2 = (num2 >= minSize / 2f);
            if (GUIUtility.hotControl == 0)
            {
                if (num2 > 0f)
                {
                    num3 = num2;
                }
                float num4 = num3 * (float)((!flag2) ? -1 : 1);
                if (num4 != this.m_CachedPref)
                {
                    this.m_CachedPref = num4;
                    EditorPrefs.SetFloat(this.m_PrefName, this.m_CachedPref);
                }
            }
            PreviewResizer.s_CachedPreviewSizeWhileDragging = num2;
            return(num2);
        }
All Usage Examples Of UnityEditor.PreviewResizer::PixelPreciseCollapsibleSlider