private static void PropertyField_Implementation(Rect rect, SerializedProperty property, bool includeChildren, PropertyFieldFunction propertyFieldFunction) { SpecialCaseDrawerAttribute specialCaseAttribute = PropertyUtility.GetAttribute <SpecialCaseDrawerAttribute>(property); if (specialCaseAttribute != null) { specialCaseAttribute.GetDrawer().OnGUI(rect, property); } else { // Check if visible bool visible = PropertyUtility.IsVisible(property); if (!visible) { return; } // Validate ValidatorAttribute[] validatorAttributes = PropertyUtility.GetAttributes <ValidatorAttribute>(property); foreach (var validatorAttribute in validatorAttributes) { validatorAttribute.GetValidator().ValidateProperty(property); } // Check if enabled and draw EditorGUI.BeginChangeCheck(); bool enabled = PropertyUtility.IsEnabled(property); using (new EditorGUI.DisabledScope(disabled: !enabled)) { propertyFieldFunction.Invoke(rect, property, PropertyUtility.GetLabel(property), includeChildren); } // Call OnValueChanged callbacks if (EditorGUI.EndChangeCheck()) { PropertyUtility.CallOnValueChangedCallbacks(property); } } }
private void DrawChildProperties(Rect rect, SerializedProperty property) { ScriptableObject scriptableObject = property.objectReferenceValue as ScriptableObject; if (scriptableObject == null) { return; } Rect boxRect = new Rect() { x = 0.0f, y = rect.y + EditorGUIUtility.singleLineHeight, width = rect.width * 2.0f, height = rect.height - EditorGUIUtility.singleLineHeight }; GUI.Box(boxRect, GUIContent.none); using (new EditorGUI.IndentLevelScope()) { SerializedObject serializedObject = new SerializedObject(scriptableObject); using (var iterator = serializedObject.GetIterator()) { float yOffset = EditorGUIUtility.singleLineHeight; if (iterator.NextVisible(true)) { do { SerializedProperty childProperty = serializedObject.FindProperty(iterator.name); if (childProperty.name.Equals("m_Script", System.StringComparison.Ordinal)) { continue; } bool visible = PropertyUtility.IsVisible(childProperty); if (!visible) { continue; } float childHeight = GetPropertyHeight(childProperty); Rect childRect = new Rect() { x = rect.x, y = rect.y + yOffset, width = rect.width, height = childHeight }; NaughtyEditorGUI.PropertyField(childRect, childProperty, true); yOffset += childHeight; }while (iterator.NextVisible(false)); } } serializedObject.ApplyModifiedProperties(); } }
protected void DrawSerializedProperties() { serializedObject.Update(); // Draw non-grouped serialized properties foreach (var property in GetNonGroupedProperties(_serializedProperties)) { if (property.name.Equals("m_Script", System.StringComparison.Ordinal)) { using (new EditorGUI.DisabledScope(disabled: true)) { EditorGUILayout.PropertyField(property); } } else { NaughtyEditorGUI.PropertyField_Layout(property, includeChildren: true); } } // Draw grouped serialized properties foreach (var group in GetGroupedProperties(_serializedProperties)) { IEnumerable <SerializedProperty> visibleProperties = group.Where(p => PropertyUtility.IsVisible(p)); if (!visibleProperties.Any()) { continue; } NaughtyEditorGUI.BeginBoxGroup_Layout(group.Key); foreach (var property in visibleProperties) { NaughtyEditorGUI.PropertyField_Layout(property, includeChildren: true); } NaughtyEditorGUI.EndBoxGroup_Layout(); } // Draw foldout serialized properties foreach (var group in GetFoldoutProperties(_serializedProperties)) { IEnumerable <SerializedProperty> visibleProperties = group.Where(p => PropertyUtility.IsVisible(p)); if (!visibleProperties.Any()) { continue; } if (!_foldouts.ContainsKey(group.Key)) { _foldouts[group.Key] = new SavedBool($"{target.GetInstanceID()}.{group.Key}", false); } _foldouts[group.Key].Value = EditorGUILayout.Foldout(_foldouts[group.Key].Value, group.Key, true); if (_foldouts[group.Key].Value) { foreach (var property in visibleProperties) { NaughtyEditorGUI.PropertyField_Layout(property, true); } } } serializedObject.ApplyModifiedProperties(); }