少年修仙传客户端基础资源
lwb
2021-01-26 f6ab248e23fb6485f4121294ff4167e8a15a47a3
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
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;
    }
 
}