DisplayObjectContextMenu() static private method

static private DisplayObjectContextMenu ( Rect position, Object context, int contextUserData ) : void
position UnityEngine.Rect
context Object
contextUserData int
return void
Exemplo n.º 1
0
        // Draws the help and settings part of the header.
        // Returns a Rect to know where to draw the rest of the header.
        internal virtual Rect DrawHeaderHelpAndSettingsGUI(Rect r)
        {
            // Help
            var settingsSize = EditorStyles.iconButton.CalcSize(EditorGUI.GUIContents.titleSettingsIcon);

            float currentOffset = settingsSize.x;

            const int kTopMargin = 5;
            // Settings; process event even for disabled UI
            Rect settingsRect = new Rect(r.xMax - currentOffset, r.y + kTopMargin, settingsSize.x, settingsSize.y);
            var  wasEnabled   = GUI.enabled;

            GUI.enabled = true;
            var showMenu = EditorGUI.DropdownButton(settingsRect, EditorGUI.GUIContents.titleSettingsIcon, FocusType.Passive,
                                                    EditorStyles.iconButton);

            GUI.enabled = wasEnabled;
            if (showMenu)
            {
                EditorUtility.DisplayObjectContextMenu(settingsRect, targets, 0);
            }

            currentOffset += settingsSize.x;

            // Show Editor Header Items.
            return(EditorGUIUtility.DrawEditorHeaderItems(new Rect(r.xMax - currentOffset, r.y + kTopMargin, settingsSize.x, settingsSize.y), targets));
        }
        public override void OnTitleBarGUI()
        {
            if (settingsEditor != null)
            {
                using (new EditorGUI.DisabledScope(!settingsEditor.IsEnabled()))
                {
                    var tagrObjects = new[] { settingsEditor.serializedObject.targetObject };

                    var btnWidth  = Styles.settingsBtn.GetFloat(StyleCatalogKeyword.width);
                    var btnHeight = Styles.settingsBtn.GetFloat(StyleCatalogKeyword.height);
                    var btnMargin = Styles.settingsBtn.GetFloat(StyleCatalogKeyword.marginTop);

                    var rect = GUILayoutUtility.GetRect(btnWidth, btnHeight);
                    rect.y = btnMargin;
                    EditorGUIUtility.DrawEditorHeaderItems(rect, tagrObjects);
                    var settingsRect = GUILayoutUtility.GetRect(btnWidth, btnHeight);
                    settingsRect.y = rect.y;

                    // Settings; process event even for disabled UI
                    var wasEnabled = GUI.enabled;
                    GUI.enabled = true;
                    var showMenu = EditorGUI.DropdownButton(settingsRect, GUIContent.none, FocusType.Passive, EditorStyles.optionsButtonStyle);
                    GUI.enabled = wasEnabled;
                    if (showMenu)
                    {
                        EditorUtility.DisplayObjectContextMenu(settingsRect, tagrObjects, 0);
                    }
                }
                base.OnTitleBarGUI();
            }
        }
Exemplo n.º 3
0
 internal static void DisplayObjectContextMenu(Rect position, UnityEngine.Object context, int contextUserData)
 {
     EditorUtility.DisplayObjectContextMenu(position, new UnityEngine.Object[]
     {
         context
     }, contextUserData);
 }
Exemplo n.º 4
0
        public override void OnTitleBarGUI()
        {
            if (settingsEditor != null)
            {
                using (new EditorGUI.DisabledScope(!settingsEditor.IsEnabled()))
                {
                    var tagrObjects = new[] { settingsEditor.serializedObject.targetObject };

                    var btnWidth  = Styles.settingsBtn.GetFloat(StyleCatalogKeyword.width);
                    var btnHeight = Styles.settingsBtn.GetFloat(StyleCatalogKeyword.height);
                    var btnMargin = Styles.settingsBtn.GetFloat(StyleCatalogKeyword.marginTop);

                    var rect = GUILayoutUtility.GetRect(btnWidth, btnHeight);
                    rect.y = btnMargin;
                    EditorGUIUtility.DrawEditorHeaderItems(rect, tagrObjects);
                    var settingsRect = GUILayoutUtility.GetRect(btnWidth, btnHeight);
                    settingsRect.y = rect.y;
                    if (GUI.Button(settingsRect, EditorGUI.GUIContents.titleSettingsIcon, Styles.settingsStyle))
                    {
                        EditorUtility.DisplayObjectContextMenu(settingsRect, tagrObjects, 0);
                    }
                }
                base.OnTitleBarGUI();
            }
        }
Exemplo n.º 5
0
        internal virtual void DrawHeaderHelpAndSettingsGUI(Rect r)
        {
            UnityEngine.Object target = this.target;
            EditorGUI.HelpIconButton(new Rect(r.xMax - 36f, r.y + 5f, 14f, 14f), target);
            EditorGUI.BeginDisabledGroup(!this.IsEnabled());
            Rect position = new Rect(r.xMax - 18f, r.y + 5f, 14f, 14f);

            if (EditorGUI.ButtonMouseDown(position, EditorGUI.GUIContents.titleSettingsIcon, FocusType.Native, EditorStyles.inspectorTitlebarText))
            {
                EditorUtility.DisplayObjectContextMenu(position, this.targets, 0);
            }
            EditorGUI.EndDisabledGroup();
        }
Exemplo n.º 6
0
        internal virtual void DrawHeaderHelpAndSettingsGUI(Rect r)
        {
            Vector2 vector   = EditorStyles.iconButton.CalcSize(EditorGUI.GUIContents.titleSettingsIcon);
            float   num      = vector.x;
            Rect    position = new Rect(r.xMax - num, r.y + 5f, vector.x, vector.y);

            if (EditorGUI.DropdownButton(position, EditorGUI.GUIContents.titleSettingsIcon, FocusType.Passive, EditorStyles.iconButton))
            {
                EditorUtility.DisplayObjectContextMenu(position, this.targets, 0);
            }
            num += vector.x;
            EditorGUIUtility.DrawEditorHeaderItems(new Rect(r.xMax - num, r.y + 5f, vector.x, vector.y), this.targets);
        }
Exemplo n.º 7
0
 public override void OnTitleBarGUI()
 {
     if (m_SettingsEditor != null)
     {
         var tagrObjects = new[] { m_SettingsEditor.serializedObject.targetObject };
         var rect        = GUILayoutUtility.GetRect(Styles.settingsBtn.GetFloat(StyleKeyword.width), Styles.settingsBtn.GetFloat(StyleKeyword.height));
         rect.y = Styles.settingsBtn.GetFloat(StyleKeyword.marginTop);
         EditorGUIUtility.DrawEditorHeaderItems(rect, tagrObjects);
         var settingsRect = GUILayoutUtility.GetRect(Styles.settingsBtn.GetFloat(StyleKeyword.width), Styles.settingsBtn.GetFloat(StyleKeyword.height));
         settingsRect.y = rect.y;
         if (GUI.Button(settingsRect, EditorGUI.GUIContents.titleSettingsIcon, Styles.settingsStyle))
         {
             EditorUtility.DisplayObjectContextMenu(settingsRect, tagrObjects, 0);
         }
     }
 }
Exemplo n.º 8
0
        internal virtual void DrawHeaderHelpAndSettingsGUI(Rect r)
        {
            Object target = this.target;
            float  num2   = 18f;

            if (this.IsEnabled())
            {
                Rect position = new Rect(r.xMax - num2, r.y + 5f, 14f, 14f);
                if (EditorGUI.ButtonMouseDown(position, EditorGUI.GUIContents.titleSettingsIcon, FocusType.Native, EditorStyles.inspectorTitlebarText))
                {
                    EditorUtility.DisplayObjectContextMenu(position, this.targets, 0);
                }
                num2 += 18f;
            }
            EditorGUI.HelpIconButton(new Rect(r.xMax - num2, r.y + 5f, 14f, 14f), target);
        }
Exemplo n.º 9
0
        internal virtual void DrawHeaderHelpAndSettingsGUI(Rect r)
        {
            // Help
            var settingsSize = EditorStyles.iconButton.CalcSize(EditorGUI.GUIContents.titleSettingsIcon);

            float currentOffset = settingsSize.x;

            const int kTopMargin = 5;
            // Settings
            Rect settingsRect = new Rect(r.xMax - currentOffset, r.y + kTopMargin, settingsSize.x, settingsSize.y);

            if (EditorGUI.DropdownButton(settingsRect, EditorGUI.GUIContents.titleSettingsIcon, FocusType.Passive,
                                         EditorStyles.iconButton))
            {
                EditorUtility.DisplayObjectContextMenu(settingsRect, targets, 0);
            }
            currentOffset += settingsSize.x;

            // Show Editor Header Items.
            EditorGUIUtility.DrawEditorHeaderItems(new Rect(r.xMax - currentOffset, r.y + kTopMargin, settingsSize.x, settingsSize.y), targets);
        }
Exemplo n.º 10
0
        internal static Rect DrawHeaderGUI(Editor editor, string header, float leftMargin)
        {
            GUILayout.BeginHorizontal(BaseStyles.inspectorBig);
            GUILayout.Space(kImageSectionWidth - 6);
            GUILayout.BeginVertical();
            GUILayout.Space(k_HeaderHeight);
            GUILayout.BeginHorizontal();
            if (leftMargin > 0f)
            {
                GUILayout.Space(leftMargin);
            }
            if (editor)
            {
                editor.OnHeaderControlsGUI();
            }
            else
            {
                EditorGUILayout.GetControlRect();
            }
            GUILayout.EndHorizontal();
            GUILayout.EndVertical();
            GUILayout.EndHorizontal();
            Rect fullRect = GUILayoutUtility.GetLastRect();

            // Content rect
            Rect r = new Rect(fullRect.x + leftMargin, fullRect.y, fullRect.width - leftMargin, fullRect.height);

            // Icon
            Rect iconRect = new Rect(r.x + 6, r.y + 6, 32, 32);

            if (editor)
            {
                editor.OnHeaderIconGUI(iconRect);
            }
            else
            {
                GUI.Label(iconRect, AssetPreview.GetMiniTypeThumbnail(typeof(UnityObject)), BaseStyles.centerStyle);
            }

            if (editor)
            {
                editor.DrawPostIconContent(iconRect);
            }

            // Help and Settings
            Rect titleRect;

            if (editor)
            {
                Rect  helpAndSettingsRect = editor.DrawHeaderHelpAndSettingsGUI(r);
                float rectX = r.x + kImageSectionWidth;
                titleRect = new Rect(rectX, r.y + 6, (helpAndSettingsRect.x - rectX) - 4, 16);
            }
            else
            {
                titleRect = new Rect(r.x + kImageSectionWidth, r.y + 6, r.width - kImageSectionWidth, 16);
            }

            // Title
            if (editor)
            {
                editor.OnHeaderTitleGUI(titleRect, header);
            }
            else
            {
                GUI.Label(titleRect, header, EditorStyles.largeLabel);
            }

            // Context Menu
            Event evt = Event.current;

            if (editor != null && evt.type == EventType.MouseDown && evt.button == 1 && r.Contains(evt.mousePosition))
            {
                EditorUtility.DisplayObjectContextMenu(new Rect(evt.mousePosition.x, evt.mousePosition.y, 0, 0), editor.targets, 0);
                evt.Use();
            }

            return(fullRect);
        }
Exemplo n.º 11
0
        internal static Rect DrawHeaderGUI(Editor editor, string header, float leftMargin)
        {
            if (Editor.s_Styles == null)
            {
                Editor.s_Styles = new Editor.Styles();
            }
            GUILayout.BeginHorizontal(Editor.s_Styles.inspectorBig, new GUILayoutOption[0]);
            GUILayout.Space(38f);
            GUILayout.BeginVertical(new GUILayoutOption[0]);
            GUILayout.Space(19f);
            GUILayout.BeginHorizontal(new GUILayoutOption[0]);
            if (leftMargin > 0f)
            {
                GUILayout.Space(leftMargin);
            }
            if (editor)
            {
                editor.OnHeaderControlsGUI();
            }
            else
            {
                EditorGUILayout.GetControlRect(new GUILayoutOption[0]);
            }
            GUILayout.EndHorizontal();
            GUILayout.EndVertical();
            GUILayout.EndHorizontal();
            Rect lastRect = GUILayoutUtility.GetLastRect();
            Rect r        = new Rect(lastRect.x + leftMargin, lastRect.y, lastRect.width - leftMargin, lastRect.height);
            Rect rect     = new Rect(r.x + 6f, r.y + 6f, 32f, 32f);

            if (editor)
            {
                editor.OnHeaderIconGUI(rect);
            }
            else
            {
                GUI.Label(rect, AssetPreview.GetMiniTypeThumbnail(typeof(UnityEngine.Object)), Editor.s_Styles.centerStyle);
            }
            if (editor)
            {
                editor.DrawPostIconContent(rect);
            }
            Rect rect2 = new Rect(r.x + 44f, r.y + 6f, r.width - 44f - 38f - 4f, 16f);

            if (editor)
            {
                editor.OnHeaderTitleGUI(rect2, header);
            }
            else
            {
                GUI.Label(rect2, header, EditorStyles.largeLabel);
            }
            if (editor)
            {
                editor.DrawHeaderHelpAndSettingsGUI(r);
            }
            Event current = Event.current;

            if (editor != null && current.type == EventType.MouseDown && current.button == 1 && r.Contains(current.mousePosition))
            {
                EditorUtility.DisplayObjectContextMenu(new Rect(current.mousePosition.x, current.mousePosition.y, 0f, 0f), editor.targets, 0);
                current.Use();
            }
            return(lastRect);
        }