/// <summary> /// Process all Toolbox-related attributes. /// </summary> private void ProcessToolboxData() { //get all possible attributes and handle each directly by type var attributes = fieldInfo.GetCustomAttributes <ToolboxAttribute>(); foreach (var attribute in attributes) { HandleNewAttribute(attribute); } //check if property has a custom attribute or target type drawer hasToolboxPropertyAssignableDrawer = propertyAttribute != null; hasToolboxPropertyTargetTypeDrawer = ToolboxDrawerModule.HasTargetTypeDrawer(type); //check if property has any of it and cache value hasToolboxPropertyDrawer = hasToolboxPropertyAssignableDrawer || hasToolboxPropertyTargetTypeDrawer; //check if property has custom decorators and keep them in order if (decoratorAttributes != null) { decoratorAttributes.Sort((a1, a2) => a1.Order.CompareTo(a2.Order)); hasToolboxDecoratorDrawer = true; } //check if property has custom conditon drawer hasToolboxConditionDrawer = conditionAttribute != null; }
/// <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)); }