-
Notifications
You must be signed in to change notification settings - Fork 99
Description
测试Dll的源码
public class A
{
public void Test()
{
byte[] result = new byte[5]{1,1,1,1,1};
for (int i = 0; i < result.Length; i++)
{
Debug.Log("Before = " + result[i]);
result[i] = 2;
Debug.Log("After = " + result[i]);
}
}
}
在Unity中
public class B : MonoBehaviour
{
void Start()
{
//创建CLRSharp环境
//加载L#模块
//执行构造函数
…………
//调用A类的Test方法
IMethod method0 = wantType.GetMethod("Test",MethodParamList.constEmpty());
method0.Invoke(context, typeObj, null);
}
}
结果A类中Test方法里的result数组中的值没有改变,全部都为1。
用new初始化可以赋值成功,= 赋值失败
我用反射试了一下,没有上面的问题
public class C : MonoBehaviour
{
void Start()
{
TextAsset dll = Resources.Load("CryptoD") as TextAsset;
Assembly ass = Assembly.Load(dll.bytes);
Type type = ass.GetType("A");
Object obj = Activator.CreateInstance(type);
MethodInfo mi = type.GetMethod("Test");
mi.Invoke(obj, null);
}
}