Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Array Property Drawers in Unity 4.3

Discussion in 'Immediate Mode GUI (IMGUI)' started by jeffayde, Apr 15, 2014.

  1. jeffayde

    jeffayde

    Joined:
    Oct 5, 2012
    Posts:
    1
    In the patch notes for Unity 4.3 there was a note on support for PropertyDrawer attributes on array members being removed. I'm wondering if this was intended to remove having any custom property drawers for collections, or simply to remove the ability to decorate an array with an attribute. This causes a fairly significant restriction on the usage of property drawers, and I'm wondering if the change made for 4.3 might have been too far reaching.

    As I read that post it would appear that the intended removal was for code similar to:

    Code (csharp):
    1.  
    2. [CustomAttr]
    3. public Ability[] abilities;
    4.  
    This appears to have had the side effect of removing the ability to have custom class drawers for collections. Specifically code like:
    Code (csharp):
    1.  
    2. [CustomPropertyDrawer(typeof(Ability[]))]
    3. public class AbilityArrayDrawer : PropertyDrawer{
    4.  
    Removal of support for the first piece of code makes sense because it removes the ambiguity of how the attribute was intended to be applied (on the entire array, or each element of the array). The second case however is less ambiguous as it was explicitly set to be applied to all arrays of Ability.

    Looking at the PropertyDrawer class it appears that the support for modifying arrays removed inside of PropertyDrawer.GetDrawer with the code:
    Support for the first case listed above could be removed while maintaining support for the second case by moving that conditional check later in the method. Perhaps to make some code similar to:
    Code (csharp):
    1. if (propertyAttribute != null
    2.  !(property.isArray  property.propertyType != SerializedPropertyType.String))
    3. {
    4.     type2 = PropertyDrawer.GetDrawerTypeForType(propertyAttribute.GetType());
    5. }