protected virtual void OnCollisionStay2D(Collision2D collision) { if (onCollisionStay2D != null) { onCollisionStay2D.Invoke(LShapClient.context, lShapObject, new object[] { collision }); } }
protected virtual void OnCollisionExit(Collision collision) { if (onCollisionExit != null) { onCollisionExit.Invoke(LShapClient.context, lShapObject, new object[] { collision }); } }
protected virtual void OnTriggerStay2D(Collider2D collider) { if (onTriggerStay2D != null) { onTriggerStay2D.Invoke(LShapClient.context, lShapObject, new object[] { collider }); } }
protected virtual void FixedUpdate() { if (fixedUpdate != null) { fixedUpdate.Invoke(LShapClient.context, lShapObject, null); } }
protected virtual void OnTriggerExit(Collider collider) { if (onTriggerExit != null) { onTriggerExit.Invoke(LShapClient.context, lShapObject, new object[] { collider }); } }
public object CreateScriptObject(string rName, params object[] rArgs) { CLRSharp.ICLRType rType; bool rGot = TryGetType(rName, out rType); if (!rGot) { return(null); } var rList = MatchParamList(rArgs); CLRSharp.IMethod rCtor = rType.GetMethod(".ctor", rList); if (rCtor == null) { Debug.LogError("Create Script Object failed, check full type name and param list:>" + rName); return(null); } object rObj = rCtor.Invoke(context, null, rArgs); return(rObj); }
protected virtual void LateUpdate() { if (lateUpdate != null) { lateUpdate.Invoke(LShapClient.context, lShapObject, null); } }
object TestOne(CLRSharp.IMethod method, bool LogStep = false, bool notry = false) { int debug = LogStep ? 9 : 0; //if (CLRSharp.ThreadContext.activeContext == null) { CLRSharp.ThreadContext context = new CLRSharp.ThreadContext(env, debug); } CLRSharp.ThreadContext.activeContext.SetNoTry = notry; return(method.Invoke(CLRSharp.ThreadContext.activeContext, null, null)); }
public object CreateScriptObject(CLRSharp.ICLRType rType, params object[] rArgs) { var rList = MatchParamList(rArgs); CLRSharp.IMethod rCtor = rType.GetMethod(".ctor", rList); if (rCtor == null) { Debug.LogError("Create Script Object failed, check full type name and param list"); return(null); } object rObj = rCtor.Invoke(context, null, null); return(rObj); }
// Use this for initialization void Start() { //创建CLRSharp环境 env = new CLRSharp.CLRSharp_Environment(new LSharpLogger()); //加载L#模块 TextAsset dll = Resources.Load("Controller.dll") as TextAsset; TextAsset pdb = Resources.Load("Controller.pdb") as TextAsset; System.IO.MemoryStream msDll = new System.IO.MemoryStream(dll.bytes); System.IO.MemoryStream msPdb = new System.IO.MemoryStream(pdb.bytes); //env.LoadModule (msDll);//如果无符号是pdb的话,第二个参数传null env.LoadModule(msDll, msPdb, new Mono.Cecil.Pdb.PdbReaderProvider()); //Pdb //env.LoadModule(msDll, msMdb, new Mono.Cecil.Mdb.MdbReaderProvider());//如果符号是Mdb格式 Debug.Log("LoadModule Controller.dll done."); //step01建立一个线程上下文,用来模拟L#的线程模型,每个线程创建一个即可。 CLRSharp.ThreadContext context = new CLRSharp.ThreadContext(env); Debug.Log("Create ThreadContext for L#."); //step02取得想要调用的L#类型 CLRSharp.ICLRType wantType = env.GetType("Controller.Entry"); //用全名称,包括命名空间 Debug.Log("GetType:" + wantType.Name); //和反射代码中的Type.GetType相对应 //step03 静态调用 //得到类型上的一个函数,第一个参数是函数名字,第二个参数是函数的参数表,这是一个没有参数的函数 CLRSharp.IMethod method01 = wantType.GetMethod("Log", CLRSharp.MethodParamList.constEmpty()); method01.Invoke(context, null, null); //第三个参数是object[] 参数表,这个例子不需要参数 //这是个静态函数调用,对应到代码他就是HotFixCode.TestClass.Test1(); ////step04 成员调用 ////第二个测试程序是一个成员变量,所以先要创建实例 //CLRSharp.IMethod methodctor = wantType.GetMethod(".ctor", CLRSharp.MethodParamList.constEmpty());//取得构造函数 //object typeObj = methodctor.Invoke(context, null, null);//执行构造函数 ////这几行的作用对应到代码就约等于 HotFixCode.TestClass typeObj =new HotFixCode.TestClass(); //CLRSharp.IMethod method02 = wantType.GetMethod("Test2", CLRSharp.MethodParamList.constEmpty()); //method02.Invoke(context, typeObj, null); ////这两行的作用就相当于 typeOBj.Test2(); // //var list = CLRSharp.MethodParamList.Make(env.GetType(typeof(int)), env.GetType(typeof(string))); //CLRSharp.IMethod method03 = wantType.GetMethod("Test2", list); //method03.Invoke(context, typeObj, new object[] { 1234, "abcddd" }); ////这两行的作用就相当于 typeOBj.Test2(1234,"abcddd"); }
private void Form1_Load(object sender, EventArgs e) { //创建CLRSharp环境 env = new CLRSharp.CLRSharp_Environment(this); //加载L#模块 var dll = System.IO.File.ReadAllBytes("testdll01.dll"); var pdb = System.IO.File.ReadAllBytes("testdll01.pdb"); System.IO.MemoryStream msDll = new System.IO.MemoryStream(dll); System.IO.MemoryStream msPdb = new System.IO.MemoryStream(pdb); //env.LoadModule (msDll, null);//不需要pdb的话,第二个参数传null env.LoadModule(msDll, msPdb); Log("LoadModule HotFixCode.dll done."); //step01建立一个线程上下文,用来模拟L#的线程模型,每个线程创建一个即可。 CLRSharp.ThreadContext context = new CLRSharp.ThreadContext(env); Log("Create ThreadContext for L#."); //step02取得想要调用的L#类型 CLRSharp.ICLRType wantType = env.GetType("HoxFixCode.TestClass", null);//用全名称,包括命名空间 Log("GetType:" + wantType.Name); //和反射代码中的Type.GetType相对应 //step03 静态调用 //得到类型上的一个函数,第一个参数是函数名字,第二个参数是函数的参数表,这是一个没有参数的函数 CLRSharp.IMethod method01 = wantType.GetMethod("Test1", CLRSharp.MethodParamList.MakeEmpty()); method01.Invoke(context, null, null);//第三个参数是object[] 参数表,这个例子不需要参数 //这是个静态函数调用,对应到代码他就是HotFixCode.TestClass.Test1(); //step04 成员调用 //第二个测试程序是一个成员变量,所以先要创建实例 CLRSharp.CLRSharp_Instance typeObj = new CLRSharp.CLRSharp_Instance(wantType as CLRSharp.ICLRType_Sharp); //创建实例 CLRSharp.IMethod methodctor = wantType.GetMethod(".ctor", CLRSharp.MethodParamList.MakeEmpty()); //取得构造函数 methodctor.Invoke(context, typeObj, null); //执行构造函数 //这几行的作用对应到代码就约等于 HotFixCode.TestClass typeObj =new HotFixCode.TestClass(); CLRSharp.IMethod method02 = wantType.GetMethod("Test2", CLRSharp.MethodParamList.MakeEmpty()); method02.Invoke(context, typeObj, null); //这两行的作用就相当于 typeOBj.Test2(); }
private void Form1_Load(object sender, EventArgs e) { //创建CLRSharp环境 env = new CLRSharp.CLRSharp_Environment(this); //加载L#模块 var dll = System.IO.File.ReadAllBytes("testdll01.dll"); var pdb = System.IO.File.ReadAllBytes("testdll01.pdb"); System.IO.MemoryStream msDll = new System.IO.MemoryStream(dll); System.IO.MemoryStream msPdb = new System.IO.MemoryStream(pdb); //env.LoadModule (msDll);//不需要pdb的话 bool useSystemAssm = false; if (useSystemAssm) { byte[] dllbytes = msDll.ToArray(); byte[] pdbbytes = msPdb.ToArray(); var assem = System.Reflection.Assembly.Load(dllbytes, pdbbytes); //用系统反射加载 env.AddSerachAssembly(assem); //直接搜索系统反射,此时L#不发挥作用,为了调试的功能 } else { env.LoadModule(msDll, msPdb, new Mono.Cecil.Pdb.PdbReaderProvider()); } Log("LoadModule HotFixCode.dll done."); env.RegCrossBind(new MyCrossBind()); //step01建立一个线程上下文,用来模拟L#的线程模型,每个线程创建一个即可。 CLRSharp.ThreadContext context = new CLRSharp.ThreadContext(env); context.SetNoTry = true; Log("Create ThreadContext for L#."); //step02取得想要调用的L#类型 CLRSharp.ICLRType wantType = env.GetType("HoxFixCode.TestClass");//用全名称,包括命名空间 Log("GetType:" + wantType.Name); //和反射代码中的Type.GetType相对应 //step03 静态调用 //得到类型上的一个函数,第一个参数是函数名字,第二个参数是函数的参数表,这是一个没有参数的函数 CLRSharp.IMethod method01 = wantType.GetMethod("Test1", CLRSharp.MethodParamList.constEmpty()); method01.Invoke(context, null, null);//第三个参数是object[] 参数表,这个例子不需要参数 //这是个静态函数调用,对应到代码他就是HotFixCode.TestClass.Test1(); //step04 成员调用 //第二个测试程序是一个成员变量,所以先要创建实例 //CLRSharp.CLRSharp_Instance typeObj = new CLRSharp.CLRSharp_Instance(wantType as CLRSharp.ICLRType_Sharp);//创建实例 //上一句写的有问题,执行构造函数返回的才是 new出来的对象 CLRSharp.IMethod methodctor = wantType.GetMethod(".ctor", CLRSharp.MethodParamList.constEmpty()); //取得构造函数 //这里用object 就可以脚本和反射通用了 object typeObj = methodctor.Invoke(context, null, null); //执行构造函数 //这几行的作用对应到代码就约等于 HotFixCode.TestClass typeObj =new HotFixCode.TestClass(); CLRSharp.IMethod method02 = wantType.GetMethod("Test2", CLRSharp.MethodParamList.constEmpty()); for (int i = 0; i < 5; i++) { method02.Invoke(context, typeObj, null); } //这两行的作用就相当于 typeOBj.Test2(); //请注意,不要在初始化之后,再修改ParamList的内容 CLRSharp.MethodParamList list = CLRSharp.MethodParamList.Make( env.GetType(typeof(int)), env.GetType(typeof(string)) ); CLRSharp.IMethod method03 = wantType.GetMethod("Test3", list); CallMethod(method03, typeObj, 345, "abbc"); //获取TestClass.CreateMyI函数 //public static Interface.IMyType CreateMyI() //{ // return new myi(); //} CLRSharp.IMethod method04 = wantType.GetMethod("CreateMyI", CLRSharp.MethodParamList.constEmpty()); var obj = method04.Invoke(context, null, null); Interface.IMyType got = obj as Interface.IMyType; //执行他其实返回的是脚本的类型,但是可以让他自动转型成 程序认识的类型 }
void CallMethod(CLRSharp.IMethod method, object _this, params object[] _params) { CLRSharp.ThreadContext context = CLRSharp.ThreadContext.activeContext; method.Invoke(context, _this, _params); }