I'm in the process of developing a library for use with third-party Unity projects. Ideally, I'd like to have certain MonoBehaviours which are defined within that library (a compiled DLL) and then exposed within Unity. But, Unity doesn't seem to pick up on the existence of MonoBehaviours inside a DLL (even if I try to add them explicitly through an editor script).
The workaround I've found so far is to subclass my library MonoBehaviour in a script file, and add the subclass as a component. This seems to work so far, but is there a way to expose the library class to the editor directly?
{EDIT: this is old information for Unity 2.x} Unity does not yet support MonoBehaviours inside a DLL. See the comments on this blog post by AngryAnt. He mentions:
Unity unfortunately does not yet
support MonoBehaviours and
ScriptableObjects in external
assemblies. Remember that your
external code is still not a first
class citizen in your Unity runtime,
but an external assembly
As AngryAnt himself is a Unity employee, I expect that's coming from the source.
Unfortunately not - but I think that would be very worthwhile feature request. Currently, Unity only keeps "assets" in the project pane; and MonoBehaviours are only considered "assets" when they exist as actual files. Another limitation you have there is that MonoBehaviours can't be put into namespaces (they must always exist in the root namespace).
For your use case, I think the ideal solution would be if Unity could look into DLLs and search for anything subclassing "MonoBehaviour" and then allow you to "expand" the DLL (it must be in your Assets/-folder anyways). Then, it could also use the namespace hierarchy you provide in the DLL, so if you have, for instance "Jormugandr.Scripts.TheUberCharacterController", in your DLL JromungandrProTools.dll, and the user has put this into Assets/External/JromungandrProTools.dll, Unity could show this in the project pane as follows: