【发布时间】:2016-07-02 18:58:23
【问题描述】:
我的项目有 2 个 DLL,一个是特定于 Android 的,另一个是独立于平台的。独立 DLL 加载 Android 程序集并调用 GetTypes 方法,但它没有返回所有公共类。 Android DLL 有 3 个类,其中 2 个是静态的,只有静态方法。只能实例化一个。不返回静态类。
Class1.cs(在VS中编译成dll):
using System;
using System.Reflection;
namespace ClassLibrary1
{
public class Class1
{
public void test()
{
Assembly asm = Assembly.Load("ClassLibrary2");
Type T = asm.GetType("ClassLibrary2.Class2");
T.InvokeMember("Method", BindingFlags.Static | BindingFlags.InvokeMethod, null, T, null);
}
}
}
Class2.cs(在VS中编译成单独的dll):
namespace ClassLibrary2
{
public static class Class2
{
public static void Method()
{
return;
}
}
}
UnityClass.cs(在 Unity 5.x 中分配给空游戏对象):
using UnityEngine;
using System;
class UnityClass : MonoBehaviour
{
public void Start()
{
var x = new ClassLibrary1.Class1();
x.test();
}
}
【问题讨论】:
-
您能在问题中包含您的代码吗?链接将来可能会失效。
标签: c# unity3d dll reflection