Dll with editor scripts only?

I am preparing a submission for the asset store. Beside the runtime classes it contains a lot of editor scripts. I would like to bundle those editor scripts in a dll, but not the runtime classes.
AngryAnt describes nicely how to create dll’s for runtime and editor scripts together, but I don’t know how to use it for editor scripts only.

Edit: Maybe with extern?

Thats possible only within limited borders. You can put your whole editor code in the dll but you need to have the editor / editor window extending classes as plain code in unity or it won’t work (so called proxy classes). these then would be near empty skeletons calling the functionality inside the assembly

Thanks for your answer! As the project has only one class that inherits Editor, it should not be such a big deal.

I would be very thankful for a hint. If I am compiling the editor scripts only using the following command (simplified version):"C:\Program Files\Unity\Editor\Data\Mono\bin\gmcs.bat" -target:library -out:smile:llTesting.Editor.dll Editor\*.cs -d:UNITY_EDITOR -r:"C:\Program Files\Unity\Editor\Data\Managed\UnityEngine.dll" -r:"C:\Program Files\Unity\Editor\Data\Managed\UnityEditor.dll" -resource:Editor\Resources\*.png
several errors are shown. All look as follows:

Editor\AClassEditor.cs(7,11): error CS0246: The type or namespace name `AClass' could not be found. Are you missing a using directive or an assembly reference?

I understand that the compilation command does not point it to the other scripts and thus the compiler doesn’t know that code. How can I point it to that code? I don’t want to have the runtime code in another dll and user another -r: to that dll.

Is the dll in the root Unity folder? (Not the Assets folder, but the root: C:\Program Files (x86)\Unity_3_3\Editor)
Or, is it in the “Editor” folder under assets?

I’m not sure the root is a requirement for editor dll’s, but it is for runtime dlls.

sure that your proxy correctly imports the external assembly? (ie is the required using there, cause a dll will always be in an own namespace)

reissgrant, it is nowhere at the moment, as I am trying to compile it. If successful, it is meant to be placed an “Editor” folder under assets.

dreamora, there is no external assembly yet and also no proxy. I am trying to compile the dll, I already struggle there :-).

Ah I see.
Well there I would normally not use command line but either Visual Studio or MonoDevelop and create a new assembly project there, code the stuff, configure the release build to target into the Editor folder and then just build it.

I assume your setup to be this:

  • You’ve got a bunch of editor classes which need to reference some runtime classes.
  • Your runtime classes stand just fine on their own - not referencing the editor classes in any way.

The appropriate build setup should be this:

  1. Build all runtime classes into MyRuntime.dll, referencing UnityEngine.dll.
  2. Build all editor classes into MyEditor.dll, referencing UnityEngine.dll, UnityEditor.dll and MyRuntime.dll.
  3. Move MyRuntime.dll to your project assets folder and MyEditor.dll to a path in the assets folder with “Editor” somewhere in it. For Behave I use /Assets/Behave/Behave.Runtime.dll and /Assets/Behave/Editor/Behave.Editor.dll.

As dremora mentioned, ScriptableObject derived classes (that includes EditorWindow) cannot be instantiated from assemblies and will therefore need a proxy setup as he describes. MonoBehaviour derived classes can live in assemblies just fine.

I probably didn’t make my point clear enough. I’ll try to explain it with a simple example.

Let’s say the project only consists of one runtime and one editor class. They are located as follows:

My goal is to deliver the project as follows:

If I understand Dreamora, it may be necessary to deliver it as follows:

My questions are:
Is it possible to do that in Unity?
How can I compile the editor classes (in detail) to achieve this result?

You could set it up like that, by referencing the dll built from the scripts by Unity, when you build your editor dll. Wouldn’t be pretty, but could work.

It would be a lot easier to manage if you mode AClass.cs into an assembly as well though.

The proxy class would be needed in any case.

Thanks AngryAnt. I am going to make it like that, if the following is still possible:
Can it still be used for web player builds? Will it also work without pro license?

  1. Editor classes are not present in builds at all :wink:
  2. But yes, assemblies, as long as they don’t use .NET frameworks that are removed, still work fine in webplayers :slight_smile:

dreamora, sure the editor classes are not in the builds. The runtime classes would be in a dll, too. My question was, if that is a problem. But as you say, it works, I am going to make it like that.

Assemblies themself work.
Unsure what works in such a case where you mix editor and runtime classes in the DLL

I won’t mix them! Two dll’s, one for runtime and one for editor scripts.

then its no problem :slight_smile:

Assemblies are simply included in builds. The same rules apply to them as any script file placed in the assets folder. Regarding resources included in the assembly, those are just an available byte stream and are unaffected by the Unity build process.

Thank you guys! That was very helpful and I learned some new things about how Unity works!

That link is broken. Try here.