UnityEditor.EditorGUIExt.DragSelection C# (CSharp) Method

DragSelection() public static method

public static DragSelection ( Rect positions, bool &selections, GUIStyle style ) : bool
positions UnityEngine.Rect
selections bool
style UnityEngine.GUIStyle
return bool
        public static bool DragSelection(Rect[] positions, ref bool[] selections, GUIStyle style)
        {
            bool flag;
            int num5;
            int controlID = GUIUtility.GetControlID(0x20f3dc7, FocusType.Keyboard);
            Event current = Event.current;
            int index = -1;
            for (int i = positions.Length - 1; i >= 0; i--)
            {
                if (positions[i].Contains(current.mousePosition))
                {
                    index = i;
                    break;
                }
            }
            switch (current.GetTypeForControl(controlID))
            {
                case EventType.MouseDown:
                {
                    if ((current.button != 0) || (index < 0))
                    {
                        goto Label_030C;
                    }
                    GUIUtility.keyboardControl = 0;
                    flag = false;
                    if (!selections[index])
                    {
                        goto Label_0132;
                    }
                    num5 = 0;
                    bool[] flagArray = selections;
                    for (int j = 0; j < flagArray.Length; j++)
                    {
                        if (flagArray[j])
                        {
                            num5++;
                            if (num5 > 1)
                            {
                                break;
                            }
                        }
                    }
                    break;
                }
                case EventType.MouseUp:
                    if (GUIUtility.hotControl == controlID)
                    {
                        GUIUtility.hotControl = 0;
                    }
                    goto Label_030C;

                case EventType.MouseDrag:
                {
                    if ((GUIUtility.hotControl != controlID) || (current.button != 0))
                    {
                        goto Label_030C;
                    }
                    if (index < 0)
                    {
                        Rect rect = new Rect(positions[0].x, positions[0].y - 200f, positions[0].width, 200f);
                        if (rect.Contains(current.mousePosition))
                        {
                            index = 0;
                        }
                        rect.y = positions[positions.Length - 1].yMax;
                        if (rect.Contains(current.mousePosition))
                        {
                            index = selections.Length - 1;
                        }
                    }
                    if (index < 0)
                    {
                        return false;
                    }
                    int num8 = Mathf.Min(initIndex, index);
                    int num9 = Mathf.Max(initIndex, index);
                    for (int k = 0; k < selections.Length; k++)
                    {
                        if ((k >= num8) && (k <= num9))
                        {
                            selections[k] = adding;
                        }
                        else
                        {
                            selections[k] = initSelections[k];
                        }
                    }
                    current.Use();
                    return true;
                }
                case EventType.Repaint:
                    for (int m = 0; m < positions.Length; m++)
                    {
                        style.Draw(positions[m], GUIContent.none, controlID, selections[m]);
                    }
                    goto Label_030C;

                default:
                    goto Label_030C;
            }
            if (num5 == 1)
            {
                flag = true;
            }
        Label_0132:
            if (!current.shift && !EditorGUI.actionKey)
            {
                for (int n = 0; n < positions.Length; n++)
                {
                    selections[n] = false;
                }
            }
            initIndex = index;
            initSelections = (bool[]) selections.Clone();
            adding = true;
            if ((current.shift || EditorGUI.actionKey) && selections[index])
            {
                adding = false;
            }
            selections[index] = !flag ? adding : false;
            GUIUtility.hotControl = controlID;
            current.Use();
            return true;
        Label_030C:
            return false;
        }

Usage Example

示例#1
0
        void DrawLegend()
        {
            List <Rect> legendRects         = new List <Rect>();
            List <AudioCurveWrapper> curves = GetShownAudioCurves();
            Rect legendRect = GUILayoutUtility.GetRect(10, 40 * EditorGUIUtility.pixelsPerPoint);

            legendRect.x     += 4 + EditorGUI.indent;
            legendRect.width -= 8 + EditorGUI.indent;
            // Graph's position acts as reference for Legends
            legendRect.y = m_CurveEditor.rect.y + m_CurveEditor.rect.height + 20;
            int width = Mathf.Min(75, Mathf.FloorToInt(legendRect.width / curves.Count));

            for (int i = 0; i < curves.Count; i++)
            {
                legendRects.Add(new Rect(legendRect.x + width * i, legendRect.y, width, legendRect.height));
            }

            bool resetSelections = false;

            if (curves.Count != m_SelectedCurves.Length)
            {
                m_SelectedCurves = new bool[curves.Count];
                resetSelections  = true;
            }

            if (EditorGUIExt.DragSelection(legendRects.ToArray(), ref m_SelectedCurves, GUIStyle.none) || resetSelections)
            {
                // If none are selected, select all
                bool someSelected = false;
                for (int i = 0; i < curves.Count; i++)
                {
                    if (m_SelectedCurves[i])
                    {
                        someSelected = true;
                    }
                }
                if (!someSelected)
                {
                    for (int i = 0; i < curves.Count; i++)
                    {
                        m_SelectedCurves[i] = true;
                    }
                }

                SyncShownCurvesToLegend(curves);
            }

            for (int i = 0; i < curves.Count; i++)
            {
                EditorGUI.DrawLegend(legendRects[i], curves[i].color, curves[i].legend.text, m_SelectedCurves[i]);
                if (curves[i].curveProp.hasMultipleDifferentValues)
                {
                    GUI.Button(new Rect(legendRects[i].x, legendRects[i].y + 20, legendRects[i].width, 20), "Different");
                }
            }
        }
All Usage Examples Of UnityEditor.EditorGUIExt::DragSelection