I'm poking around with exactly what wom wanted to do in the OP. I'm using a List<EventDelegate> in a custom class that I want to draw in the same way NGUI does. This is actually accomplished quite easily with PropertyDrawers. ArenMook, to answer your question: yes, you can decorate individual fields with an attribute that tells it to use a specific PropertyDrawer. That's exactly what they're for. You don't have to create them on a class-by-class basis.
All that's missing for this to work is a variant of NGUIEditorTools.DrawEvents that can be used by PropertyDrawers (i.e. it can't use GUILayout and EditorGUILayout).
Here's what's need. 1) an attribute we can decorate List<EventDelegate> with:
public class EventDelegateAttribute : PropertyAttribute
{
public readonly string name;
public EventDelegateAttribute ( string name )
{
this.name = name;
}
}
2) a PropertyDrawer for the above attribute:
[CustomPropertyDrawer
(typeof(EventDelegateAttribute
))] public class EventDelegateDrawer : PropertyDrawer
{
public override float GetPropertyHeight ( SerializedProperty prop, GUIContent label )
{
return NGUIEditorTools.GetEventsDrawerPropertyHeight(prop, label);
}
public override void OnGUI ( Rect position, SerializedProperty prop, GUIContent label )
{
NGUIEditorTools.DrawEventsPropertyDrawer(position, prop, label);
}
}
3) NGUI methods for drawing the EventDelegate editor in a PropertyDrawer (that part that's missing):
public partial class NGUIEditorTools
{
static public float GetEventsDrawerPropertyHeight ( SerializedProperty prop, GUIContent label )
{
//Calculate the space needed for the PropertyDrawer
}
static public void DrawEventsPropertyDrawer ( Rect position, SerializedProperty prop, GUIContent label )
{
UnityEngine.Object undoObject = prop.serializedObject.targetObject;
//'prop' is the SerializePoperty of type List<EventDelegate>
//Use GUI and EditorGUI methods to draw the events inside 'position'
}
}
Then, when we want to use it, all we have to do is:
[EventDelegate("On Click")]
[SerializeField
] private List
<EventDelegate
> onClick
= new List
<EventDelegate
>;
and that even applies to custom classes. I tested it in on of my own:
public class GameScreen : MonoBehaviour
{
[Serializable] public class NavButtonSettings
{
[HideInInspector] public bool isHidden = false;
public bool isClickable = true;
public UINavButton type;
public UINavButtonOverlay overlay;
public Justification overlayJustification = Justification.Center;
public string text;
public Justification textJustification = Justification.Center;
[EventDelegate("On Click")]
public List
<EventDelegate
> onClick
= new List
<EventDelegate
>(); }
/* Will be drawn exactly as you would expect. All the fields except
* 'onClick' draw in their normal way, but when it gets to 'onClick' the
* EventDelegateDrawer will be used. Hooray!
*/
[SerializeField
] private List
<NavButtonSettings
> btnSettings
= new List
<NavButtonSettings
>; }
90% of the actual work needed is just the drawing methods, which can mostly be copied from the existing ones with the *Layout methods replaced. I don't know how interested you'd be in this, ArenMook, but I think it'd be a really cool feature.
I'm in a time-crunch at the moment, so I'm just going to slap together half-assed versions of the 2 needed drawing methods for now. If this get's added later, I'll swap to the built in methods.