Ejemplo n.º 1
0
        internal static EditorElement CreateEditorElement(VisualElement element, IMGUIContainer header, IMGUIContainer footer, SmartInspector smartInspector)
        {
            var editor      = EditorElementRef.GetEditor(element);
            var editorIndex = EditorElementRef.GetEditorIndex(element);
            var inspector   = EditorElementRef.GetInspectorElement(element);

            var window  = smartInspector.propertyEditor;
            var tracker = smartInspector.tracker;


            var data = new EditorElement(element)
            {
                header    = header,
                inspector = inspector,
                footer    = footer,

                index         = editorIndex,
                expandedState = -1,

                editor  = editor,
                window  = window,
                tracker = tracker,

                smartInspector = smartInspector,
            };

            return(data);
        }
Ejemplo n.º 2
0
        void SetElementVisible(EditorElement x, bool visible, bool changeDisplay = true)
        {
            x.expandedState = visible ? 1 : 0;
            x.element.EnableClass("is-expanded", visible);

            if (changeDisplay)
            {
                x.inspector.style.display = visible ? DisplayStyle.Flex : DisplayStyle.None;
            }

            //Debug.Log($"{x.name} {visible}");
        }
Ejemplo n.º 3
0
        void OnComponentLayout(EditorElement x)
        {
            // Do this only once on selection change for components
            if (x.expandedState != -1)
            {
                return;
            }

            x.expandedState = InternalEditorUtility.GetIsInspectorExpanded(x.target) ? 1 : 0;

            SetElementVisible(x, x.isExpanded);
        }
Ejemplo n.º 4
0
        void OnMaterialLayout(EditorElement x)
        {
            var isExpanded = InternalEditorUtility.GetIsInspectorExpanded(x.target);

            if (x.isExpanded != isExpanded)
            {
                SetElementVisible(x, isExpanded, changeDisplay: false);

                // Material doesn't care about our flexing, unless we set global expand state
                if (x.isMaterial)
                {
                    InternalEditorUtility.SetIsInspectorExpanded(x.target, x.isExpanded);
                }
            }
        }
Ejemplo n.º 5
0
        public InspectorTab(EditorElement editor)
        {
            this.editor  = editor;
            this.tracker = PropertyEditorRef.GetTracker(inspector.propertyEditor);

            name = GetTitle();
            RestoreTabState();

            AddToClassList(EditorTabClass);
            AddToClassList("toolbar-button");

            RegisterCallbacks();

            preview   = AssetPreview.GetAssetPreview(target);
            thumbnail = AssetPreview.GetMiniThumbnail(target);

            icon = new FluentUITK.Icon();
            Add(icon);

            this.Query(className: "unity-toggle__input").First().RemoveFromHierarchy();
        }
Ejemplo n.º 6
0
        /// <see cref="EditorElementPatch.Init_"/>
        public void SetupEditorElement(EditorElement x)
        {
            var element   = x.element;
            var header    = x.header;
            var inspector = x.inspector;
            var footer    = x.footer;
            var data      = x.Get <SubData>().First();

            var cullingEnabled = prefs.useIMGUICulling;

            if (x.isGo)
            {
                // Tabs bar is injected inside GO editor
                gameObjectEditor = element;
            }

            element.AddClass("editor-element");
            header.AddClass("header");
            inspector.AddClass("inspector");
            footer.AddClass("footer");

            header.onAddChild    = e => e.AddToClassList("user-element");
            inspector.onAddChild = e => e.AddToClassList("user-element");

            SetupSubData();
            SetupEditorElement();
            SetupHeader();
            SetupInspectorElement();
            // Footer is manipulated by EditorElementPatch.Init_

            if (!editors.ContainsKey(element))
            {
                editors.Add(element, x);
            }

            try
            {
                Runtime.SmartInspector.OnSetupEditorElement?.Invoke(x);
            }
            catch (Exception ex) { Debug.LogException(ex); }


            void SetupSubData()
            {
                if (data == null)
                {
                    inspector.Add(data = new SubData());
                }

                data.smartInspector = this;
                data.element        = x;
            }

            void SetupEditorElement()
            {
                x.Register <GeometryChangedEvent>(evt => OnElementLayout(data));

                element.EnableClass("game-object", x.isGo);
                element.EnableClass("transform", x.isTransform);
                element.EnableClass("component", x.isComponent);
                element.EnableClass("material", x.isMaterial);

                #if !UNITY_2020_1_OR_NEWER
                if (x.isTransform)
                {
                    element.style.top = -2;
                }
                #endif
            }

            void SetupHeader()
            {
                #if UNITY_2020_1_OR_NEWER
                header.x.cullingEnabled = cullingEnabled;
                #endif

                if (x.isComponent)
                {
                    x.header.Direction(FlexDirection.RowReverse);

                    var width = 64;
                    if (!prefs.showHelp)
                    {
                        width -= 20;
                    }
                    if (!prefs.showPreset)
                    {
                        width -= 20;
                    }

                    // Temp solution for component header buttons spacing
                    if (!x.header.Has("#rightSpace", out Space space))
                    {
                        space = new Space {
                            name = "rightSpace"
                        };
                        x.header.x.Add(space);
                    }

                    space.style.width = width;
                }
            }

            void SetupInspectorElement()
            {
                var container = inspector.Get <IMGUIContainer>().First() ??
                                inspector.Get(".unity-inspector-element__custom-inspector-container").First();

                if (container != null)
                {
                    SetupInspectorContainer(container);
                }
            }

            void SetupInspectorContainer(VisualElement container)
            {
                if (container is IMGUIContainer imgui)
                {
                    #if UNITY_2020_1_OR_NEWER
                    imgui.cullingEnabled = cullingEnabled;
                    #endif
                }

                if (x.isComponent)
                {
                    // Dragging is calculated based on container layout (it ignores InspectorElement padding)
                    container.style.paddingBottom = ComponentPaddingBottom;
                    inspector.style.paddingBottom = 0;
                }
            }
        }