How to override inspector without [CustomEditor(typeof(Transform))]

Hi there!

I am working on some assets that require custom inspectors.

I’ve written a custom inspector in C# that is quite dynamic and works well and rely’s heavly on serialization, and it inspects the class it is meant to override, looking at its, attributes, properties, public and private stuff and presents this information in a different, standard way in unity. It works well but I have one remaining issue.

The problem I’m having is, I need a way to specifiy that this is a customer editor for a particular class without having to use the [CustomEditor(typeof(Transform))] before the class name. There will be classes that are unknown and may be added later, and i dont want to write a custom inspector for them every time. Ideally, it would override only classes that inherit specificly from some arbitial base class which is used to actually deveil classes for my framework, but the custom inspector itself, is designed to work outside the bound sof the framework and has no knowledge of it - so it should work with Transform, Camera and other already defined unity classes in addition to any created by other users, including, existing custom editors (though i could always just delete their editor code). .

Can this be done?

C#: Conditional Attributes

https://msdn.microsoft.com/en-us/library/aa664622(v=vs.71).aspx

I need more or less the same effect, but without actually specifiying it as an attribute, in code. I know this is a compile time thing but is there any method or base to start with?

Unity has to know about inspectors at compile time - it (probably) uses the information in the CustomEditor attribute to build an index, mapping a type to its custom editor type.

You could define a custom inspector for a given (base class) type, and then derive all your classes from that type. This will work, even for future types that haven’t been defined yet.

Regarding Transform, Camera, etc - these already define their own inspector probably, so you would have to explicitly state that your inspector is used for these types.