少年修仙传客户端基础资源
dabaoji
2023-11-13 0a23e1b83f8fda8ab9f9e32fe71c26c431faf63a
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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
using ILRuntime.CLR.Method;
using ILRuntime.Runtime.Enviorment;
using ILRuntime.Runtime.Intepreter;
using Snxxz.UI;
using UnityEngine;
 
/// <summary>
/// 热更工程使用一级窗口的基础代理类
/// </summary>
public class ILOneLevelWindowProxy : OneLevelWin
{
 
    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["ILOneLevelWindow"];
        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);
    }
 
    public void CloseAllChildWindow()
    {
        CloseSubWindows();
    }
 
    protected override void OnActived()
    {
        base.OnActived();
        if (onActived != null)
            appDomain.Invoke(onActived, obj);
    }
 
    protected override void LateUpdate()
    {
        base.LateUpdate();
        if (lateUpdate != null)
            appDomain.Invoke(lateUpdate, obj);
    }
 
    protected override void BindController()
    {
        base.BindController();
        Init();
        if (bindController != null)
            appDomain.Invoke(bindController, obj);
    }
    protected override void AddListeners()
    {
        base.AddListeners();
        if (addListeners != null)
            appDomain.Invoke(addListeners, obj);
    }
    protected override void OnPreOpen()
    {
        base.OnPreOpen();
        if (onPreOpen != null)
            appDomain.Invoke(onPreOpen, obj);
    }
    protected override void OnAfterOpen()
    {
        base.OnAfterOpen();
        if (onAfterOpen != null)
            appDomain.Invoke(onAfterOpen, obj);
    }
    protected override void OnPreClose()
    {
        base.OnPreClose();
        if (onPreClose != null)
            appDomain.Invoke(onPreClose, obj);
    }
    protected override void OnAfterClose()
    {
        base.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;
    }
 
 
}