using ILRuntime.CLR.Method;
|
using ILRuntime.Runtime.Enviorment;
|
using ILRuntime.Runtime.Intepreter;
|
using Snxxz.UI;
|
using UnityEngine;
|
|
public class ILWindow : Window
|
{
|
ILTypeInstance obj;
|
|
IMethod bindController, addListeners, onPreOpen, onAfterOpen, onPreClose, onAfterClose, onDestroy, lateUpdate, onActived;
|
|
AppDomain appDomain
|
{
|
get { return ILRuntimeUtility.Instance.appDomain; }
|
}
|
private void Init()
|
{
|
//使用与预制同名的代码文件
|
var windowName = string.Format("{0}.{1}", ILRuntimeUtility.NameSpace, gameObject.name);
|
obj = appDomain.Instantiate(windowName, new object[] { this });
|
if (obj == null)
|
{
|
DebugEx.LogErrorFormat("ILWindow 热更代码不存在:{0}", windowName);
|
return;
|
}
|
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");
|
}
|
|
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);
|
bindController = null;
|
addListeners = null;
|
onPreOpen = null;
|
onAfterOpen = null;
|
onPreClose = null;
|
onAfterClose = null;
|
onDestroy = null;
|
lateUpdate = null;
|
onActived = null;
|
obj = null;
|
}
|
|
}
|