public static NaughtyProperty CreateNaughtyProperty(SerializedProperty serializedProperty) { NaughtyProperty naughtyProperty = new NaughtyProperty(); naughtyProperty.serializedProperty = serializedProperty; naughtyProperty.readOnlyAttribute = PropertyUtility.GetAttribute <ReadOnlyAttribute>(serializedProperty); naughtyProperty.enableIfAttribute = PropertyUtility.GetAttribute <EnableIfAttributeBase>(serializedProperty); naughtyProperty.showIfAttribute = PropertyUtility.GetAttribute <ShowIfAttributeBase>(serializedProperty); naughtyProperty.validatorAttributes = PropertyUtility.GetAttributes <ValidatorAttribute>(serializedProperty); naughtyProperty.labelAttribute = PropertyUtility.GetAttribute <LabelAttribute>(serializedProperty); naughtyProperty.specialCaseDrawerAttribute = PropertyUtility.GetAttribute <SpecialCaseDrawerAttribute>(serializedProperty); return(naughtyProperty); }
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); }
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); }
private static void DrawPropertyField_Layout(Rect rect, NaughtyProperty naughtyProperty, GUIContent label, bool includeChildren) { EditorGUILayout.PropertyField(naughtyProperty.serializedProperty, label, includeChildren); }
public static bool PropertyField_Layout(NaughtyProperty naughtyProperty, bool includeChildren) { Rect dummyRect = new Rect(); return(PropertyField_Implementation(dummyRect, naughtyProperty, includeChildren, DrawPropertyField_Layout)); }
public static bool PropertyField(Rect rect, NaughtyProperty naughtyProperty, bool includeChildren) { return(PropertyField_Implementation(rect, naughtyProperty, includeChildren, DrawPropertyField)); }