Ejemplo n.º 1
0
            public static int DragReorder(Rect position, int elementHeight, List <MonoScript> elements, ScriptExecutionOrderInspector.DragReorderGUI.DrawElementDelegate drawElementDelegate)
            {
                int  controlID = GUIUtility.GetControlID(ScriptExecutionOrderInspector.DragReorderGUI.s_DragReorderGUIHash, FocusType.Passive);
                Rect r         = position;

                r.height = (float)elementHeight;
                int  num = 0;
                Rect position2;

                if (GUIUtility.hotControl == controlID && Event.current.type == EventType.Repaint)
                {
                    for (int i = 0; i < elements.Count; i++)
                    {
                        if (i != ScriptExecutionOrderInspector.DragReorderGUI.s_ReorderingDraggedElement)
                        {
                            if (ScriptExecutionOrderInspector.DragReorderGUI.IsDefaultTimeElement(elements[i]))
                            {
                                num = i;
                                i++;
                            }
                            else
                            {
                                r.y = position.y + ScriptExecutionOrderInspector.DragReorderGUI.s_ReorderingPositions[i] * (float)elementHeight;
                                drawElementDelegate(r, elements[i], false);
                            }
                        }
                    }
                    position2 = new Rect(r.x, position.y + ScriptExecutionOrderInspector.DragReorderGUI.s_ReorderingPositions[num] * (float)elementHeight, r.width, (ScriptExecutionOrderInspector.DragReorderGUI.s_ReorderingPositions[num + 1] - ScriptExecutionOrderInspector.DragReorderGUI.s_ReorderingPositions[num] + 1f) * (float)elementHeight);
                }
                else
                {
                    for (int j = 0; j < elements.Count; j++)
                    {
                        r.y = position.y + (float)(j * elementHeight);
                        if (ScriptExecutionOrderInspector.DragReorderGUI.IsDefaultTimeElement(elements[j]))
                        {
                            num = j;
                            j++;
                        }
                        else
                        {
                            drawElementDelegate(r, elements[j], false);
                        }
                    }
                    position2 = new Rect(r.x, position.y + (float)(num * elementHeight), r.width, (float)(elementHeight * 2));
                }
                GUI.Label(position2, ScriptExecutionOrderInspector.m_Styles.defaultTimeContent, ScriptExecutionOrderInspector.m_Styles.defaultTime);
                bool flag = position2.height > (float)elementHeight * 2.5f;

                if (GUIUtility.hotControl == controlID)
                {
                    if (flag)
                    {
                        GUI.color = new Color(1f, 1f, 1f, 0.5f);
                    }
                    r.y = position.y + ScriptExecutionOrderInspector.DragReorderGUI.s_ReorderingPositions[ScriptExecutionOrderInspector.DragReorderGUI.s_ReorderingDraggedElement] * (float)elementHeight;
                    drawElementDelegate(r, elements[ScriptExecutionOrderInspector.DragReorderGUI.s_ReorderingDraggedElement], true);
                    GUI.color = Color.white;
                }
                int result = -1;

                switch (Event.current.GetTypeForControl(controlID))
                {
                case EventType.MouseDown:
                    if (position.Contains(Event.current.mousePosition))
                    {
                        GUIUtility.keyboardControl = 0;
                        EditorGUI.EndEditingActiveTextField();
                        ScriptExecutionOrderInspector.DragReorderGUI.s_ReorderingDraggedElement = Mathf.FloorToInt((Event.current.mousePosition.y - position.y) / (float)elementHeight);
                        if (!ScriptExecutionOrderInspector.DragReorderGUI.IsDefaultTimeElement(elements[ScriptExecutionOrderInspector.DragReorderGUI.s_ReorderingDraggedElement]))
                        {
                            ScriptExecutionOrderInspector.DragReorderGUI.s_ReorderingPositions = new float[elements.Count];
                            ScriptExecutionOrderInspector.DragReorderGUI.s_ReorderingGoals     = new int[elements.Count];
                            for (int k = 0; k < elements.Count; k++)
                            {
                                ScriptExecutionOrderInspector.DragReorderGUI.s_ReorderingGoals[k]     = k;
                                ScriptExecutionOrderInspector.DragReorderGUI.s_ReorderingPositions[k] = (float)k;
                            }
                            GUIUtility.hotControl = controlID;
                            Event.current.Use();
                        }
                    }
                    break;

                case EventType.MouseUp:
                    if (GUIUtility.hotControl == controlID)
                    {
                        if (ScriptExecutionOrderInspector.DragReorderGUI.s_ReorderingGoals[ScriptExecutionOrderInspector.DragReorderGUI.s_ReorderingDraggedElement] != ScriptExecutionOrderInspector.DragReorderGUI.s_ReorderingDraggedElement)
                        {
                            List <MonoScript> list = new List <MonoScript>(elements);
                            for (int l = 0; l < elements.Count; l++)
                            {
                                elements[ScriptExecutionOrderInspector.DragReorderGUI.s_ReorderingGoals[l]] = list[l];
                            }
                            result = ScriptExecutionOrderInspector.DragReorderGUI.s_ReorderingGoals[ScriptExecutionOrderInspector.DragReorderGUI.s_ReorderingDraggedElement];
                        }
                        ScriptExecutionOrderInspector.DragReorderGUI.s_ReorderingGoals          = null;
                        ScriptExecutionOrderInspector.DragReorderGUI.s_ReorderingPositions      = null;
                        ScriptExecutionOrderInspector.DragReorderGUI.s_ReorderingDraggedElement = -1;
                        GUIUtility.hotControl = 0;
                        Event.current.Use();
                    }
                    break;

                case EventType.MouseDrag:
                    if (GUIUtility.hotControl == controlID)
                    {
                        ScriptExecutionOrderInspector.DragReorderGUI.s_ReorderingPositions[ScriptExecutionOrderInspector.DragReorderGUI.s_ReorderingDraggedElement] = (Event.current.mousePosition.y - position.y) / (float)elementHeight - 0.5f;
                        ScriptExecutionOrderInspector.DragReorderGUI.s_ReorderingPositions[ScriptExecutionOrderInspector.DragReorderGUI.s_ReorderingDraggedElement] = Mathf.Clamp(ScriptExecutionOrderInspector.DragReorderGUI.s_ReorderingPositions[ScriptExecutionOrderInspector.DragReorderGUI.s_ReorderingDraggedElement], 0f, (float)(elements.Count - 1));
                        int num2 = Mathf.RoundToInt(ScriptExecutionOrderInspector.DragReorderGUI.s_ReorderingPositions[ScriptExecutionOrderInspector.DragReorderGUI.s_ReorderingDraggedElement]);
                        if (num2 != ScriptExecutionOrderInspector.DragReorderGUI.s_ReorderingGoals[ScriptExecutionOrderInspector.DragReorderGUI.s_ReorderingDraggedElement])
                        {
                            for (int m = 0; m < elements.Count; m++)
                            {
                                ScriptExecutionOrderInspector.DragReorderGUI.s_ReorderingGoals[m] = m;
                            }
                            int num3 = (num2 <= ScriptExecutionOrderInspector.DragReorderGUI.s_ReorderingDraggedElement) ? 1 : -1;
                            for (int num4 = ScriptExecutionOrderInspector.DragReorderGUI.s_ReorderingDraggedElement; num4 != num2; num4 -= num3)
                            {
                                ScriptExecutionOrderInspector.DragReorderGUI.s_ReorderingGoals[num4 - num3] = num4;
                            }
                            ScriptExecutionOrderInspector.DragReorderGUI.s_ReorderingGoals[ScriptExecutionOrderInspector.DragReorderGUI.s_ReorderingDraggedElement] = num2;
                        }
                        Event.current.Use();
                    }
                    break;

                case EventType.Repaint:
                    if (GUIUtility.hotControl == controlID)
                    {
                        for (int n = 0; n < elements.Count; n++)
                        {
                            if (n != ScriptExecutionOrderInspector.DragReorderGUI.s_ReorderingDraggedElement)
                            {
                                ScriptExecutionOrderInspector.DragReorderGUI.s_ReorderingPositions[n] = Mathf.MoveTowards(ScriptExecutionOrderInspector.DragReorderGUI.s_ReorderingPositions[n], (float)ScriptExecutionOrderInspector.DragReorderGUI.s_ReorderingGoals[n], 0.075f);
                            }
                        }
                        GUIView.current.Repaint();
                    }
                    break;
                }
                return(result);
            }
            public static int DragReorder(Rect position, int elementHeight, List <MonoScript> elements, ScriptExecutionOrderInspector.DragReorderGUI.DrawElementDelegate drawElementDelegate)
            {
                int  controlId = GUIUtility.GetControlID(ScriptExecutionOrderInspector.DragReorderGUI.s_DragReorderGUIHash, FocusType.Passive);
                Rect r         = position;

                r.height = (float)elementHeight;
                int  index1 = 0;
                Rect position1;

                if (GUIUtility.hotControl == controlId && Event.current.type == EventType.Repaint)
                {
                    for (int index2 = 0; index2 < elements.Count; ++index2)
                    {
                        if (index2 != ScriptExecutionOrderInspector.DragReorderGUI.s_ReorderingDraggedElement)
                        {
                            if (ScriptExecutionOrderInspector.DragReorderGUI.IsDefaultTimeElement(elements[index2]))
                            {
                                index1 = index2;
                                ++index2;
                            }
                            else
                            {
                                r.y = position.y + ScriptExecutionOrderInspector.DragReorderGUI.s_ReorderingPositions[index2] * (float)elementHeight;
                                drawElementDelegate(r, (object)elements[index2], false);
                            }
                        }
                    }
                    position1 = new Rect(r.x, position.y + ScriptExecutionOrderInspector.DragReorderGUI.s_ReorderingPositions[index1] * (float)elementHeight, r.width, (float)((double)ScriptExecutionOrderInspector.DragReorderGUI.s_ReorderingPositions[index1 + 1] - (double)ScriptExecutionOrderInspector.DragReorderGUI.s_ReorderingPositions[index1] + 1.0) * (float)elementHeight);
                }
                else
                {
                    for (int index2 = 0; index2 < elements.Count; ++index2)
                    {
                        r.y = position.y + (float)(index2 * elementHeight);
                        if (ScriptExecutionOrderInspector.DragReorderGUI.IsDefaultTimeElement(elements[index2]))
                        {
                            index1 = index2;
                            ++index2;
                        }
                        else
                        {
                            drawElementDelegate(r, (object)elements[index2], false);
                        }
                    }
                    position1 = new Rect(r.x, position.y + (float)(index1 * elementHeight), r.width, (float)(elementHeight * 2));
                }
                GUI.Label(position1, ScriptExecutionOrderInspector.m_Styles.defaultTimeContent, ScriptExecutionOrderInspector.m_Styles.defaultTime);
                bool flag = (double)position1.height > (double)elementHeight * 2.5;

                if (GUIUtility.hotControl == controlId)
                {
                    if (flag)
                    {
                        GUI.color = new Color(1f, 1f, 1f, 0.5f);
                    }
                    r.y = position.y + ScriptExecutionOrderInspector.DragReorderGUI.s_ReorderingPositions[ScriptExecutionOrderInspector.DragReorderGUI.s_ReorderingDraggedElement] * (float)elementHeight;
                    drawElementDelegate(r, (object)elements[ScriptExecutionOrderInspector.DragReorderGUI.s_ReorderingDraggedElement], true);
                    GUI.color = Color.white;
                }
                int num1 = -1;

                switch (Event.current.GetTypeForControl(controlId))
                {
                case EventType.MouseDown:
                    if (position.Contains(Event.current.mousePosition))
                    {
                        GUIUtility.keyboardControl = 0;
                        EditorGUI.EndEditingActiveTextField();
                        ScriptExecutionOrderInspector.DragReorderGUI.s_ReorderingDraggedElement = Mathf.FloorToInt((Event.current.mousePosition.y - position.y) / (float)elementHeight);
                        if (!ScriptExecutionOrderInspector.DragReorderGUI.IsDefaultTimeElement(elements[ScriptExecutionOrderInspector.DragReorderGUI.s_ReorderingDraggedElement]))
                        {
                            ScriptExecutionOrderInspector.DragReorderGUI.s_ReorderingPositions = new float[elements.Count];
                            ScriptExecutionOrderInspector.DragReorderGUI.s_ReorderingGoals     = new int[elements.Count];
                            for (int index2 = 0; index2 < elements.Count; ++index2)
                            {
                                ScriptExecutionOrderInspector.DragReorderGUI.s_ReorderingGoals[index2]     = index2;
                                ScriptExecutionOrderInspector.DragReorderGUI.s_ReorderingPositions[index2] = (float)index2;
                            }
                            GUIUtility.hotControl = controlId;
                            Event.current.Use();
                            break;
                        }
                        break;
                    }
                    break;

                case EventType.MouseUp:
                    if (GUIUtility.hotControl == controlId)
                    {
                        if (ScriptExecutionOrderInspector.DragReorderGUI.s_ReorderingGoals[ScriptExecutionOrderInspector.DragReorderGUI.s_ReorderingDraggedElement] != ScriptExecutionOrderInspector.DragReorderGUI.s_ReorderingDraggedElement)
                        {
                            List <MonoScript> monoScriptList = new List <MonoScript>((IEnumerable <MonoScript>)elements);
                            for (int index2 = 0; index2 < elements.Count; ++index2)
                            {
                                elements[ScriptExecutionOrderInspector.DragReorderGUI.s_ReorderingGoals[index2]] = monoScriptList[index2];
                            }
                            num1 = ScriptExecutionOrderInspector.DragReorderGUI.s_ReorderingGoals[ScriptExecutionOrderInspector.DragReorderGUI.s_ReorderingDraggedElement];
                        }
                        ScriptExecutionOrderInspector.DragReorderGUI.s_ReorderingGoals          = (int[])null;
                        ScriptExecutionOrderInspector.DragReorderGUI.s_ReorderingPositions      = (float[])null;
                        ScriptExecutionOrderInspector.DragReorderGUI.s_ReorderingDraggedElement = -1;
                        GUIUtility.hotControl = 0;
                        Event.current.Use();
                        break;
                    }
                    break;

                case EventType.MouseDrag:
                    if (GUIUtility.hotControl == controlId)
                    {
                        ScriptExecutionOrderInspector.DragReorderGUI.s_ReorderingPositions[ScriptExecutionOrderInspector.DragReorderGUI.s_ReorderingDraggedElement] = (float)(((double)Event.current.mousePosition.y - (double)position.y) / (double)elementHeight - 0.5);
                        ScriptExecutionOrderInspector.DragReorderGUI.s_ReorderingPositions[ScriptExecutionOrderInspector.DragReorderGUI.s_ReorderingDraggedElement] = Mathf.Clamp(ScriptExecutionOrderInspector.DragReorderGUI.s_ReorderingPositions[ScriptExecutionOrderInspector.DragReorderGUI.s_ReorderingDraggedElement], 0.0f, (float)(elements.Count - 1));
                        int num2 = Mathf.RoundToInt(ScriptExecutionOrderInspector.DragReorderGUI.s_ReorderingPositions[ScriptExecutionOrderInspector.DragReorderGUI.s_ReorderingDraggedElement]);
                        if (num2 != ScriptExecutionOrderInspector.DragReorderGUI.s_ReorderingGoals[ScriptExecutionOrderInspector.DragReorderGUI.s_ReorderingDraggedElement])
                        {
                            for (int index2 = 0; index2 < elements.Count; ++index2)
                            {
                                ScriptExecutionOrderInspector.DragReorderGUI.s_ReorderingGoals[index2] = index2;
                            }
                            int num3 = num2 <= ScriptExecutionOrderInspector.DragReorderGUI.s_ReorderingDraggedElement ? 1 : -1;
                            int reorderingDraggedElement = ScriptExecutionOrderInspector.DragReorderGUI.s_ReorderingDraggedElement;
                            while (reorderingDraggedElement != num2)
                            {
                                ScriptExecutionOrderInspector.DragReorderGUI.s_ReorderingGoals[reorderingDraggedElement - num3] = reorderingDraggedElement;
                                reorderingDraggedElement -= num3;
                            }
                            ScriptExecutionOrderInspector.DragReorderGUI.s_ReorderingGoals[ScriptExecutionOrderInspector.DragReorderGUI.s_ReorderingDraggedElement] = num2;
                        }
                        Event.current.Use();
                        break;
                    }
                    break;

                case EventType.Repaint:
                    if (GUIUtility.hotControl == controlId)
                    {
                        for (int index2 = 0; index2 < elements.Count; ++index2)
                        {
                            if (index2 != ScriptExecutionOrderInspector.DragReorderGUI.s_ReorderingDraggedElement)
                            {
                                ScriptExecutionOrderInspector.DragReorderGUI.s_ReorderingPositions[index2] = Mathf.MoveTowards(ScriptExecutionOrderInspector.DragReorderGUI.s_ReorderingPositions[index2], (float)ScriptExecutionOrderInspector.DragReorderGUI.s_ReorderingGoals[index2], 0.075f);
                            }
                        }
                        GUIView.current.Repaint();
                        break;
                    }
                    break;
                }
                return(num1);
            }