void Init(ICLRSharp_Environment env, CLRSharp_Instance instance) { mRuntimeObject = instance; var type = instance.type; mGetDataModel = type.GetMethod("GetDataModel", new MethodParamList(new[] { env.GetType(typeof(string)) })); mClose = type.GetMethod("Close", MethodParamList.constEmpty()); mCleanUp = type.GetMethod("CleanUp", MethodParamList.constEmpty()); mRefreshDate = type.GetMethod("RefreshData", new MethodParamList(new[] { env.GetType(typeof(UIInitArguments)) })); mGetState = type.GetMethod("get_State", MethodParamList.constEmpty()); mSetState = type.GetMethod("set_State", new MethodParamList(new[] { env.GetType(typeof(FrameState)) })); mTick = type.GetMethod("Tick", new MethodParamList(MethodParamList.constEmpty())); mOnChangeScene = type.GetMethod("OnChangeScene", new MethodParamList(new[] { env.GetType(typeof(int)) })); mCallFromMethod = type.GetMethod("CallFromOtherClass", new MethodParamList(new[] { env.GetType(typeof(string)), env.GetType(typeof(object[])) })); mOnShow = type.GetMethod("OnShow", MethodParamList.constEmpty()); }
public ScriptableController(ICLRSharp_Environment env, ICLRType type, string name) { var method = type.GetMethod(".ctor", MethodParamList.constEmpty()); mRuntimeObject = method.Invoke(ThreadContext.activeContext, null, null); mName = name; Init(env, (CLRSharp_Instance)mRuntimeObject); }
private void LoadModule(string name) { string path = name + ".dll"; string path2 = name + ".pdb"; byte[] bytes = Resources.Load <TextAsset>(path).bytes; byte[] bytes2 = Resources.Load <TextAsset>(path2).bytes; MemoryStream dllStream = new MemoryStream(bytes); MemoryStream pdbStream = new MemoryStream(bytes2); try { this.mRunEnv.LoadModule(dllStream, pdbStream, new PdbReaderProvider()); } catch (Exception var_6_59) { } this.mRunEnv.GetType(typeof(Dictionary <int, string>)); this.mRunEnv.GetType(typeof(Dictionary <ShopType, UIToggle>)); this.mRunEnv.GetType(typeof(Dictionary <int, CLRSharp_Instance>)); this.mRunEnv.GetType(typeof(Dictionary <int, Action>)); this.mRunEnv.GetType(typeof(Dictionary <short, Action>)); this.mRunEnv.GetType(typeof(LinkedList <int>)); this.mRunEnv.GetType(typeof(int[, ])); this.mRunEnv.GetType(typeof(List <Vector3>)); this.mRunEnv.GetType(typeof(List <ShopData>)); this.mRunEnv.GetType(typeof(List <EquipmentInfoData>)); this.mRunEnv.GetType(typeof(List <HeroInfoData>)); this.mRunEnv.GetType(typeof(List <SummSkinData>)); this.mRunEnv.GetType(typeof(List <int>[])); this.mRunEnv.GetType(typeof(List <List <int> >)); this.mRunEnv.GetType(typeof(List <List <List <int> > >)); this.mRunEnv.GetType(typeof(Vector3[])); this.mRunEnv.GetType(typeof(IEnumerable <int>)); Delegate_Binder.RegBind(typeof(Action <int>), new Delegate_BindTool <int>()); Delegate_Binder.RegBind(typeof(Action <bool, ShopData>), new Delegate_BindTool_Ret <bool, ShopData>()); Delegate_Binder.RegBind(typeof(Action <bool, EquipmentInfoData>), new Delegate_BindTool_Ret <bool, EquipmentInfoData>()); Delegate_Binder.RegBind(typeof(Action <bool, SummSkinData>), new Delegate_BindTool_Ret <bool, SummSkinData>()); Delegate_Binder.RegBind(typeof(Action <int, int>), new Delegate_BindTool <int, int>()); Delegate_Binder.RegBind(typeof(Action <int, int, int>), new Delegate_BindTool <int, int, int>()); Delegate_Binder.RegBind(typeof(Func <int, int, int>), new Delegate_BindTool_Ret <int, int, int>()); Delegate_Binder.RegBind(typeof(Action <int, string>), new Delegate_BindTool <int, string>()); Delegate_Binder.RegBind(typeof(Action <string>), new Delegate_BindTool <string>()); Delegate_Binder.RegBind(typeof(Action <bool>), new Delegate_BindTool <bool>()); this.mRunEnv.RegCrossBind(new IViewCrossBind()); if (ThreadContext.activeContext == null) { this.mContext = new ThreadContext(this.mRunEnv, 2); } ICLRType type = this.mRunEnv.GetType("GUIScript.ShellClass"); IMethod method = type.GetMethod("Initialize", MethodParamList.constEmpty()); method.Invoke(this.mContext, null, null); }
public void InvokeScriptMethod(byte[] datas) { var ot = env.GetType("FlyModel.Proto.ClientMethod") as Type_Common_CLRSharp; int opcode = BitConverter.ToInt32(datas, 0); string method = ""; foreach (var f in ot.type_CLRSharp.Fields) { if (f.HasConstant && (int)f.Constant == opcode) { method = f.Name; break; } } Debug.Log("try invoke method " + method); var ms = commandType.GetMethods(method); if (ms.Length > 0) { var m = ms[0]; if (m.Name == method) { if (m.ParamList.Count > 0) { var pt = m.ParamList[0]; var po = new CLRSharp_Instance(pt as ICLRType_Sharp); var ptctor = pt.GetMethod(".ctor", MethodParamList.constEmpty()); //取得构造函数 ptctor.Invoke(context, po, null); //执行构造函数 paramArray[0] = po; var ts = pt.GetMethod("ReadFrom", MethodParamList.Make( HotFixScript.env.GetType(typeof(byte[])), HotFixScript.env.GetType(typeof(int)), HotFixScript.env.GetType(typeof(int)) )); ts.Invoke(context, po, new object[] { datas, 4, datas.Length - 4 }); m.Invoke(context, null, paramArray); } } } else { Debug.LogError("Command " + method + " not found"); } }
public static MainUIThread GetInstance() { if (ui == null) { ui = GameObject.FindObjectOfType(typeof(MainUIThread)) as MainUIThread; if (!ui) { GameObject obj = new GameObject("_MainUIThread"); GameObject.DontDestroyOnLoad(obj); ui = obj.AddComponent <MainUIThread>(); ICLRType program = LSharpModule.env.GetType("GameUI.Program"); IMethod main = program.GetMethod("GetInstance", MethodParamList.constEmpty()); object program_object = main.Invoke(ThreadContext.activeContext, null, null); IMethod method_AddNotifys = program.GetMethod("AddNotifys", MethodParamList.Make(LSharpModule.env.GetType(typeof(MainUIThread)))); method_AddNotifys.Invoke(ThreadContext.activeContext, program_object, new object[] { ui }); } } return(ui); }
/// <summary> /// 构造函数只是为了把脚本实例传进来,用其他的形式也可以 /// </summary> /// <param name="inst"></param> public Base_IMyType(CLRSharp.CLRSharp_Instance inst) { var context = ThreadContext.activeContext; this.inst = inst; //这里先把需要的脚本方法记下来,只是为了后面调用起来方便 var ms = this.inst.type.GetMethodNames(); foreach (string name in ms) { if (name.Contains("GetName")) { _GetName = this.inst.type.GetMethod(name, MethodParamList.constEmpty()); } if (name.Contains("GetDesc")) { _GetDesc = this.inst.type.GetMethod(name, MethodParamList.constEmpty()); } if (name.Contains("SetName")) { _SetName = this.inst.type.GetMethod(name, MethodParamList.Make(context.environment.GetType(typeof(string)))); } } }
public Base_IMyType(CLRSharp_Instance inst) { ThreadContext activeContext = ThreadContext.activeContext; this.inst = inst; string[] methodNames = this.inst.type.GetMethodNames(); string[] array = methodNames; for (int i = 0; i < array.Length; i++) { string text = array[i]; if (text.Contains("get_transform")) { this._get_transform = this.inst.type.GetMethod(text, MethodParamList.constEmpty()); } if (text.Contains("get_gameObject")) { this._get_gameobject = this.inst.type.GetMethod(text, MethodParamList.constEmpty()); } if (text.Contains("get_WinResCfg")) { this._get_WinResCfg = this.inst.type.GetMethod(text, MethodParamList.constEmpty()); } if (text.Contains("get_uiWindow")) { this._get_uiWindow = this.inst.type.GetMethod(text, MethodParamList.constEmpty()); } if (text.Contains("set_uiWindow")) { this._set_uiWindow = this.inst.type.GetMethod(text, MethodParamList.Make(new ICLRType[] { activeContext.environment.GetType(typeof(TUIWindow)) })); } if (text.Contains("Init")) { this._Init = this.inst.type.GetMethod(text, MethodParamList.constEmpty()); } if (text.Contains("Destroy")) { this._Destroy = this.inst.type.GetMethod(text, MethodParamList.constEmpty()); } if (text.Contains("HandleAfterOpenView")) { this._HandleAfterOpenView = this.inst.type.GetMethod(text, MethodParamList.constEmpty()); } if (text.Contains("HandleBeforeCloseView")) { this._HandleBeforeCloseView = this.inst.type.GetMethod(text, MethodParamList.constEmpty()); } if (text.Contains("RegisterUpdateHandler")) { this._RegisterUpdateHandler = this.inst.type.GetMethod(text, MethodParamList.constEmpty()); } if (text.Contains("CancelUpdateHandler")) { this._CancelUpdateHandler = this.inst.type.GetMethod(text, MethodParamList.constEmpty()); } if (text.Contains("RefreshUI")) { this._RefreshUI = this.inst.type.GetMethod(text, MethodParamList.constEmpty()); } if (text.Contains("DataUpdated")) { this._DataUpdated = this.inst.type.GetMethod(text, MethodParamList.Make(new ICLRType[] { activeContext.environment.GetType(typeof(object)) })); } if (text.Contains("Initialize")) { this._Initialize = this.inst.type.GetMethod(text, MethodParamList.constEmpty()); } if (text.Contains("HandleHideEvent")) { this._HandleHideEvent = this.inst.type.GetMethod(text, MethodParamList.constEmpty()); } if (text.Contains("HandleDestroyEvent")) { this._HandleDestroyEvent = this.inst.type.GetMethod(text, MethodParamList.constEmpty()); } } }