少年修仙传客户端代码仓库
hch
2025-06-12 204ef05a831c9484e2abc561d27ecbff7c797453
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
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;
    }
}