/// <summary> /// Draws the component editors in an inspector. /// </summary> public void OnGUI() { if (m_ComponentList == null) { return; } if (m_ComponentList.isDirty) { RefreshEditors(); m_ComponentList.isDirty = false; } var isEditable = !UnityEditor.VersionControl.Provider.isActive || AssetDatabase.IsOpenForEdit(m_ComponentList.self, StatusQueryOptions.UseCachedIfPossible); if (!targetRequiresProxyMenu) { m_MarsInspectorSharedSettings.ComponentTabSelection = 0; } using (new EditorGUI.DisabledScope(!isEditable)) { EditorGUILayout.LabelField(EditorGUIUtils.GetContent("Components"), EditorStyles.boldLabel); var availableWidth = EditorGUIUtility.currentViewWidth; var isWideEnoughForAllTabs = availableWidth > k_MinWidthForAllTabs; if (isWideEnoughForAllTabs && targetRequiresProxyMenu) { m_MarsInspectorSharedSettings.ComponentTabSelection = GUILayout.Toolbar(m_MarsInspectorSharedSettings.ComponentTabSelection, k_ProxyComponentsStrings); } else if (targetRequiresProxyMenu) { var tabIndex = m_MarsInspectorSharedSettings.ComponentTabSelection; var shortIndex = (tabIndex == 0) ? 0 : 1; k_ProxyFilterStrings[1] = ((tabIndex == 0) ? k_ProxyFilter : k_ProxyComponentsStrings[tabIndex]) + k_DownArrowPostFix; using (var check = new EditorGUI.ChangeCheckScope()) { var selectedShortIndex = GUILayout.Toolbar(shortIndex, k_ProxyFilterStrings); if (shortIndex != selectedShortIndex) { if (selectedShortIndex == 0) { m_MarsInspectorSharedSettings.ComponentTabSelection = 0; } else { ComponentFilterContextMenu(); } } else if (check.changed) { ComponentFilterContextMenu(); } } } if (targetRequiresProxyMenu && (MarsInspectorSharedSettings.Instance.ComponentTabSelection == k_ForcesTab)) { Forces.EditorExtensions.ForcesMenuItemsRegions.DrawForcesInInspectorForMainProxy(m_BaseEditor.target); } // Override list for (var i = 0; i < m_Editors.Count; i++) { var editor = m_Editors[i]; if (editor.activeProperty.serializedObject.targetObject == null) { continue; } if (CanDrawSelectedOption(editor.target)) { var title = string.Format("{0}|{1}", editor.GetDisplayTitle(), editor.GetToolTip()); var id = i; // Needed for closure capture below EditorGUIUtils.DrawSplitter(); var displayContent = EditorGUIUtils.DrawHeader( title, editor.baseProperty, editor.activeProperty, () => ResetComponent(editor.target.GetType(), id), () => RemoveComponent(id), () => CopyComponent(id), () => PasteComponent(id), CanPasteComponent(id), editor.HasDisplayProperties() ); if (displayContent) { if (beforeDrawComponentInspector != null) { beforeDrawComponentInspector(editor); } using (new EditorGUI.DisabledScope(!editor.activeProperty.boolValue)) { editor.OnInternalInspectorGUI(); } if (afterDrawComponentInspector != null) { afterDrawComponentInspector(editor); } } } } if (targetRequiresProxyMenu || (m_BaseEditor.target is ProxyGroup)) { if (m_Editors.Count > 0) { EditorGUIUtils.DrawSplitter(); EditorGUILayout.Space(); } AddComponentMenuButton(); EditorGUILayout.Space(); } } }