Unity编译C#库的注意事项

我们有时想将编写的C#代码编译成库,方便后面使用。

我们可以使用以下命令编译成库:

Unity编译C#库的注意事项

1:使用这种命令的时候,里面包含的Editor文件夹千万需要另建一个Editor的库

2:代码中包含 #if Unity_Editor 宏定义的命令的也不要编译进去,需要单独剥离出来

如果不遵守以上两点,编译的库在另外一个工程里面使用打包的时候,会报这样的错误

ArgumentException: The Assembly UnityEditor is referenced by Tool ('Assets/Tools/JSBase/DLL/Tool.dll'). But the dll is not allowed to be included or could not be found.

最后希望看到这个贴子的朋友,对编译成库使用的时候出现bug有所帮助。