コード例 #1
0
        public override void OnInspectorGUI()
        {
            if (m_Styles == null)
            {
                m_Styles = new Styles();
            }
            if (this.m_Edited != null)
            {
                this.UpdateOrder(this.m_Edited);
                this.m_Edited = null;
            }
            EditorGUILayout.BeginVertical(EditorStyles.inspectorFullWidthMargins, new GUILayoutOption[0]);
            GUILayout.Label(m_Styles.helpText, EditorStyles.helpBox, new GUILayoutOption[0]);
            EditorGUILayout.Space();
            Rect       position = EditorGUILayout.BeginVertical(new GUILayoutOption[0]);
            int        id       = GUIUtility.GetControlID(s_DropFieldHash, FocusType.Passive, position);
            MonoScript script   = EditorGUI.DoDropField(position, id, typeof(MonoScript), new EditorGUI.ObjectFieldValidator(ScriptExecutionOrderInspector.MonoScriptValidatorCallback), false, m_Styles.dropField) as MonoScript;

            if (script != null)
            {
                this.AddScriptToCustomOrder(script);
            }
            EditorGUILayout.BeginVertical(m_Styles.boxBackground, new GUILayoutOption[0]);
            this.m_Scroll = EditorGUILayout.BeginVerticalScrollView(this.m_Scroll, new GUILayoutOption[0]);
            GUILayoutOption[] options = new GUILayoutOption[] { GUILayout.ExpandWidth(true) };
            int indexOfChangedItem    = DragReorderGUI.DragReorder(GUILayoutUtility.GetRect((float)10f, (float)(0x15 * this.m_CustomTimeScripts.Count), options), 0x15, this.m_CustomTimeScripts, new DragReorderGUI.DrawElementDelegate(this.DrawElement));

            if (indexOfChangedItem >= 0)
            {
                this.SetExecutionOrderAtIndexAccordingToNeighbors(indexOfChangedItem, 0);
                this.UpdateOrder(this.m_CustomTimeScripts[indexOfChangedItem]);
                this.SetExecutionOrderAtIndexAccordingToNeighbors(indexOfChangedItem, 0);
            }
            EditorGUILayout.EndScrollView();
            EditorGUILayout.EndVertical();
            GUILayout.BeginHorizontal(m_Styles.toolbar, new GUILayoutOption[0]);
            GUILayout.FlexibleSpace();
            GUIContent iconToolbarPlus = m_Styles.iconToolbarPlus;
            Rect       rect            = GUILayoutUtility.GetRect(iconToolbarPlus, m_Styles.toolbarDropDown);

            if (EditorGUI.ButtonMouseDown(rect, iconToolbarPlus, FocusType.Native, m_Styles.toolbarDropDown))
            {
                this.ShowScriptPopup(rect);
            }
            GUILayout.EndHorizontal();
            GUILayout.EndVertical();
            this.ApplyRevertGUI();
            GUILayout.EndVertical();
            GUILayout.FlexibleSpace();
        }
コード例 #2
0
        public override void OnInspectorGUI()
        {
            if (m_Edited)
            {
                UpdateOrder(m_Edited);
                m_Edited = null;
            }

            EditorGUILayout.BeginVertical(EditorStyles.inspectorFullWidthMargins);
            {
                GUILayout.Label(Content.helpText, EditorStyles.helpBox);

                EditorGUILayout.Space();

                // Vertical that contains box and the toolbar below it
                Rect listRect = EditorGUILayout.BeginVertical();
                {
                    int        dropFieldId = EditorGUIUtility.GetControlID(s_DropFieldHash, FocusType.Passive, listRect);
                    MonoScript dropped     = EditorGUI.DoDropField(listRect, dropFieldId, typeof(MonoScript), MonoScriptValidatorCallback, false, Styles.dropField) as MonoScript;
                    if (dropped)
                    {
                        AddScriptToCustomOrder(dropped);
                    }

                    // Vertical that is used as a border around the scrollview
                    EditorGUILayout.BeginVertical(Styles.boxBackground);
                    {
                        // The scrollview itself
                        m_Scroll = EditorGUILayout.BeginVerticalScrollView(m_Scroll);
                        {
                            // List
                            Rect r       = GUILayoutUtility.GetRect(10, kListElementHeight * m_CustomTimeScripts.Count, GUILayout.ExpandWidth(true));
                            int  changed = DragReorderGUI.DragReorder(r, kListElementHeight, m_CustomTimeScripts, DrawElement);
                            if (changed >= 0)
                            {
                                // Give dragged item value in between neighbors
                                SetExecutionOrderAtIndexAccordingToNeighbors(changed, 0);
                                // Update neighbors if needed
                                UpdateOrder(m_CustomTimeScripts[changed]);
                                // Neighbors may have been moved so there's more space around dragged item,
                                // so set order again to get possible rounding benefits
                                SetExecutionOrderAtIndexAccordingToNeighbors(changed, 0);
                            }
                        } EditorGUILayout.EndScrollView();
                    } EditorGUILayout.EndVertical();

                    // The toolbar below the box
                    GUILayout.BeginHorizontal(Styles.toolbar);
                    {
                        GUILayout.FlexibleSpace();
                        Rect       r2;
                        GUIContent content = Content.iconToolbarPlus;
                        r2 = GUILayoutUtility.GetRect(content, Styles.toolbarDropDown);
                        if (EditorGUI.DropdownButton(r2, content, FocusType.Passive, Styles.toolbarDropDown))
                        {
                            ShowScriptPopup(r2);
                        }
                    } GUILayout.EndHorizontal();
                } GUILayout.EndVertical();

                ApplyRevertGUI();
            } GUILayout.EndVertical();

            GUILayout.FlexibleSpace();
        }