Has anyone else tried using NGUI on a Unity project that puts scripts into pre-built assemblies? For scalability reasons we are building our game this way. See this video from Unite 11 for the full explanation of why this is a good idea and why more developers are starting to do this:
http://video.unity3d.com/video/3708530/unite-11-scaleable-gameWe are having a problem with NGUI when using this approach. Since all of our game code resides in scripts that are compiled into pre-built assemblies, using NGUI requires putting all the NGUI code into a pre-built assembly as well and then referencing it from our assemblies. We have done this, but we run into problems with NGUI code that uses "#if UNITY_EDITOR" to do conditional compilation. Since the code is compiled externally (by Visual Studio in our case, but you can also do it with MonoDevelop), we have to compile the DLL with or without UNITY_EDITOR defined. We cannot compile a single DLL that has the option of running with or without this define. If we define UNITY_EDITOR during compilation, then everything works fine in the Editor but building a stand-alone player fails due to the calls to UnityEditor.dll which is not allowed. If we do NOT define UNITY_EDITOR then we end up with some missing/incorrect behavior of NGUI within the editor. I see two possible solutions to this problem:
1. Remove all "#if UNITY_EDITOR" from the NGUI code and use events/delegates to decouple the editor-specific stuff and place it in a separate assembly. There would be no calls to the UnityEditor.dll API within NGUI.dll at all. A separate NGUIEditor.dll would contain everything that is editor-specific. This would register to the events broadcasted by NGUI.dll and perform any editor-specific stuff at the right time. Since NGUIEditor.dll is not present in a stand-alone build, nothing would be listening to those events and no UnityEditor.dll calls would ever be made.
2. Maintain two different build configurations of NGUI.dll, one for the editor with UNITY_EDITOR defined, and one for stand-alone builds without UNITY_EDITOR defined. We would use the editor version of NGUI.dll until ready to do a stand-alone build, at which time we'd need to replace NGUI.dll in the Unity project's Assets/Assemblies folder with the stand-alone version. This option seems like the easiest solution for the short term since we don't have to modify any NGUI code, but it comes with the ongoing nuisance of maintaining different versions of NGUI.dll.
Before we go ahead with option 2, I wanted to see if anyone else using NGUI has had to deal with this, and if so, what they did. It's possible that we are the first ones to try using NGUI in this manner. Unity has some known issues with scripts in pre-built assemblies that call the Unity API in certain ways. Most things work fine but there are a few gotchas. It would be reassuring to know that the developers of NGUI are aware of this usage scenario and are testing that all aspects of NGUI work as designed when the NGUI code is compiled into pre-built assemblies. We (Idol Minds) have purchased a NGUI professional license, if that makes a difference.
Best regards,
Jeremy Walker, Senior Programmer
Idol Minds, LLC