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; } })); }