public sealed override void OnGUI(Rect rect, SerializedProperty property, GUIContent label) { // 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)) { OnGUI_Internal(rect, property, PropertyUtility.GetLabel(property)); } // Call OnValueChanged callbacks if (EditorGUI.EndChangeCheck()) { PropertyUtility.CallOnValueChangedCallbacks(property); } }
//OnEditor public void OnGUI(SerializedProperty property) { // 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); GUI.enabled = enabled; OnGUI_Internal(property, new GUIContent(PropertyUtility.GetLabel(property))); GUI.enabled = true; // Call OnValueChanged callbacks if (EditorGUI.EndChangeCheck()) { PropertyUtility.CallOnValueChangedCallbacks(property); } }
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 { GUIContent label = new GUIContent(PropertyUtility.GetLabel(property)); bool anyDrawerAttribute = PropertyUtility.GetAttributes <DrawerAttribute>(property).Any(); if (!anyDrawerAttribute) { // Drawer attributes check for visibility, enableability and validator themselves, // so if a property doesn't have a DrawerAttribute we need to check for these explicitly // 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, label, includeChildren); } // Call OnValueChanged callbacks if (EditorGUI.EndChangeCheck()) { PropertyUtility.CallOnValueChangedCallbacks(property); } } else { // We don't need to check for enableIfAttribute propertyFieldFunction.Invoke(rect, property, label, includeChildren); } } }
public static void PropertyField_Layout(SerializedProperty property, bool includeChildren) { SpecialCaseDrawerAttribute specialCaseAttribute = PropertyUtility.GetAttribute <SpecialCaseDrawerAttribute>(property); if (specialCaseAttribute != null) { specialCaseAttribute.GetDrawer().OnGUI(property); } else { GUIContent label = new GUIContent(PropertyUtility.GetLabel(property)); bool anyDrawerAttribute = PropertyUtility.GetAttributes <DrawerAttribute>(property).Any(); if (!anyDrawerAttribute) { // Drawer attributes check for visibility, enableability and validator themselves, // so if a property doesn't have a DrawerAttribute we need to check for these explicitly // 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); GUI.enabled = enabled; EditorGUILayout.PropertyField(property, label, includeChildren); GUI.enabled = true; // Call OnValueChanged callbacks if (EditorGUI.EndChangeCheck()) { PropertyUtility.CallOnValueChangedCallbacks(property); } } else { // We don't need to check for enableIfAttribute EditorGUILayout.PropertyField(property, label, includeChildren); } } }
private static bool PropertyField_Implementation(Rect rect, NaughtyProperty naughtyProperty, bool includeChildren, PropertyFieldFunction propertyFieldFunction) { bool changeDetected = false; if (naughtyProperty.specialCaseDrawerAttribute != null) { return(naughtyProperty.specialCaseDrawerAttribute.GetDrawer().OnGUI(rect, naughtyProperty)); } else { // Check if visible if (!naughtyProperty.cachedIsVisible) { return(false); } // Validate foreach (var validatorAttribute in naughtyProperty.validatorAttributes) { validatorAttribute.GetValidator().ValidateProperty(naughtyProperty.serializedProperty); } // Check if enabled and draw EditorGUI.BeginChangeCheck(); bool enabled = naughtyProperty.cachedIsEnabled; using (new EditorGUI.DisabledScope(disabled: !enabled)) { propertyFieldFunction.Invoke(rect, naughtyProperty, PropertyUtility.GetLabel(naughtyProperty.labelAttribute, naughtyProperty.serializedProperty), includeChildren); } // Call OnValueChanged callbacks if (EditorGUI.EndChangeCheck()) { changeDetected = true; PropertyUtility.CallOnValueChangedCallbacks(naughtyProperty.serializedProperty); } } return(changeDetected); }
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); } } }
public bool OnGUI(Rect rect, NaughtyProperty naughtyProperty) { bool changeDetected = false; // Check if visible bool visible = PropertyUtility.IsVisible(naughtyProperty.showIfAttribute, naughtyProperty.serializedProperty); if (!visible) { return(false); } // Validate ValidatorAttribute[] validatorAttributes = naughtyProperty.validatorAttributes; foreach (var validatorAttribute in validatorAttributes) { validatorAttribute.GetValidator().ValidateProperty(naughtyProperty.serializedProperty); } // Check if enabled and draw EditorGUI.BeginChangeCheck(); bool enabled = PropertyUtility.IsEnabled(naughtyProperty.readOnlyAttribute, naughtyProperty.enableIfAttribute, naughtyProperty.serializedProperty); using (new EditorGUI.DisabledScope(disabled: !enabled)) { OnGUI_Internal(rect, naughtyProperty.serializedProperty, PropertyUtility.GetLabel(naughtyProperty.labelAttribute, naughtyProperty.serializedProperty)); } // Call OnValueChanged callbacks if (EditorGUI.EndChangeCheck()) { changeDetected = true; PropertyUtility.CallOnValueChangedCallbacks(naughtyProperty.serializedProperty); } return(changeDetected); }