Example #1
0
        public void Reinit(int editorIndex)
        {
            if (m_Header == null)
            {
                m_EditorIndex = editorIndex;
                Clear();
                Init();
                return;
            }

            PopulateCache();
            Object editorTarget = editor.targets[0];
            string editorTitle  = ObjectNames.GetInspectorTitle(editorTarget);

            // If the target change we need to invalidate IMGUI container cached measurements
            // See https://fogbugz.unity3d.com/f/cases/1279830/
            if (m_EditorTarget != editorTarget)
            {
                m_Header.MarkDirtyLayout();
                m_Footer.MarkDirtyLayout();
            }

            m_EditorTarget = editorTarget;
            m_EditorIndex  = editorIndex;

            m_Header.onGUIHandler = HeaderOnGUI;
            m_Footer.onGUIHandler = FooterOnGUI;

            name          = editorTitle;
            m_Header.name = editorTitle + "Header";
            m_Footer.name = editorTitle + "Footer";

            if (m_InspectorElement != null)
            {
                m_InspectorElement.AssignExistingEditor(editor);
                m_InspectorElement.name = editorTitle + "Inspector";

                // InspectorElement should be enabled only if the Editor is open for edit.
                m_InspectorElement.SetEnabled(editor.IsOpenForEdit());
            }

            UpdateInspectorVisibility();
        }
Example #2
0
        void HeaderOnGUI()
        {
            var editors = PopulateCache();

            if (!IsEditorValid())
            {
                if (m_InspectorElement != null)
                {
                    SetElementVisible(m_InspectorElement, false);
                }
                return;
            }

            // Avoid drawing editor if native target object is not alive, unless it's a MonoBehaviour/ScriptableObject
            // We want to draw the generic editor with a warning about missing/invalid script
            // Case 891450:
            // - ActiveEditorTracker will automatically create editors for materials of components on tracked game objects
            // - UnityEngine.UI.Mask will destroy this material in OnDisable (e.g. disabling it with the checkbox) causing problems when drawing the material editor
            var target = editor.target;

            if (target == null && !NativeClassExtensionUtilities.ExtendsANativeType(target))
            {
                if (m_InspectorElement != null)
                {
                    SetElementVisible(m_InspectorElement, false);
                }
                return;
            }

            // Active polling of "open for edit" changes.
            // If the header is moving to UI Toolkit, we may have to rely on a scheduler instead.
            if (editor != null)
            {
                bool openForEdit = editor.IsOpenForEdit();
                if (openForEdit != m_LastOpenForEdit)
                {
                    m_LastOpenForEdit = openForEdit;
                    m_InspectorElement?.SetEnabled(openForEdit);
                }
            }

            m_WasVisible = inspectorWindow.WasEditorVisible(editors, m_EditorIndex, target);

            GUIUtility.GetControlID(target.GetInstanceID(), FocusType.Passive);
            EditorGUIUtility.ResetGUIState();

            if (editor.target is AssetImporter)
            {
                inspectorWindow.editorsWithImportedObjectLabel.Add(m_EditorIndex + 1);
            }

            //set the current PropertyHandlerCache to the current editor
            ScriptAttributeUtility.propertyHandlerCache = editor.propertyHandlerCache;
            using (new InspectorWindowUtils.LayoutGroupChecker())
            {
                m_DragRect = DrawEditorHeader(editors, target, ref m_WasVisible);
            }

            if (GUI.changed)
            {
                // If the header changed something, we must trigger a layout calculating on imgui children
                // Fixes Material editor toggling layout issues (case 1148706)
                InvalidateIMGUILayouts(this);
            }

            if (m_InspectorElement != null && m_WasVisible != IsElementVisible(m_InspectorElement))
            {
                SetElementVisible(m_InspectorElement, m_WasVisible);
            }

            UpdateInspectorVisibility();

            var multiEditingSupported = PropertyEditor.IsMultiEditingSupported(editor, target, inspectorWindow.inspectorMode);

            if (!multiEditingSupported && m_WasVisible)
            {
                GUILayout.Label("Multi-object editing not supported.", EditorStyles.helpBox);
                return;
            }

            InspectorWindowUtils.DisplayDeprecationMessageIfNecessary(editor);

            // Reset dirtiness when repainting
            if (Event.current.type == EventType.Repaint)
            {
                editor.isInspectorDirty = false;
            }

            // Case 1359247:
            // Object might have been unloaded. Calling into native code down here will crash the editor.
            if (editor.target != null)
            {
                bool excludedClass = InspectorWindowUtils.IsExcludedClass(target);
                if (excludedClass)
                {
                    EditorGUILayout.HelpBox(
                        "The module which implements this component type has been force excluded in player settings. This object will be removed in play mode and from any builds you make.",
                        MessageType.Warning);
                }
            }

            if (m_WasVisible)
            {
                m_ContentRect = m_InspectorElement?.layout ?? Rect.zero;
            }
            else
            {
                Rect r = m_Header.layout;
                r.y           = r.y + r.height - 1;
                r.height      = kFooterDefaultHeight;
                m_ContentRect = r;
            }
        }