Ejemplo n.º 1
0
        VisualElement GetPanelContent(Editor editor)
        {
            if (editor == null)
            {
                return(null);
            }

            var root = editor.CreateInspectorGUI();

            if (root != null)
            {
                return(root);
            }

            // If the Editor does not provide an OnInspectorGUI, try to fall back to a toolbar.
            var inspector = editor.GetType().GetMethod("OnInspectorGUI",
                                                       BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);

            if (inspector == null || inspector.DeclaringType != editor.GetType())
            {
                if (editor is ICreateToolbar toolbar)
                {
                    return(EditorToolbar.CreateOverlay(toolbar.toolbarElements, containerWindow));
                }

                if (editor is ICreateHorizontalToolbar horizontal)
                {
                    return(horizontal.CreateHorizontalToolbarContent());
                }

                if (editor is ICreateVerticalToolbar vertical)
                {
                    return(vertical.CreateVerticalToolbarContent());
                }
            }

            return(new IMGUIContainer(editor.OnInspectorGUI));
        }
Ejemplo n.º 2
0
        // As a rule, Overlays should be compatible with toolbars or not. This class is an exception, hence the
        // possibility for ICreateToolbar implementations to return null.

        public OverlayToolbar CreateHorizontalToolbarContent()
        {
            var root = new OverlayToolbar();

            if (m_ContextEditor is ICreateHorizontalToolbar ctx)
            {
                root.Add(ctx.CreateHorizontalToolbarContent());
            }
            else if (m_ContextEditor is ICreateToolbar toolbar)
            {
                root.Add(EditorToolbar.CreateOverlay(toolbar.toolbarElements, containerWindow));
            }

            if (m_ToolEditor is ICreateHorizontalToolbar tool)
            {
                root.Add(tool.CreateHorizontalToolbarContent());
            }
            else if (m_ToolEditor is ICreateToolbar toolbar)
            {
                root.Add(EditorToolbar.CreateOverlay(toolbar.toolbarElements, containerWindow));
            }

            return(root);
        }