using ILRuntime.CLR.Method; using ILRuntime.Runtime.Enviorment; using ILRuntime.Runtime.Intepreter; using Snxxz.UI; using UnityEngine; /// /// 热更工程使用window的基础代理类 /// public class ILWindowProxy : Window { ILTypeInstance obj; IMethod bindController, addListeners, onPreOpen, onAfterOpen, onPreClose, onAfterClose, onDestroy, lateUpdate, onActived; IMethod dipose; AppDomain appDomain { get { return ILLauncherProxy.Instance.appDomain; } } private void Init() { InitWidgts(); //使用与预制同名的代码文件 var windowName =gameObject.name; var baseType = appDomain.LoadedTypes["ILWindow"]; obj = appDomain.Instantiate(windowName); if (obj == null) { DebugEx.LogErrorFormat("ILWindow 热更代码不存在:{0}", windowName); return; } var setProxy = baseType.GetMethod("SetProxy", 1); appDomain.Invoke(setProxy, obj, this);//将当前代理对象传过去 //此处用type获取的方法,子类不定义是不会执行Logic工程父类的方法 var type = obj.Type; bindController = type.GetMethod("BindController"); addListeners = type.GetMethod("AddListeners"); onPreOpen = type.GetMethod("OnPreOpen"); onAfterOpen = type.GetMethod("OnAfterOpen"); onPreClose = type.GetMethod("OnPreClose"); onAfterClose = type.GetMethod("OnAfterClose"); onDestroy = type.GetMethod("OnDestroy"); lateUpdate = type.GetMethod("LateUpdate"); onActived = type.GetMethod("OnActived"); //baseType 获取的方法,才会执行父类Logic工程的父类方法,但同时也不会调用子类重写的方法 dipose = baseType.GetMethod("Dipose", 0); } protected override void OnActived() { if (onActived != null) appDomain.Invoke(onActived, obj); } protected override void LateUpdate() { if (lateUpdate != null) appDomain.Invoke(lateUpdate, obj); } protected override void BindController() { Init(); if (bindController != null) appDomain.Invoke(bindController, obj); } protected override void AddListeners() { if (addListeners != null) appDomain.Invoke(addListeners, obj); } protected override void OnPreOpen() { if (onPreOpen != null) appDomain.Invoke(onPreOpen, obj); } protected override void OnAfterOpen() { if (onAfterOpen != null) appDomain.Invoke(onAfterOpen, obj); } protected override void OnPreClose() { if (onPreClose != null) appDomain.Invoke(onPreClose, obj); } protected override void OnAfterClose() { if (onAfterClose != null) appDomain.Invoke(onAfterClose, obj); } private void OnDestroy() { if (onDestroy != null) appDomain?.Invoke(onDestroy, obj); if (dipose != null) appDomain?.Invoke(dipose, obj); bindController = null; addListeners = null; onPreOpen = null; onAfterOpen = null; onPreClose = null; onAfterClose = null; onDestroy = null; lateUpdate = null; onActived = null; obj = null; } }