using vnxbqy.UI;
|
using System;
|
using System.Reflection;
|
using UnityEngine;
|
|
/// <summary>
|
/// 热更工程使用window的基础代理类
|
/// </summary>
|
public class ILWindowProxy : Window
|
{
|
public object prefabScript;
|
private void Init()
|
{
|
InitWidgts();
|
//使用与预制同名的代码文件
|
var windowName = gameObject.name;
|
Type prefabType = GetTypeFromAllAssemblies(windowName);
|
if (prefabType != null)
|
{
|
prefabScript = Activator.CreateInstance(prefabType);
|
ILWindow.SetProxy(windowName, this);
|
}
|
}
|
|
protected override void OnActived()
|
{
|
if (prefabScript == null)
|
return;
|
InvokeMethodIfExists(prefabScript, "OnActived");
|
}
|
|
protected override void LateUpdate()
|
{
|
if (prefabScript == null)
|
return;
|
InvokeMethodIfExists(prefabScript, "LateUpdate");
|
}
|
|
protected override void BindController()
|
{
|
Init();
|
if (prefabScript == null)
|
return;
|
InvokeMethodIfExists(prefabScript, "BindController");
|
}
|
protected override void AddListeners()
|
{
|
if (prefabScript == null)
|
return;
|
InvokeMethodIfExists(prefabScript, "AddListeners");
|
}
|
protected override void OnPreOpen()
|
{
|
if (prefabScript == null)
|
return;
|
InvokeMethodIfExists(prefabScript, "OnPreOpen");
|
}
|
protected override void OnAfterOpen()
|
{
|
if (prefabScript == null)
|
return;
|
InvokeMethodIfExists(prefabScript, "OnAfterOpen");
|
}
|
protected override void OnPreClose()
|
{
|
if (prefabScript == null)
|
return;
|
InvokeMethodIfExists(prefabScript, "OnPreClose");
|
}
|
protected override void OnAfterClose()
|
{
|
if (prefabScript == null)
|
return;
|
InvokeMethodIfExists(prefabScript, "OnAfterClose");
|
}
|
|
private void OnDestroy()
|
{
|
if (prefabScript == null)
|
return;
|
InvokeMethodIfExists(prefabScript, "OnDestroy");
|
}
|
|
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;
|
}
|
}
|