public void Register(AppDomain appdomain) { appdomain.RegisterCrossBindingAdaptor(new MonoBehaviourAdapter()); appdomain.RegisterCrossBindingAdaptor(new CoroutineAdapter()); appdomain.RegisterCrossBindingAdaptor(new IAsyncStateMachineClassInheritanceAdaptor()); appdomain.RegisterCrossBindingAdaptor(new ExceptionAdapter()); appdomain.RegisterCrossBindingAdaptor(new IExtensibleAdapter()); }
static void InitILRuntime(ILRuntime.Runtime.Enviorment.AppDomain domain) { //这里需要注册所有热更DLL中用到的跨域继承Adapter,否则无法正确抓取引用 domain.RegisterCrossBindingAdaptor(new MonoBehaviourAdapter()); domain.RegisterCrossBindingAdaptor(new CoroutineAdapter()); domain.RegisterCrossBindingAdaptor(new GComponentAdapter()); //domain.RegisterValueTypeBinder(typeof(Vector3), new Vector3Binder()); }
public static void Init(ILRuntime.Runtime.Enviorment.AppDomain app) { if (app == null) { //should log error return; } app.RegisterCrossBindingAdaptor(new ILRuntimeTest.TestFramework.TestClass2Adaptor()); app.RegisterCrossBindingAdaptor(new ILRuntimeTest.TestFramework.TestClass3Adaptor()); app.DelegateManager.RegisterDelegateConvertor <ILRuntimeTest.TestFramework.IntDelegate>((action) => { return(new ILRuntimeTest.TestFramework.IntDelegate((a) => { ((Action <Int32>)action)(a); })); }); app.DelegateManager.RegisterDelegateConvertor <ILRuntimeTest.TestFramework.Int2Delegate>((action) => { return(new ILRuntimeTest.TestFramework.Int2Delegate((a, b) => { ((Action <Int32, Int32>)action)(a, b); })); }); app.DelegateManager.RegisterDelegateConvertor <ILRuntimeTest.TestFramework.InitFloat>((action) => { return(new ILRuntimeTest.TestFramework.InitFloat((a, b) => { ((Action <Int32, Single>)action)(a, b); })); }); app.DelegateManager.RegisterDelegateConvertor <ILRuntimeTest.TestFramework.IntDelegate2>((action) => { return(new ILRuntimeTest.TestFramework.IntDelegate2((a) => { return ((Func <Int32, Int32>)action)(a); })); }); app.DelegateManager.RegisterDelegateConvertor <ILRuntimeTest.TestFramework.Int2Delegate2>((action) => { return(new ILRuntimeTest.TestFramework.Int2Delegate2((a, b) => { return ((Func <Int32, Int32, Boolean>)action)(a, b); })); }); app.DelegateManager.RegisterDelegateConvertor <ILRuntimeTest.TestFramework.IntFloatDelegate2>((action) => { return(new ILRuntimeTest.TestFramework.IntFloatDelegate2((a, b) => { return ((Func <Int32, Single, String>)action)(a, b); })); }); }
unsafe public void InitializeILRuntime(ILRuntime.Runtime.Enviorment.AppDomain AppDomain) { m_AppDomain = AppDomain; #if DEBUG && (UNITY_EDITOR || UNITY_ANDROID || UNITY_IPHONE) //由于Unity的Profiler接口只允许在主线程使用,为了避免出异常,需要告诉ILRuntime主线程的线程ID才能正确将函数运行耗时报告给Profiler m_AppDomain.UnityMainThreadID = System.Threading.Thread.CurrentThread.ManagedThreadId; m_AppDomain.DebugService.StartDebugService(56000); #endif //这里做一些ILRuntime的注册,注册漏了的委托,运行的时候会报错提示的 //委托,适配器,,值类型绑定等等的注册 m_AppDomain.DelegateManager.RegisterMethodDelegate <GameObject>(); m_AppDomain.DelegateManager.RegisterMethodDelegate <UnityEngine.Sprite>(); m_AppDomain.DelegateManager.RegisterDelegateConvertor <UnityEngine.Events.UnityAction>((act) => { return(new UnityEngine.Events.UnityAction(() => { ((System.Action)act)(); })); }); m_AppDomain.DelegateManager.RegisterMethodDelegate <System.String, UnityEngine.Object, System.Object[]>(); m_AppDomain.DelegateManager.RegisterDelegateConvertor <Improve.OnAsyncFinish>((act) => { return(new Improve.OnAsyncFinish((path, obj, paramList) => { ((System.Action <System.String, UnityEngine.Object, System.Object[]>)act)(path, obj, paramList); })); }); //m_AppDomain.RegisterValueTypeBinder(typeof(Vector3), new Vector3Binder()); m_AppDomain.RegisterCrossBindingAdaptor(new MonoBehaviourAdapter()); m_AppDomain.RegisterCrossBindingAdaptor(new CoroutineAdapter()); m_AppDomain.RegisterCrossBindingAdaptor(new GComponentAdapter()); //CLR重定向的注册 //DebugLog的重定向 var mi = typeof(Debug).GetMethod("Log", new System.Type[] { typeof(object) }); m_AppDomain.RegisterCLRMethodRedirection(mi, Log_11); //GameObject的get,add Commponent的注册 SetupCLRRedirectionAddGetComponent(); //FairyGUI的创建UI的重定向 SetupCLRRedirectionSetPackageItemExtension(); //初始化CLR绑定请放在初始化的最后一步!! //CLR绑定借助了ILRuntime的CLR重定向机制来实现,因为实质上也是将对CLR方法的反射调用重定向到我们自己定义的方法里面来。 //但是手动编写CLR重定向方法是个工作量非常巨大的事,而且要求对ILRuntime底层机制非常了解(比如如何装拆箱基础类型,怎么处理Ref/Out引用等等), //因此ILRuntime提供了一个代码生成工具来自动生成CLR绑定代码。 //在CLR绑定代码生成之后,需要将这些绑定代码注册到AppDomain中才能使CLR绑定生效, //但是一定要记得将CLR绑定的注册写在CLR重定向的注册后面,因为同一个方法只能被重定向一次,只有先注册的那个才能生效。 //请在生成了绑定代码后解除下面的的注释,将这些绑定代码注册到AppDomain中 ILRuntime.Runtime.Generated.CLRBindings.Initialize(m_AppDomain); }
public void InitializeILRuntime() { //注册LitJson LitJson.JsonMapper.RegisterILRuntimeCLRRedirection(appdomain); //注册CLR绑定 ILRuntime.Runtime.Generated.CLRBindings.Initialize(appdomain); //使用Couroutine时,C#编译器会自动生成一个实现了IEnumerator,IEnumerator<object>,IDisposable接口的类,因为这是跨域继承,所以需要写CrossBindAdapter(详细请看04_Inheritance教程),Demo已经直接写好,直接注册即可 appdomain.RegisterCrossBindingAdaptor(new CoroutineAdapter()); #region Action泛型转换 appdomain.DelegateManager.RegisterMethodDelegate <float>(); appdomain.DelegateManager.RegisterMethodDelegate <UnityEngine.EventSystems.PointerEventData>(); appdomain.DelegateManager.RegisterMethodDelegate <UnityEngine.EventSystems.AxisEventData>(); appdomain.DelegateManager.RegisterMethodDelegate <UnityEngine.Object>(); appdomain.DelegateManager.RegisterMethodDelegate <UnityEngine.Collider2D>(); appdomain.DelegateManager.RegisterMethodDelegate <string>(); #endregion appdomain.DelegateManager.RegisterDelegateConvertor <UnityEngine.Events.UnityAction>((action) => { return(new UnityEngine.Events.UnityAction(() => { ((System.Action)action)(); })); }); }
public static void RegisterAdaptor(ILRuntime.Runtime.Enviorment.AppDomain appdomain) { //注册自己写的适配器 appdomain.RegisterCrossBindingAdaptor(new IAsyncStateMachineClassInheritanceAdaptor()); appdomain.RegisterValueTypeBinder(typeof(Vector2), new Vector2Binder()); appdomain.RegisterValueTypeBinder(typeof(Vector3), new Vector3Binder()); appdomain.RegisterValueTypeBinder(typeof(Quaternion), new QuaternionBinder()); }
public static void Init(ILRuntime.Runtime.Enviorment.AppDomain app) { if (app == null) { // should log error return; } // adaptor register app.RegisterCrossBindingAdaptor(new TestBaseAdaptor()); app.RegisterCrossBindingAdaptor(new SubMonoBehaviorAdaptor()); app.RegisterCrossBindingAdaptor(new TestClassAdaptor()); // interface adaptor register app.RegisterCrossBindingAdaptor(new IDisposableAdaptor()); app.RegisterCrossBindingAdaptor(new ITestAdaptor()); app.RegisterCrossBindingAdaptor(new IUIViewAdaptor()); // delegate register // delegate convertor }
private void OnILRuntimeInitialized() { #if UNITY_EDITOR || UNITY_ANDROID || UNITY_IPHONE //appdomain.UnityMainThreadID = Thread.CurrentThread.ManagedThreadId; #endif appdomain.RegisterCrossBindingAdaptor(new MonoBehaviourAdapter()); CLRRedirection(); string KEY = "委托调用"; switch (KEY) { case "静态调用": { appdomain.Invoke("ILRuntime.Program", "Initialize", null); } break; case "实例调用": { object script = appdomain.Instantiate("ILRuntime.Main"); appdomain.Invoke("ILRuntime.Main", "Test", script); } break; case "反射调用": { var script = appdomain.LoadedTypes["ILRuntime.Main"]; var type = script.ReflectionType; var ctor = type.GetConstructor(new System.Type[0]); var obj = ctor.Invoke(null); var field = type.GetField("index", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance); field.SetValue(obj, 123456); var value = field.GetValue(obj); Debug.Log("ID = " + value); } break; default: break; } }
void GenerateCLRBindingByAnalysis(string dllFile, string generatedDir) { //用新的分析热更dll调用引用来生成绑定代码 ILRuntime.Runtime.Enviorment.AppDomain domain = new ILRuntime.Runtime.Enviorment.AppDomain(); using (System.IO.FileStream fs = new System.IO.FileStream(dllFile, System.IO.FileMode.Open, System.IO.FileAccess.Read)) { domain.LoadAssembly(fs); #region 这里需要注册所有热更DLL中用到的跨域继承Adapter,否则无法正确抓取引用 domain.RegisterCrossBindingAdaptor(new CoroutineAdapter()); #endregion ILRuntime.Runtime.CLRBinding.BindingCodeGenerator.GenerateBindingCode(domain, generatedDir); } }
/// <summary> /// 注册跨域继承适配器 /// </summary> /// <param name="appDomain">AppDomain</param> public static void Register(ILRuntimeDomain appDomain) { appDomain.RegisterCrossBindingAdaptor(new AdapterServiceProvider()); appDomain.RegisterCrossBindingAdaptor(new AdapterIServiceProvider()); }
public static void Init(ILRuntime.Runtime.Enviorment.AppDomain app) { if (app == null) { // should log error return; } // adaptor register app.RegisterCrossBindingAdaptor(new ClassInheritanceTestAdaptor()); app.RegisterCrossBindingAdaptor(new InterfaceTestAdaptor()); app.RegisterCrossBindingAdaptor(new TestClass2Adaptor()); app.RegisterCrossBindingAdaptor(new TestClass3Adaptor()); app.RegisterCrossBindingAdaptor(new TestClass4Adaptor()); app.RegisterCrossBindingAdaptor(new ClassInheritanceTest2Adaptor()); // delegate register app.DelegateManager.RegisterFunctionDelegate <System.Int32, System.Boolean>(); app.DelegateManager.RegisterMethodDelegate <System.Int32>(); app.DelegateManager.RegisterFunctionDelegate <System.Int32, System.Int32>(); app.DelegateManager.RegisterMethodDelegate <System.Int32, System.String, System.String>(); app.DelegateManager.RegisterMethodDelegate <ILRuntimeTest.TestFramework.BaseClassTest>(); // delegate convertor app.DelegateManager.RegisterDelegateConvertor <ILRuntimeTest.TestFramework.IntDelegate>((action) => { return(new ILRuntimeTest.TestFramework.IntDelegate((a) => { ((Action <Int32>)action)(a); })); }); app.DelegateManager.RegisterDelegateConvertor <ILRuntimeTest.TestFramework.Int2Delegate>((action) => { return(new ILRuntimeTest.TestFramework.Int2Delegate((a, b) => { ((Action <Int32, Int32>)action)(a, b); })); }); app.DelegateManager.RegisterDelegateConvertor <ILRuntimeTest.TestFramework.InitFloat>((action) => { return(new ILRuntimeTest.TestFramework.InitFloat((a, b) => { ((Action <Int32, Single>)action)(a, b); })); }); app.DelegateManager.RegisterDelegateConvertor <ILRuntimeTest.TestFramework.IntDelegate2>((action) => { return(new ILRuntimeTest.TestFramework.IntDelegate2((a) => { return ((Func <Int32, Int32>)action)(a); })); }); app.DelegateManager.RegisterDelegateConvertor <ILRuntimeTest.TestFramework.Int2Delegate2>((action) => { return(new ILRuntimeTest.TestFramework.Int2Delegate2((a, b) => { return ((Func <Int32, Int32, Boolean>)action)(a, b); })); }); app.DelegateManager.RegisterDelegateConvertor <ILRuntimeTest.TestFramework.IntFloatDelegate2>((action) => { return(new ILRuntimeTest.TestFramework.IntFloatDelegate2((a, b) => { return ((Func <Int32, Single, String>)action)(a, b); })); }); }
protected virtual void initOtherAdapters(AppDomain appdomain) { appdomain.RegisterCrossBindingAdaptor(new MonoBehaviourAdapter()); appdomain.RegisterCrossBindingAdaptor(new BaseDataAdapter()); appdomain.RegisterCrossBindingAdaptor(new BaseHttpRequestAdapter()); appdomain.RegisterCrossBindingAdaptor(new BaseRequestAdapter()); appdomain.RegisterCrossBindingAdaptor(new BaseResponseAdapter()); appdomain.RegisterCrossBindingAdaptor(new BytesHttpRequestAdapter()); appdomain.RegisterCrossBindingAdaptor(new DataMakerAdapter()); appdomain.RegisterCrossBindingAdaptor(new MessageBindToolAdapter()); appdomain.RegisterCrossBindingAdaptor(new PoolObjectAdapter()); appdomain.RegisterCrossBindingAdaptor(new UIContainerAdapter()); appdomain.RegisterCrossBindingAdaptor(new UIElementAdapter()); appdomain.RegisterCrossBindingAdaptor(new UIModelAdapter()); }
public void GenerateByAssemblies_InitILRuntime(ILRuntime.Runtime.Enviorment.AppDomain appdomain) { //注册跨域 appdomain.RegisterCrossBindingAdaptor(new XUIBehaviourAdaptors()); }
public static void RegisterAdaptor(ILRuntime.Runtime.Enviorment.AppDomain appdomain) { //注册自己写的适配器 appdomain.RegisterCrossBindingAdaptor(new IAsyncStateMachineClassInheritanceAdaptor()); }
/// <summary> /// 初始化一下ILRuntime框架的东西 /// 注册一些回掉 /// </summary> unsafe void InitializeILRuntime() { // 注册litjson LitJson.JsonMapper.RegisterILRuntimeCLRRedirection(appdomain); appdomain.RegisterCrossBindingAdaptor(new MonoBehaviourAdapter()); appdomain.RegisterCrossBindingAdaptor(new CoroutineAdapter()); //添加值绑定 appdomain.RegisterValueTypeBinder(typeof(Vector3), new Vector3Binder()); appdomain.RegisterValueTypeBinder(typeof(Quaternion), new QuaternionBinder()); appdomain.RegisterValueTypeBinder(typeof(Vector2), new Vector2Binder()); //==============================如果将委托实例传出给ILRuntime外部使用============================================= appdomain.DelegateManager.RegisterMethodDelegate <int>(); appdomain.DelegateManager.RegisterMethodDelegate <int, MemoryStream>(); appdomain.DelegateManager.RegisterMethodDelegate <Scene, LoadSceneMode>(); appdomain.DelegateManager.RegisterMethodDelegate <int, object>(); appdomain.DelegateManager.RegisterMethodDelegate <GameObject>(); appdomain.DelegateManager.RegisterMethodDelegate <bool>(); appdomain.DelegateManager.RegisterMethodDelegate <GameObject[]>(); appdomain.DelegateManager.RegisterMethodDelegate <UnityEngine.Object[]>(); appdomain.DelegateManager.RegisterMethodDelegate <Sprite[]>(); appdomain.DelegateManager.RegisterMethodDelegate <BaseEventData>(); appdomain.DelegateManager.RegisterMethodDelegate <float>(); appdomain.DelegateManager.RegisterMethodDelegate <Dictionary <string, string> >(); appdomain.DelegateManager.RegisterMethodDelegate <string>(); appdomain.DelegateManager.RegisterMethodDelegate <NotificationMessage>(); appdomain.DelegateManager.RegisterMethodDelegate <AssetBundlePackage>(); appdomain.DelegateManager.RegisterMethodDelegate <TrackEntry>(); appdomain.DelegateManager.RegisterFunctionDelegate <GameObject>(); appdomain.DelegateManager.RegisterMethodDelegate <System.Int32, System.Byte[]>(); //===========================委托转换器(DelegateConvertor)================================================ // 如果你需要将一个不是Action或者Func类型的委托实例传到ILRuntime外部使用的话, // 除了委托适配器,还需要额外写一个转换器,将Action和Func转换成你真正需要的那个委托类型 appdomain.DelegateManager.RegisterDelegateConvertor <UnityAction>((action) => { return(new UnityAction(() => { ((Action)action)(); })); }); appdomain.DelegateManager.RegisterDelegateConvertor <UnityAction <bool> >((action) => { return(new UnityAction <bool>((a) => { ((Action <bool>)action)(a); })); }); appdomain.DelegateManager.RegisterDelegateConvertor <UnityAction <string> >((action) => { return(new UnityAction <string>((a) => { ((Action <string>)action)(a); })); }); appdomain.DelegateManager.RegisterDelegateConvertor <UnityAction <float> >((action) => { return(new UnityAction <float>((a) => { ((Action <float>)action)(a); })); }); appdomain.DelegateManager.RegisterDelegateConvertor <UnityAction <Scene, LoadSceneMode> >((action) => { return(new UnityAction <Scene, LoadSceneMode>((s, l) => { ((Action <Scene, LoadSceneMode>)action)(s, l); })); }); appdomain.DelegateManager.RegisterDelegateConvertor <TweenCallback>((action) => { return(new TweenCallback(() => { ((Action)action)(); })); }); appdomain.DelegateManager.RegisterDelegateConvertor <UnityAction <BaseEventData> >((action) => { return(new UnityAction <BaseEventData>((p) => { ((Action <BaseEventData>)action)(p); })); }); appdomain.DelegateManager.RegisterDelegateConvertor <Spine.AnimationState.TrackEntryDelegate>((action) => { return(new Spine.AnimationState.TrackEntryDelegate((p) => { ((Action <TrackEntry>)action)(p); })); }); //不要注释 否则会开启大量反射方法 ILRuntime.Runtime.Generated.CLRBindings.Initialize(appdomain); AppDomainCommonSetting.Instance.SetupCLRRedirection(appdomain); }
protected void RegBindingAdaptor() { mApp.RegisterCrossBindingAdaptor(new IEnumeratorAdaptor()); }
void InitializeILRuntime() { #region Delegate appDomain.DelegateManager.RegisterMethodDelegate <int>(); appDomain.DelegateManager.RegisterFunctionDelegate <int, string>(); appDomain.DelegateManager.RegisterMethodDelegate <string>(); appDomain.DelegateManager.RegisterMethodDelegate <int, int>(); appDomain.DelegateManager.RegisterMethodDelegate <List <int>, List <int> >(); appDomain.DelegateManager.RegisterMethodDelegate <string, string>(); appDomain.DelegateManager.RegisterMethodDelegate <object, MessageArgs <object> >(); appDomain.DelegateManager.RegisterMethodDelegate <object, MessageArgs <ILTypeInstance> >(); //appDomain.DelegateManager.RegisterDelegateConvertor<TestDelegateMethod>((action) => //{ // //转换器的目的是把Action或者Func转换成正确的类型,这里则是把Action<int>转换成TestDelegateMethod // return new TestDelegateMethod((a) => // { // //调用委托实例 // ((Action<int>)action)(a); // }); //}); //appDomain.DelegateManager.RegisterDelegateConvertor<TestDelegateFunction>((action) => //{ // return new TestDelegateFunction((a) => // { // return ((Func<int, string>)action)(a); // }); //}); appDomain.DelegateManager.RegisterDelegateConvertor <UnityEngine.Events.UnityAction <float> >((action) => { return(new UnityEngine.Events.UnityAction <float>((a) => { ((Action <float>)action)(a); })); }); #endregion #region CLRBinding //ILRuntime.Runtime.Generated.CLRBindings.Initialize(appDomain); #endregion #region Adaptor appDomain.RegisterCrossBindingAdaptor(new ViewModelBaseAdapter()); appDomain.RegisterCrossBindingAdaptor(new UnityGuiViewAdapter()); appDomain.RegisterCrossBindingAdaptor(new ModuleBaseAdapter()); appDomain.RegisterCrossBindingAdaptor(new ComponentAdapter()); #endregion appDomain.RegisterValueTypeBinder(typeof(Vector3), new Vector3Binder()); #region UniRX appDomain.DelegateManager.RegisterMethodDelegate <Exception>(); appDomain.DelegateManager.RegisterMethodDelegate <UniRx.Unit>(); #endregion }
public unsafe static void Register(ILRuntime.Runtime.Enviorment.AppDomain appdomain) { #if DEBUG && (UNITY_EDITOR || UNITY_ANDROID || UNITY_IPHONE) appdomain.UnityMainThreadID = System.Threading.Thread.CurrentThread.ManagedThreadId; #endif // 注册litjson LitJson.JsonMapper.RegisterILRuntimeCLRRedirection(appdomain); appdomain.RegisterCrossBindingAdaptor(new MonoBehaviourAdapter()); appdomain.RegisterCrossBindingAdaptor(new CoroutineAdapter()); appdomain.RegisterCrossBindingAdaptor(new IAsyncStateMachineClassInheritanceAdaptor()); //添加值绑定 appdomain.RegisterValueTypeBinder(typeof(Vector3), new Vector3Binder()); appdomain.RegisterValueTypeBinder(typeof(Quaternion), new QuaternionBinder()); appdomain.RegisterValueTypeBinder(typeof(Vector2), new Vector2Binder()); //Log 重定向 为了显示行号 var mi = typeof(HFLog).GetMethod("L", new System.Type[] { typeof(object) }); appdomain.RegisterCLRMethodRedirection(mi, L); mi = typeof(HFLog).GetMethod("C", new System.Type[] { typeof(object), typeof(LogColor) }); appdomain.RegisterCLRMethodRedirection(mi, C); mi = typeof(HFLog).GetMethod("E", new System.Type[] { typeof(object) }); appdomain.RegisterCLRMethodRedirection(mi, E); //==============================如果将委托实例传出给ILRuntime外部使用============================================= appdomain.DelegateManager.RegisterMethodDelegate <int>(); appdomain.DelegateManager.RegisterMethodDelegate <int, MemoryStream>(); appdomain.DelegateManager.RegisterMethodDelegate <Scene, LoadSceneMode>(); appdomain.DelegateManager.RegisterMethodDelegate <int, object>(); appdomain.DelegateManager.RegisterMethodDelegate <GameObject>(); appdomain.DelegateManager.RegisterMethodDelegate <bool>(); appdomain.DelegateManager.RegisterMethodDelegate <GameObject[]>(); appdomain.DelegateManager.RegisterMethodDelegate <UnityEngine.Object[]>(); appdomain.DelegateManager.RegisterMethodDelegate <Sprite[]>(); appdomain.DelegateManager.RegisterMethodDelegate <BaseEventData>(); appdomain.DelegateManager.RegisterMethodDelegate <float>(); appdomain.DelegateManager.RegisterMethodDelegate <Dictionary <string, string> >(); appdomain.DelegateManager.RegisterMethodDelegate <string>(); appdomain.DelegateManager.RegisterMethodDelegate <NotificationMessage>(); appdomain.DelegateManager.RegisterMethodDelegate <AssetPackage>(); appdomain.DelegateManager.RegisterFunctionDelegate <GameObject>(); appdomain.DelegateManager.RegisterMethodDelegate <System.Int32, System.Byte[]>(); //===========================委托转换器(DelegateConvertor)================================================ // 如果你需要将一个不是Action或者Func类型的委托实例传到ILRuntime外部使用的话, // 除了委托适配器,还需要额外写一个转换器,将Action和Func转换成你真正需要的那个委托类型 appdomain.DelegateManager.RegisterDelegateConvertor <UnityAction>((action) => { return(new UnityAction(() => { ((Action)action)(); })); }); appdomain.DelegateManager.RegisterDelegateConvertor <UnityAction <bool> >((action) => { return(new UnityAction <bool>((a) => { ((Action <bool>)action)(a); })); }); appdomain.DelegateManager.RegisterDelegateConvertor <UnityAction <string> >((action) => { return(new UnityAction <string>((a) => { ((Action <string>)action)(a); })); }); appdomain.DelegateManager.RegisterDelegateConvertor <UnityAction <float> >((action) => { return(new UnityAction <float>((a) => { ((Action <float>)action)(a); })); }); appdomain.DelegateManager.RegisterDelegateConvertor <UnityAction <Scene, LoadSceneMode> >((action) => { return(new UnityAction <Scene, LoadSceneMode>((s, l) => { ((Action <Scene, LoadSceneMode>)action)(s, l); })); }); appdomain.DelegateManager.RegisterDelegateConvertor <TweenCallback>((action) => { return(new TweenCallback(() => { ((Action)action)(); })); }); appdomain.DelegateManager.RegisterDelegateConvertor <UnityAction <BaseEventData> >((action) => { return(new UnityAction <BaseEventData>((p) => { ((Action <BaseEventData>)action)(p); })); }); }
//跨域继承绑定适配器 public static void RegisterCrossBindingAdaptor(ILRuntime.Runtime.Enviorment.AppDomain appdomain) { appdomain.RegisterCrossBindingAdaptor(new CoroutineAdapter()); }
private static void Internal_HandleBeforeGenCodeByAssemblies(ILAppDomain domain) { domain.RegisterCrossBindingAdaptor(new IAsyncStateMachineClassInheritanceAdaptor()); }
private void ILHotfixInitialize() { _appDomain.RegisterCrossBindingAdaptor(new ILHotfixProcedureAdapter()); }
/// <summary> /// 注册跨域继承适配器 /// </summary> /// <param name="appDomain">AppDomain</param> public static void Register(ILRuntimeDomain appDomain) { appDomain.RegisterCrossBindingAdaptor(new AdapterIDebug()); appDomain.RegisterCrossBindingAdaptor(new AdapterIHotfixEntry()); }
/// <summary> /// Initialize the CLR binding, please invoke this AFTER CLR Redirection registration /// </summary> public static void Initialize(ILRuntime.Runtime.Enviorment.AppDomain app) { app.RegisterCrossBindingAdaptor(new IEnumerableAdapter()); app.RegisterCrossBindingAdaptor(new DataLookILRObjectAdapter()); app.RegisterCrossBindingAdaptor(new GameEventAdapter()); app.RegisterCrossBindingAdaptor(new LogicILRObjectAdapter()); app.RegisterCrossBindingAdaptor(new TableAdapter()); app.RegisterCrossBindingAdaptor(new UIControllerILRObjectAdapter()); app.RegisterCrossBindingAdaptor(new IComparer_1_StringAdapter()); app.RegisterCrossBindingAdaptor(new IComparer_1_ILTypeInstanceAdapter()); app.RegisterCrossBindingAdaptor(new IComparer_1_DynamicMonoILRObjectAdaptor_Binding_AdaptorAdapter()); app.RegisterCrossBindingAdaptor(new IComparer_1_KeyValuePair_2_ILRuntime_Runtime_GeneratedAdapter_IComparable_1_ILTypeInstanceAdapter_Binding_Adapter_ILTypeInstanceAdapter()); app.RegisterCrossBindingAdaptor(new IComparableAdapter()); app.RegisterCrossBindingAdaptor(new IComparable_1_ILTypeInstanceAdapter()); app.RegisterCrossBindingAdaptor(new IEqualityComparer_1_ILRuntime_Runtime_GeneratedAdapter_IComparableAdapter_Binding_AdapterAdapter()); app.RegisterCrossBindingAdaptor(new IEqualityComparerAdapter()); app.RegisterCrossBindingAdaptor(new IEqualityComparer_1_ILTypeInstanceAdapter()); app.RegisterCrossBindingAdaptor(new IEqualityComparer_1_Int32Adapter()); app.RegisterCrossBindingAdaptor(new IEqualityComparer_1_ILRuntime_Runtime_GeneratedAdapter_IComparable_1_ILTypeInstanceAdapter_Binding_AdapterAdapter()); }
protected static void InitILRuntime(ILRuntime.Runtime.Enviorment.AppDomain domain) { //这里需要注册所有热更DLL中用到的跨域继承Adapter,否则无法正确抓取引用 domain.RegisterCrossBindingAdaptor(new MonoBehaviourAdapter()); }
// manual register public static void Init(ILRuntime.Runtime.Enviorment.AppDomain app) { if (app == null) { // should log error return; } // adaptor register app.RegisterCrossBindingAdaptor(new ClassInheritanceTestAdaptor()); app.RegisterCrossBindingAdaptor(new InterfaceTestAdaptor()); app.RegisterCrossBindingAdaptor(new TestClass2Adaptor()); app.RegisterCrossBindingAdaptor(new TestClass3Adaptor()); app.RegisterCrossBindingAdaptor(new TestClass4Adaptor()); app.RegisterCrossBindingAdaptor(new IDisposableClassInheritanceAdaptor()); app.RegisterCrossBindingAdaptor(new ClassInheritanceTest2Adaptor()); app.RegisterCrossBindingAdaptor(new IAsyncStateMachineClassInheritanceAdaptor()); // value type register app.RegisterValueTypeBinder(typeof(TestVector3), new TestVector3Binder()); app.RegisterValueTypeBinder(typeof(TestVectorStruct), new TestVectorStructBinder()); app.RegisterValueTypeBinder(typeof(TestVectorStruct2), new TestVectorStruct2Binder()); // delegate register app.DelegateManager.RegisterFunctionDelegate <System.Int32, System.Boolean>(); app.DelegateManager.RegisterMethodDelegate <System.Int32>(); app.DelegateManager.RegisterFunctionDelegate <System.Int32, System.Int32>(); app.DelegateManager.RegisterMethodDelegate <System.Int32, System.String, System.String>(); app.DelegateManager.RegisterMethodDelegate <ILRuntimeTest.TestFramework.BaseClassTest>(); app.DelegateManager.RegisterFunctionDelegate <System.Int32>(); app.DelegateManager.RegisterFunctionDelegate <System.Int32, System.Single, System.Int16, System.Double>(); app.DelegateManager.RegisterFunctionDelegate <ILRuntime.Runtime.Intepreter.ILTypeInstance, System.Boolean>(); // delegate convertor app.DelegateManager.RegisterDelegateConvertor <System.Predicate <ILRuntime.Runtime.Intepreter.ILTypeInstance> >((act) => { return(new System.Predicate <ILRuntime.Runtime.Intepreter.ILTypeInstance>((obj) => { return ((Func <ILRuntime.Runtime.Intepreter.ILTypeInstance, System.Boolean>)act)(obj); })); }); app.DelegateManager.RegisterDelegateConvertor <ILRuntimeTest.TestFramework.IntDelegate>((action) => { return(new ILRuntimeTest.TestFramework.IntDelegate((a) => { ((Action <Int32>)action)(a); })); }); app.DelegateManager.RegisterDelegateConvertor <ILRuntimeTest.TestFramework.Int2Delegate>((action) => { return(new ILRuntimeTest.TestFramework.Int2Delegate((a, b) => { ((Action <Int32, Int32>)action)(a, b); })); }); app.DelegateManager.RegisterDelegateConvertor <ILRuntimeTest.TestFramework.InitFloat>((action) => { return(new ILRuntimeTest.TestFramework.InitFloat((a, b) => { ((Action <Int32, Single>)action)(a, b); })); }); app.DelegateManager.RegisterDelegateConvertor <ILRuntimeTest.TestFramework.IntDelegate2>((action) => { return(new ILRuntimeTest.TestFramework.IntDelegate2((a) => { return ((Func <Int32, Int32>)action)(a); })); }); app.DelegateManager.RegisterDelegateConvertor <ILRuntimeTest.TestFramework.Int2Delegate2>((action) => { return(new ILRuntimeTest.TestFramework.Int2Delegate2((a, b) => { return ((Func <Int32, Int32, Boolean>)action)(a, b); })); }); app.DelegateManager.RegisterDelegateConvertor <ILRuntimeTest.TestFramework.IntFloatDelegate2>((action) => { return(new ILRuntimeTest.TestFramework.IntFloatDelegate2((a, b) => { return ((Func <Int32, Single, String>)action)(a, b); })); }); // LitJson register LitJson.JsonMapper.RegisterILRuntimeCLRRedirection(app); }
private static void GenerateCLRBindingByAnalysis() { //用新的分析热更dll调用引用来生成绑定代码 ILRuntime.Runtime.Enviorment.AppDomain domain = new ILRuntime.Runtime.Enviorment.AppDomain(); using (System.IO.FileStream fs = new System.IO.FileStream("Assets/UpdatableLogic/HotFix/HotFix.dll.bytes", System.IO.FileMode.Open, System.IO.FileAccess.Read)) { domain.LoadAssembly(fs); //Crossbind Adapter is needed to generate the correct binding code domain.RegisterCrossBindingAdaptor(new Dictionary_2_Object_ObjectAdapter()); domain.RegisterCrossBindingAdaptor(new ExceptionAdapter()); domain.RegisterCrossBindingAdaptor(new HashSet_1_ObjectAdapter()); domain.RegisterCrossBindingAdaptor(new IEnumerable_1_ILTypeInstanceAdapter()); domain.RegisterCrossBindingAdaptor(new IEnumerable_1_ObjectAdapter()); domain.RegisterCrossBindingAdaptor(new IEnumerator_1_ILTypeInstanceAdapter()); domain.RegisterCrossBindingAdaptor(new IEnumerator_1_ObjectAdapter()); domain.RegisterCrossBindingAdaptor(new LinkedList_1_ObjectAdapter()); domain.RegisterCrossBindingAdaptor(new List_1_ObjectAdapter()); domain.RegisterCrossBindingAdaptor(new Queue_1_ObjectAdapter()); domain.RegisterCrossBindingAdaptor(new Stack_1_ObjectAdapter()); ILRuntime.Runtime.CLRBinding.BindingCodeGenerator.GenerateBindingCode( domain, "Assets/ILRuntime/Generated"); } AssetDatabase.Refresh(); }
// manual register public static void Init(ILRuntime.Runtime.Enviorment.AppDomain app) { if (app == null) { // should log error return; } ILRuntime.Runtime.Enviorment.PrimitiveConverter <ILRuntimeTest.TestFramework.TestCLREnum> .ToInteger = (a) => (int)a; ILRuntime.Runtime.Enviorment.PrimitiveConverter <ILRuntimeTest.TestFramework.TestCLREnum> .FromInteger = (a) => (ILRuntimeTest.TestFramework.TestCLREnum)a; // adaptor register app.RegisterCrossBindingAdaptor(new ClassInheritanceTestAdaptor()); app.RegisterCrossBindingAdaptor(new InterfaceTestAdaptor()); app.RegisterCrossBindingAdaptor(new TestClass2Adapter()); app.RegisterCrossBindingAdaptor(new TestClass3Adaptor()); app.RegisterCrossBindingAdaptor(new TestClass4Adaptor()); app.RegisterCrossBindingAdaptor(new IDisposableAdapter()); app.RegisterCrossBindingAdaptor(new ClassInheritanceTest2Adaptor()); app.RegisterCrossBindingAdaptor(new IAsyncStateMachineClassInheritanceAdaptor()); // value type register app.RegisterValueTypeBinder(typeof(TestVector3), new TestVector3Binder()); app.RegisterValueTypeBinder(typeof(TestVectorStruct), new TestVectorStructBinder()); app.RegisterValueTypeBinder(typeof(TestVectorStruct2), new TestVectorStruct2Binder()); app.RegisterValueTypeBinder(typeof(System.Collections.Generic.KeyValuePair <uint, ILRuntime.Runtime.Intepreter.ILTypeInstance>), new KeyValuePairUInt32ILTypeInstanceBinder()); // delegate register app.DelegateManager.RegisterFunctionDelegate <System.Int32, System.Boolean>(); app.DelegateManager.RegisterMethodDelegate <System.Int32>(); app.DelegateManager.RegisterFunctionDelegate <System.Int32, System.Int32>(); app.DelegateManager.RegisterMethodDelegate <System.Int32, System.String, System.String>(); app.DelegateManager.RegisterMethodDelegate <ILRuntimeTest.TestFramework.BaseClassTest>(); app.DelegateManager.RegisterFunctionDelegate <System.Int32>(); app.DelegateManager.RegisterFunctionDelegate <System.Collections.Generic.KeyValuePair <System.Int32, System.Collections.Generic.List <System.Int32> >, System.Collections.Generic.IEnumerable <System.Int32> >(); app.DelegateManager.RegisterFunctionDelegate <System.Int32, System.Single, System.Int16, System.Double>(); app.DelegateManager.RegisterFunctionDelegate <ILRuntime.Runtime.Intepreter.ILTypeInstance, System.Boolean>(); app.DelegateManager.RegisterMethodDelegate <ILRuntimeTest.TestFramework.TestCLREnum>(); app.DelegateManager.RegisterFunctionDelegate <ILRuntimeTest.TestFramework.TestCLREnum>(); app.DelegateManager.RegisterFunctionDelegate <System.Threading.Tasks.Task <System.Collections.Generic.List <System.String> > >(); app.DelegateManager.RegisterFunctionDelegate <System.Byte, System.Boolean>(); app.DelegateManager.RegisterFunctionDelegate <System.Byte, System.Byte>(); app.DelegateManager.RegisterFunctionDelegate <System.Linq.IGrouping <System.Byte, System.Byte>, ILRuntime.Runtime.Intepreter.ILTypeInstance>(); app.DelegateManager.RegisterFunctionDelegate <ILRuntime.Runtime.Intepreter.ILTypeInstance, System.Int32>(); app.DelegateManager.RegisterFunctionDelegate <ILRuntimeTest.TestFramework.TestVector3, System.Single>(); app.DelegateManager.RegisterMethodDelegate <ILRuntimeTest.TestFramework.TestVector3>(); // delegate convertor app.DelegateManager.RegisterDelegateConvertor <ILRuntimeTest.TestFramework.TestValueTypeDelegate>((act) => { return(new ILRuntimeTest.TestFramework.TestValueTypeDelegate((vec) => { ((Action <ILRuntimeTest.TestFramework.TestVector3>)act)(vec); })); }); app.DelegateManager.RegisterDelegateConvertor <System.Predicate <ILRuntime.Runtime.Intepreter.ILTypeInstance> >((act) => { return(new System.Predicate <ILRuntime.Runtime.Intepreter.ILTypeInstance>((obj) => { return ((Func <ILRuntime.Runtime.Intepreter.ILTypeInstance, System.Boolean>)act)(obj); })); }); app.DelegateManager.RegisterDelegateConvertor <ILRuntimeTest.TestFramework.IntDelegate>((action) => { return(new ILRuntimeTest.TestFramework.IntDelegate((a) => { ((Action <Int32>)action)(a); })); }); app.DelegateManager.RegisterDelegateConvertor <ILRuntimeTest.TestFramework.Int2Delegate>((action) => { return(new ILRuntimeTest.TestFramework.Int2Delegate((a, b) => { ((Action <Int32, Int32>)action)(a, b); })); }); app.DelegateManager.RegisterDelegateConvertor <ILRuntimeTest.TestFramework.InitFloat>((action) => { return(new ILRuntimeTest.TestFramework.InitFloat((a, b) => { ((Action <Int32, Single>)action)(a, b); })); }); app.DelegateManager.RegisterDelegateConvertor <ILRuntimeTest.TestFramework.IntDelegate2>((action) => { return(new ILRuntimeTest.TestFramework.IntDelegate2((a) => { return ((Func <Int32, Int32>)action)(a); })); }); app.DelegateManager.RegisterDelegateConvertor <ILRuntimeTest.TestFramework.Int2Delegate2>((action) => { return(new ILRuntimeTest.TestFramework.Int2Delegate2((a, b) => { return ((Func <Int32, Int32, Boolean>)action)(a, b); })); }); app.DelegateManager.RegisterDelegateConvertor <ILRuntimeTest.TestFramework.IntFloatDelegate2>((action) => { return(new ILRuntimeTest.TestFramework.IntFloatDelegate2((a, b) => { return ((Func <Int32, Single, String>)action)(a, b); })); }); app.DelegateManager.RegisterDelegateConvertor <ILRuntimeTest.TestFramework.BindableProperty <System.Int64> .onChangeWithOldVal>((act) => { return(new ILRuntimeTest.TestFramework.BindableProperty <System.Int64> .onChangeWithOldVal((oldVal, newVal) => { ((Action <System.Int64, System.Int64>)act)(oldVal, newVal); })); }); // LitJson register LitJson.JsonMapper.RegisterILRuntimeCLRRedirection(app); app.DelegateManager.RegisterMethodDelegate <System.Object>(); app.DelegateManager.RegisterMethodDelegate <ILRuntimeTest.TestBase.ExtensionClass, System.Object>(); app.DelegateManager.RegisterMethodDelegate <System.Exception>(); app.DelegateManager.RegisterMethodDelegate <ILRuntimeTest.TestBase.ExtensionClass, System.Exception>(); app.DelegateManager.RegisterMethodDelegate <ILRuntimeTest.TestBase.ExtensionClass, System.ArgumentException>(); app.DelegateManager.RegisterMethodDelegate <System.Exception>(); app.DelegateManager.RegisterMethodDelegate <ILRuntimeTest.TestBase.ExtensionClass <System.Int32>, System.Exception>(); app.DelegateManager.RegisterMethodDelegate <System.ArgumentException>(); app.DelegateManager.RegisterMethodDelegate <ILRuntime.Runtime.Intepreter.ILTypeInstance>(); app.DelegateManager.RegisterMethodDelegate <ILRuntimeTest.TestBase.ExtensionClass <System.Int32>, System.ArgumentException>(); app.DelegateManager.RegisterMethodDelegate <ILRuntimeTest.TestBase.ExtensionClass>(); app.DelegateManager.RegisterMethodDelegate <System.Int64, System.Int64>(); app.DelegateManager.RegisterFunctionDelegate <ILRuntimeTest.TestBase.ExtensionClass, System.Int32>(); app.DelegateManager.RegisterFunctionDelegate <System.Threading.Tasks.Task>(); app.DelegateManager.RegisterFunctionDelegate <ILRuntimeTest.TestBase.ExtensionClass, System.Threading.Tasks.Task>(); app.DelegateManager.RegisterFunctionDelegate <System.Threading.Tasks.Task <System.Int32> >(); app.DelegateManager.RegisterFunctionDelegate <ILRuntimeTest.TestBase.ExtensionClass, System.Threading.Tasks.Task <System.Int32> >(); app.Prewarm("TestCases.AsyncAwaitTest", false); //app.Prewarm("ILRuntime.Runtime.Enviorment.CrossBindingAdaptorType"); }
public void GenerateByAssemblies_InitILRuntime(ILRuntime.Runtime.Enviorment.AppDomain appdomain) { //注册跨域 appdomain.RegisterCrossBindingAdaptor(new StageControllerBaseAdapter()); }