using vnxbqy.UI; using System; using System.Reflection; /// /// 热更工程使用一级窗口的基础代理类 /// public class ILOneLevelWindowProxy : OneLevelWin { public object prefabScript; private void Init() { InitWidgts(); var windowName = gameObject.name; Type prefabType = GetTypeFromAllAssemblies(windowName); if (prefabType != null) { prefabScript = Activator.CreateInstance(prefabType); } ILOneLevelWindow.SetProxy(this); } public void CloseAllChildWindow() { CloseSubWindows(); } protected override void OnActived() { base.OnActived(); if (prefabScript == null) return; InvokeMethodIfExists(prefabScript, "OnActived"); } protected override void LateUpdate() { base.LateUpdate(); if (prefabScript == null) return; InvokeMethodIfExists(prefabScript, "LateUpdate"); } protected override void BindController() { base.BindController(); Init(); if (prefabScript == null) return; InvokeMethodIfExists(prefabScript, "BindController"); } protected override void AddListeners() { base.AddListeners(); if (prefabScript == null) return; InvokeMethodIfExists(prefabScript, "AddListeners"); } protected override void OnPreOpen() { base.OnPreOpen(); if (prefabScript == null) return; InvokeMethodIfExists(prefabScript, "OnPreOpen"); } protected override void OnAfterOpen() { base.OnAfterOpen(); if (prefabScript == null) return; InvokeMethodIfExists(prefabScript, "OnAfterOpen"); } protected override void OnPreClose() { base.OnPreClose(); if (prefabScript == null) return; InvokeMethodIfExists(prefabScript, "OnPreClose"); } protected override void OnAfterClose() { base.OnAfterClose(); if (prefabScript == null) return; InvokeMethodIfExists(prefabScript, "OnAfterClose"); } private void OnDestroy() { if (prefabScript == null) return; InvokeMethodIfExists(prefabScript, "OnDestroy"); InvokeMethodIfExists(prefabScript, "Dipose"); } private void InvokeMethodIfExists(object instance, string methodName) { if (instance == null) return; MethodInfo method = instance.GetType().GetMethod(methodName, BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance); if (method != null) method.Invoke(instance, null); } Type GetTypeFromAllAssemblies(string typeName) { foreach (var assembly in AppDomain.CurrentDomain.GetAssemblies()) { var type = assembly.GetType(typeName); if (type != null) return type; } return null; } }