我正在尝试从DLL文件创建自定义类ServerPlugin的实例,但是,我得到了例外:
TypeLoadException:无法加载类型'ServerPlugin'。
这是我的主要代码,它将创建ServerPlugin的实例:
public class Main : MonoBehaviour
{
void Start()
{
string path = System.IO.Path.Combine(Application.streamingAssetsPath, "ProjectIGTestMod.dll");
// Domain
AppDomain domain = AppDomain.CreateDomain("Plugin");
Type type = typeof(ServerPlugin);
// Create instance of plugin
ServerPlugin plugin = null;
try
{
plugin = domain.CreateInstanceFromAndUnwrap(path, type.FullName) as ServerPlugin;
}
catch (Exception e)
{
Debug.LogException(e);
}
// If loaded plugin
if (plugin != null)
{
// Load and enable
//plugin.onLoad();
plugin.onEnable();
}
}
}
这是我正在尝试创建一个实例的类:
namespace ProjectIGTestMod
{
public class Main : ServerPlugin
{
public void onLoad()
{
throw new System.NotImplementedException();
}
public void onEnable()
{
Debug.Log("Test Mod enabled.");
}
public void onDisable()
{
throw new System.NotImplementedException();
}
}
}
我不确定我到底做错了什么。我试图关注this code。