private bool TryAssignConditionAttribute(ToolboxConditionAttribute attribute) { //prevent condition checks for children (for array properties) //we can only have on condition attribute per serialized property if (conditionAttribute != null || isChild) { return(false); } else { conditionAttribute = attribute; return(true); } }
public PropertyHandler(SerializedProperty property) { this.property = property; //get all available area attributes areaAttributes = property.GetAttributes <ToolboxAreaAttribute>(); //keep area attributes in proper order Array.Sort(areaAttributes, (a1, a2) => a1.Order.CompareTo(a2.Order)); //get only one attribute per type groupAttribute = property.GetAttribute <ToolboxGroupAttribute>(); propertyAttribute = property.GetAttribute <ToolboxPropertyAttribute>(); conditionAttribute = property.GetAttribute <ToolboxConditionAttribute>(); }
/// <summary> /// Constructor prepares all property-related data for custom drawing. /// </summary> /// <param name="property"></param> public ToolboxPropertyHandler(SerializedProperty property) { this.property = property; //here starts preparation of all needed data for this handler //first of all we have to retrieve the native data like FieldInfo, custom native drawer, etc. //after this we have to retrieve (if possible) all Toolbox-related data - ToolboxAttributes //set basic content for the handled property label = new GUIContent(property.displayName); //get FieldInfo associated to this property, it is needed to cache custom attributes if ((fieldInfo = property.GetFieldInfo(out type)) == null) { return; } isArray = property.isArray && property.propertyType == SerializedPropertyType.Generic; //check if this property has built-in property drawer if (!(hasNativePropertyDrawer = ToolboxDrawerModule.HasNativeTypeDrawer(type))) { var propertyAttributes = fieldInfo.GetCustomAttributes <PropertyAttribute>(); foreach (var attribute in propertyAttributes) { var attributeType = attribute.GetType(); if (hasNativePropertyDrawer = ToolboxDrawerModule.HasNativeTypeDrawer(attributeType)) { break; } } } if (isArray) { //get collection drawer associated to this array propertyAttribute = fieldInfo.GetCustomAttribute <ToolboxListPropertyAttribute>(); } else { //get property drawer associated to this field propertyAttribute = fieldInfo.GetCustomAttribute <ToolboxSelfPropertyAttribute>(); } //check if property has a custom attribute drawer hasToolboxPropertyAttributeDrawer = propertyAttribute != null; //check if property has a custom target type drawer hasToolboxPropertyTargetTypeDrawer = ToolboxDrawerModule.HasTargetTypeDrawer(type); hasToolboxPropertyDrawer = hasToolboxPropertyAttributeDrawer || hasToolboxPropertyTargetTypeDrawer; //validate child property using the associated FieldInfo if (isChild = (property.name != fieldInfo.Name)) { return; } //get only one condition attribute to valdiate state of this property conditionAttribute = fieldInfo.GetCustomAttribute <ToolboxConditionAttribute>(); hasToolboxConditionDrawer = conditionAttribute != null; //get all available decorator attributes decoratorAttributes = fieldInfo.GetCustomAttributes <ToolboxDecoratorAttribute>().ToArray(); hasToolboxDecoratorDrawer = decoratorAttributes != null && decoratorAttributes.Length > 0; //keep decorator attributes in the order Array.Sort(decoratorAttributes, (a1, a2) => a1.Order.CompareTo(a2.Order)); }
/// <summary> /// Constructor prepares all property-related data for custom drawing. /// </summary> /// <param name="property"></param> public ToolboxPropertyHandler(SerializedProperty property) { this.property = property; //here starts preparation of all needed data for this handler //first of all we have to retrieve native data like field info, custom native drawer, etc. //after this we have to retrieve (if possible) all Toolbox-related data - ToolboxAttributes //get field info associated with this property, this property is needed for custom attributes propertyFieldInfo = property.GetFieldInfo(out propertyType); if (propertyFieldInfo == null) { return; } //set basic content for handled property propertyLabel = new GUIContent(property.displayName); //check if this property has built-in property drawer if (!(hasNativePropertyDrawer = property.HasCustomDrawer(propertyType))) { var propertyAttributes = propertyFieldInfo.GetCustomAttributes <PropertyAttribute>(); foreach (var attribute in propertyAttributes) { if (hasNativePropertyDrawer = property.HasCustomDrawer(attribute.GetType())) { break; } } } hasToolboxTargetTypeDrawer = ToolboxDrawerUtility.HasTargetTypeDrawer(propertyType); //specify drawer attribute if (property.isArray) { //get collection drawer associated to this array field propertyArrayAttribute = propertyFieldInfo.GetCustomAttribute <ToolboxCollectionAttribute>(); } else { //get property drawer associated to this property propertySingleAttribute = propertyFieldInfo.GetCustomAttribute <ToolboxPropertyAttribute>(); } hasToolboxPropertyDrawer = hasToolboxTargetTypeDrawer || propertySingleAttribute != null || propertyArrayAttribute != null; //validate child property using associated field info if (propertyFieldInfo == null || propertyFieldInfo.Name != property.name) { return; } //get only one condition attribute to valdiate state of this property conditionAttribute = propertyFieldInfo.GetCustomAttribute <ToolboxConditionAttribute>(); //get all available decorator attributes decoratorAttributes = propertyFieldInfo.GetCustomAttributes <ToolboxDecoratorAttribute>() .ToArray(); //keep decorator attributes in proper order Array.Sort(decoratorAttributes, (a1, a2) => a1.Order.CompareTo(a2.Order)); }