public void CreateInspectorElement() { if (null == editor || null != m_InspectorElement || m_IsCulled) { return; } // Need to update the cache for multi-object edit detection. if (editor.targets.Length != Selection.objects.Length) { inspectorWindow.tracker.RebuildIfNecessary(); } // If the editor targets contain many targets and multi editing is not supported, we should not add this inspector. if (null != editor && (editor.targets.Length <= 1 || PropertyEditor.IsMultiEditingSupported(editor, editor.target, inspectorWindow.inspectorMode))) { m_InspectorElement = BuildInspectorElement(); Insert(IndexOf(m_Header) + 1, m_InspectorElement); UpdateInspectorVisibility(); SetElementVisible(m_InspectorElement, m_WasVisible); } }
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; } }