void Init() { var editors = PopulateCache(); Object editorTarget = editor.targets[0]; string editorTitle = ObjectNames.GetInspectorTitle(editorTarget); var inspectorElementMode = InspectorElement.GetModeFromInspectorMode(inspectorWindow.inspectorMode); if (inspectorWindow.useUIElementsDefaultInspector) { inspectorElementMode &= ~(InspectorElement.Mode.IMGUIDefault); } m_InspectorElement = new InspectorElement(editor, inspectorElementMode) { focusable = false }; m_Header = BuildHeaderElement(editorTitle); m_Footer = BuildFooterElement(editorTitle); m_InspectorElement.name = editorTitle + "Inspector"; m_InspectorElement.style.paddingBottom = InspectorWindow.kEditorElementPaddingBottom; if (EditorNeedsVerticalOffset(editors, editorTarget)) { m_InspectorElement.style.overflow = Overflow.Hidden; } UpdateInspectorVisibility(); }
private void Reset(SerializedPropertyBindEvent evt) { Clear(); var bindProperty = evt.bindProperty; m_SerializedProperty = bindProperty; if (bindProperty == null) { return; } var handler = ScriptAttributeUtility.GetHandler(m_SerializedProperty); if (handler.hasPropertyDrawer) { var customPropertyGUI = handler.propertyDrawer.CreatePropertyGUI(m_SerializedProperty); if (customPropertyGUI == null) { customPropertyGUI = new IMGUIContainer(() => { var originalWideMode = InspectorElement.SetWideModeForWidth(this); try { EditorGUI.BeginChangeCheck(); m_SerializedProperty.serializedObject.Update(); EditorGUILayout.PropertyField(m_SerializedProperty, true); m_SerializedProperty.serializedObject.ApplyModifiedProperties(); if (EditorGUI.EndChangeCheck()) { DispatchPropertyChangedEvent(); } } finally { EditorGUIUtility.wideMode = originalWideMode; } }); } else { RegisterPropertyChangesOnCustomDrawerElement(customPropertyGUI); } hierarchy.Add(customPropertyGUI); } else { var field = CreateFieldFromProperty(bindProperty); if (field != null) { hierarchy.Add(field); } } }
private VisualElement CreatePropertyIMGUIContainer() { GUIContent customLabel = string.IsNullOrEmpty(label) ? null : new GUIContent(label); return(new IMGUIContainer(() => { var originalWideMode = InspectorElement.SetWideModeForWidth(this); try { if (!serializedProperty.isValid) { return; } EditorGUI.BeginChangeCheck(); serializedProperty.serializedObject.Update(); if (m_FoldoutDepth > 0) { EditorGUI.indentLevel += m_FoldoutDepth; } // Wait at last minute to call GetHandler, sometimes the handler cache is cleared between calls. var handler = ScriptAttributeUtility.GetHandler(serializedProperty); using (var nestingContext = handler.ApplyNestingContext(m_DrawNestingLevel)) { if (label == null) { EditorGUILayout.PropertyField(serializedProperty, true); } else if (label == string.Empty) { EditorGUILayout.PropertyField(serializedProperty, GUIContent.none, true); } else { EditorGUILayout.PropertyField(serializedProperty, new GUIContent(label), true); } } if (m_FoldoutDepth > 0) { EditorGUI.indentLevel -= m_FoldoutDepth; } serializedProperty.serializedObject.ApplyModifiedProperties(); if (EditorGUI.EndChangeCheck()) { DispatchPropertyChangedEvent(); } } finally { EditorGUIUtility.wideMode = originalWideMode; } })); }
static void SetInspectorElementChildIMGUIContainerFocusable(InspectorElement ve, bool focusable) { foreach (var child in ve.Children()) { var imguiContainer = child as IMGUIContainer; if (imguiContainer != null) { imguiContainer.focusable = focusable; } } }
internal static void SetElementVisible(InspectorElement ve, bool visible) { if (visible) { ve.style.display = DisplayStyle.Flex; SetInspectorElementChildIMGUIContainerFocusable(ve, true); } else { ve.style.display = DisplayStyle.None; SetInspectorElementChildIMGUIContainerFocusable(ve, false); } }
static void SetInspectorElementChildIMGUIContainerFocusable(InspectorElement ve, bool focusable) { var childCount = ve.childCount; for (int i = 0; i < childCount; ++i) { var child = ve[i]; if (child.isIMGUIContainer) { var imguiContainer = (IMGUIContainer)child; imguiContainer.focusable = focusable; } } }
void Init() { var editors = PopulateCache(); Object editorTarget = editor.targets[0]; string editorTitle = ObjectNames.GetInspectorTitle(editorTarget); var inspectorElementMode = InspectorElement.GetModeFromInspectorMode(inspectorWindow.inspectorMode); if (inspectorWindow.useUIElementsDefaultInspector) { inspectorElementMode &= ~(InspectorElement.Mode.IMGUIDefault); } m_InspectorElement = new InspectorElement(editor, inspectorElementMode) { focusable = false }; m_Header = BuildHeaderElement(editorTitle); m_Footer = BuildFooterElement(editorTitle); m_InspectorElement.name = editorTitle + "Inspector"; m_InspectorElement.style.paddingBottom = InspectorWindow.kEditorElementPaddingBottom; if (EditorNeedsVerticalOffset(editors, editorTarget)) { m_InspectorElement.style.overflow = Overflow.Hidden; } UpdateInspectorVisibility(); Add(m_Header); // If the editor targets contain many target and the multi editing is not supported, we should not add this inspector. // However, the header and footer are kept since these are showing information regarding this state. if ((editor.targets.Length <= 1) || (inspectorWindow.IsMultiEditingSupported(editor, editor.target))) { Add(m_InspectorElement); } Add(m_Footer); }
InspectorElement BuildInspectorElement() { var editors = PopulateCache(); var editorTitle = ObjectNames.GetInspectorTitle(m_EditorTarget); InspectorElement.Mode inspectorElementMode; var propertyEditor = inspectorWindow as PropertyEditor; if (null == propertyEditor || propertyEditor.inspectorElementModeOverride == 0) { inspectorElementMode = InspectorElement.GetModeFromInspectorMode(inspectorWindow.inspectorMode); if (inspectorWindow.useUIElementsDefaultInspector) { inspectorElementMode &= ~(InspectorElement.Mode.IMGUIDefault); } } else { inspectorElementMode = (InspectorElement.Mode)propertyEditor.inspectorElementModeOverride; } var inspectorElement = new InspectorElement(editor, inspectorElementMode) { focusable = false, name = editorTitle + "Inspector", style = { paddingBottom = PropertyEditor.kEditorElementPaddingBottom } }; if (EditorNeedsVerticalOffset(editors, m_EditorTarget)) { inspectorElement.style.overflow = Overflow.Hidden; } return(inspectorElement); }
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); } }