private void CheckIfPropertyHasPropertyDrawer(Type type) { //NOTE: arrays cannot have built-in property drawers if (hasBuiltInPropertyDrawer || isArray) { return; } hasBuiltInPropertyDrawer = ToolboxDrawerModule.HasNativeTypeDrawer(type); }
private void ProcessBuiltInData() { //check if this property has built-in property drawer if (!(hasBuiltInPropertyDrawer = ToolboxDrawerModule.HasNativeTypeDrawer(type))) { var propertyAttributes = fieldInfo.GetCustomAttributes <PropertyAttribute>(); foreach (var attribute in propertyAttributes) { var attributeType = attribute.GetType(); if (hasBuiltInPropertyDrawer = ToolboxDrawerModule.HasNativeTypeDrawer(attributeType)) { break; } } } }
/// <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)); }