I've got a custom property drawer targeting an open generic type like the following:
[CustomPropertyDrawer(typeof(ClampableVariable<>), true)]
I then have types deriving from this type like:
class ClampableFloat : ClampableVariable<float>class ClampableChar : ClampableVariable<char>
I've also got a custom Editor like:
[CustomEditor(typeof(ClampableVariable<>), true)]
PowerInspector does not detect that these types implement this generic type as a result of how Type.IsSubclassOf works and thus the PropertyDrawer and Editor does not get used to render these types in PowerInspector.
I found this StackOverflow post which provides a handy method for checking if a type inherits from a given generic type:
static bool IsSubclassOfRawGeneric(Type generic, Type toCheck) {
while (toCheck != null && toCheck != typeof(object)) {
var cur = toCheck.IsGenericType ? toCheck.GetGenericTypeDefinition() : toCheck;
if (generic == cur) {
return true;
}
toCheck = toCheck.BaseType;
}
return false;
}
I noticed that Unity's native inspector can handle rendering the Editor but not the PropertyDrawer (even though they both target the open generic type).
I've got a custom property drawer targeting an open generic type like the following:
[CustomPropertyDrawer(typeof(ClampableVariable<>), true)]
I then have types deriving from this type like:
class ClampableFloat : ClampableVariable<float>
class ClampableChar : ClampableVariable<char>
I've also got a custom
Editor
like:[CustomEditor(typeof(ClampableVariable<>), true)]
PowerInspector does not detect that these types implement this generic type as a result of how
Type.IsSubclassOf
works and thus thePropertyDrawer
andEditor
does not get used to render these types in PowerInspector.I found this StackOverflow post which provides a handy method for checking if a type inherits from a given generic type:
I noticed that Unity's native inspector can handle rendering the
Editor
but not thePropertyDrawer
(even though they both target the open generic type).