简体   繁体   中英

TypeLoadException after compile unity editor script into dll

I have compiled our editor scripts into a single .dll file, and put it in /Assets/Editor directory:

在此处输入图片说明

These extended script menus are shown in editor correctly:

在此处输入图片说明

But it has this TypeLoadException when I click the menu. The type 'Util' is actually in 'UnityVS.x3dgame.CSharp.csproj' project, which is also a library project.

TypeLoadException: Could not load type 'Util' from assembly 'EditorLibrary'.
Scene2DBundleTool.GenerateSceneEffectLuaEditor ()

在此处输入图片说明

I have no idea how to solve this.

Here is some more information: Solution structure:

在此处输入图片说明

EditorLibrary references:

在此处输入图片说明

Help wanted.

You get this error because you did not build the dll it properly. If you want to include Unity's API in your own dll, you must add also add Unity reference to the dll so that your dll can use those API.

You must the basic references such as, System , System.Core and System.Xml .

Now, you must add Unity's references to your dll project before build the dll project. The dll reference to add depends on where the Unity API came from.

Standalone API :

  • UnityEngine.dll - from C:\\Program Files\\Unity\\Editor\\Data\\Managed

Editor API :

  • UnityEditor.dll - from C:\\Program Files\\Unity\\Editor\\Data\\Managed

UI :

  • UnityEngine.UI.dll - from C:\\Program Files\\Unity\\Editor\\Data\\UnityExtensions\\Unity\\GUISystem

    [Editor features]:

  • UnityEditor.UI.dll - from C:\\Program Files\\Unity\\Editor\\Data\\UnityExtensions\\Unity\\GUISystem\\Editor

Finally, make sure to select the proper .NET framework in your dll project before building it. .Net Framework 2.0 should be fine.

Our Unity's path may be different but once you find the root path where it is installed, everything else is the-same.

Note:

When I said, add reference, I meant add reference to the library project you are building not to your Unity project. From Visual Studio, this can be done by going to Projects ---> Add Reference... ---> Browse...(Button) then select the appropriate dll file.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM