I’m new in the world of dlls and i was doing a lib to add it to unity having my editor scripts and normal scripts.
Everything works fine but i have one problem and i think i’m not understanding something.
In my dll project i cannot have the reference of UnityEditor, if i add it i will have an error when building the project and if i add #if UNITY_EDITOR in my dll project it don’t detect it which is ok.
The problem is that when i put my dll in Unity, it don’t understand when i put that #if so basically i’m limited on doing stuff in my normal scripts.
What i need to use those #if in my dll inside Unity. Is there a way to do it or am i limited?
Because if i add UnityEditor.dll in my solution when i build the dll, then in Unity i need to set the dll import settings to any platform and then i build it throws an error that cannot compile my dll because it has the UNityEditor.dll reference on it
#if SOMEFLAG means that the code’s only compiled if that flag is defined.
That works great in scripts in Unity, but for a .dll, everything’s already compiled. This means that those #if-conditions have already been parsed and resolved as you build the .dll.
So what you’re trying to do here won’t work. If you want to put both editor code and non-editor code in dlls, you’ll have to build two different dlls, and set the editor one to only get imported in editor - you can do that by clicking the dll and unchecking “standalone” in the editor.
Hi Baste!
I have my editors scripts on a dll and the normal scripts on another, they are called MGUILibEdito.dll and MGUILib.dll
My Editor dll has reference to UnityEngine and UnityEditor cause it need them and the normal scripts have reference to UnityEngine and has the #if unity_editor flag.
As you said those #if are compiled and in Unity they don’t have effect but i need in a way to have the same effect like if scripts are there.
For anyone that comes across this I also solved at .dll level by ensuring the release dll stripped out if #UNITY_EDITOR code and was only included in standalone using .dll Inspector settings. The editor dll included everything rather than just the editor scripts.
Create two configurations to build your scripts into a .dll:
Editor version: Everything
Runtime version: Editor code stripped out
Ensure that the assembly name is the same for both .dlls that you build (otherwise you’ll get problems in the compiled app) - I put my runtime version in a ‘Release’ folder.
Copy both .dlls into the project - as they have the same name you’ll have to put them in different folders.
Note: it would be nice to put the editor .dll in an editor folder but that doesn’t seem to work for me…
Ensure your runtime version is set to only be included on standalone platforms while the editor version is set to editor only.