- Home /
Question by
Jean-Fabre · May 17, 2017 at 12:46 PM ·
classpropertydrawergenericcustomeditor
how to declare a custom propertydrawer of a ClassName
Hi Everyone,
I can create customPropertyDrawer attributes for a regular class, but I am not about the syntax for when the class is declaring generic type:
so if I have
[Serializable]
public class Owner<T> where T : Component{
}
how can I create the related custom property drawer? the code below doesn't work...
[CustomPropertyDrawer (typeof (Owner<T>))]
public class PlayMakerPropertyDrawerBaseClass : PropertyDrawer {
// and then I guess the following hurdle would be how to access T ?
}
Thanks :)
Bye,
Jean
Comment
Best Answer
Answer by Adam-Mechtley · May 17, 2017 at 01:02 PM
You can't specify an open generic type as the type for the PropertyDrawer. It's up to you how you go about it, but I usually do something like this:
public abstract class OwnerBase {}
// made this abstract because Unity will only serialize if it's a concrete type anyway
public abstract class Owner<T> : OwnerBase where T : Component {}
// add Serializable to your concrete implementations
[Serializable]
public class TransformOwner : Owner<Transform>
// specify the base type and that children should use the drawer
[CustomPropertyDrawer(typeof(OwnerBase), true)]
public class OwnerPropertyDrawer : PropertyDrawer {}
Answer by Jean-Fabre · May 17, 2017 at 01:05 PM
Hi,
I was worried I would not be able too.
neverMind I'll be using an attribute to define the type I need for the class, I need this for public variables inside components.
Thanks for your insight :)
Bye,
Jean
Your answer
