少年修仙传客户端代码仓库
hch
1 天以前 600733c8f592cb9e65f2b7a3e110ac1d686e6bfe
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
131
132
133
134
135
136
using vnxbqy.UI;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using UnityEngine;
 
/// <summary>
/// 扩展函数,主要为调用泛型方式做性能优化
/// </summary>
public static class ILExtension
{
 
    #region 主项目相关
    public static T GetWidgtEx<T>(this WidgetBehavior mono, string name) where T : Component
    {
        var cp = mono.GetWidgt(typeof(T), name);
        return (T)cp;
    }
 
    //不能在preopen中调用,会是null
    public static T GetILBehaviour<T>(this Component cp) where T : ILBehaviour
    {
        return cp.gameObject.GetILBehaviour<T>();
    }
 
    public static T GetILBehaviour<T>(this GameObject go) where T : ILBehaviour
    {
        var proxy = go.GetComponentEx<ILBehaviourProxy>();
        if (proxy == null)
            return default(T);
        var type = typeof(T);
        var bh = proxy.GetILBehaviour(type.FullName);
        if (bh == null || !type.IsInstanceOfType(bh))
            return default(T);
        return (T)bh;
    }
 
    public static T GetModelEx<T>(this ModelCenter center) where T : Model
    {
        var model = center.GetModel(typeof(T));
        return (T)model;
    }
 
    public static T GetEx<T>(this WindowCenter center) where T : Window
    {
        var win = center.Get(typeof(T).Name);
        return (T)win;
    }
 
    public static void OpenFromLocalEx<T>(this WindowCenter center) where T : Window
    {
        center.OpenFromLocal(typeof(T).Name);
    }
 
    public static void OpenEx<T>(this WindowCenter center, bool forceSync = false, int functionOrder = 0) where T : Window
    {
        center.Open(typeof(T).Name, forceSync, functionOrder);
    }
 
    public static void OpenIL<T>(this WindowCenter center, bool forceSync = false, int functionOrder = 0) where T : ILWindow
    {
        center.Open(typeof(T).Name, forceSync, functionOrder);
    }
 
    public static void CloseIL<T>(this WindowCenter center) where T : ILWindow
    {
        center.Close(typeof(T).Name);
    }
 
    public static void CloseEx<T>(this WindowCenter center) where T : Window
    {
        center.Close(typeof(T).Name);
    }
 
    public static bool IsOpenEx<T>(this WindowCenter center) where T : Window
    {
        return center.IsOpen(typeof(T).Name);
    }
 
    #endregion
 
    #region Unity 相关
 
    public static T GetComponentEx<T>(this Component component) where T : Component
    {
        var cp = component.GetComponent(typeof(T));
        return (T)cp;
    }
 
    public static T AddComponentEx<T>(this GameObject go) where T : Component
    {
        var cp = go.AddComponent(typeof(T));
        return (T)cp;
    }
 
    public static T GetComponentEx<T>(this GameObject go) where T : Component
    {
        var cp = go.GetComponent(typeof(T));
        return (T)cp;
    }
 
    public static T GetComponentInParentEx<T>(this Component component) where T : Component
    {
        var cp = component.GetComponentInParent(typeof(T));
        return (T)cp;
    }
 
    public static T GetComponentInParentEx<T>(this GameObject go) where T : Component
    {
        var cp = go.GetComponentInParent(typeof(T));
        return (T)cp;
    }
 
    public static T FindComponentEx<T>(this Component cp, string path) where T : Component
    {
        var child = cp.transform.Find(path);
        var childCp = child.GetComponentEx<T>();
        return (T)childCp;
    }
 
    //效果同c#底层的ComponentExtersion SetActive
    public static void SetActiveIL(this Component cp, bool state)
    {
        if (cp == null) return;
 
        if (cp.gameObject.activeSelf != state)
        {
            cp.gameObject.SetActive(state);
        }
    }
 
    #endregion
 
}