@@ -15,14 +15,29 @@ namespace GameFrameX.Core.Hotfix;
1515/// </summary>
1616public static class HotfixManager
1717{
18+ /// <summary>
19+ /// 标识是否正在进行热更新操作
20+ /// </summary>
1821 internal static volatile bool DoingHotfix ;
1922
23+ /// <summary>
24+ /// 当前使用的热更新模块
25+ /// </summary>
2026 private static volatile HotfixModule _module ;
2127
28+ /// <summary>
29+ /// 基础配置信息
30+ /// </summary>
2231 private static AppSetting _baseSetting ;
2332
33+ /// <summary>
34+ /// 存储旧的热更新模块的映射表,用于处理热更新过渡期间的请求
35+ /// </summary>
2436 private static readonly ConcurrentDictionary < int , HotfixModule > OldModuleMap = new ( ) ;
2537
38+ /// <summary>
39+ /// 空的事件监听器列表,用于在找不到监听器时返回
40+ /// </summary>
2641 private static readonly List < IEventListener > EmptyListenerList = new ( ) ;
2742
2843 /// <summary>
@@ -34,18 +49,18 @@ public static Assembly HotfixAssembly
3449 }
3550
3651 /// <summary>
37- /// 重载时间
52+ /// 最近一次热更新重载的时间
3853 /// </summary>
3954 public static DateTime ReloadTime { get ; private set ; }
4055
4156 /// <summary>
4257 /// 加载热更新模块
4358 /// </summary>
44- /// <param name="setting"></param>
59+ /// <param name="setting">应用程序配置 </param>
4560 /// <param name="dllPath">热更新程序集路径,默认为hotfix</param>
4661 /// <param name="hotfixDllName">热更新程序集名称</param>
4762 /// <param name="dllVersion">Dll版本.当不为空的时候会优先加载指定的Dll.替换 dllPath 参数</param>
48- /// <returns>返回是否成功 </returns>
63+ /// <returns>返回是否加载成功 </returns>
4964 public static async Task < bool > LoadHotfixModule ( AppSetting setting , string dllVersion = "" , string dllPath = "hotfix" , string hotfixDllName = "GameFrameX.Hotfix.dll" )
5065 {
5166 dllPath . CheckNotNullOrEmptyOrWhiteSpace ( nameof ( dllPath ) ) ;
@@ -68,6 +83,13 @@ public static async Task<bool> LoadHotfixModule(AppSetting setting, string dllVe
6883 return await Load ( hotfixModule , _baseSetting , reload ) ;
6984 }
7085
86+ /// <summary>
87+ /// 加载新的热更新模块
88+ /// </summary>
89+ /// <param name="newModule">新的热更新模块</param>
90+ /// <param name="setting">应用程序配置</param>
91+ /// <param name="reload">是否为重新加载</param>
92+ /// <returns>返回加载是否成功</returns>
7193 private static async Task < bool > Load ( HotfixModule newModule , AppSetting setting , bool reload )
7294 {
7395 ReloadTime = DateTime . Now ;
@@ -77,6 +99,7 @@ private static async Task<bool> Load(HotfixModule newModule, AppSetting setting,
7799 DoingHotfix = true ;
78100 var oldModuleHash = oldModule . GetHashCode ( ) ;
79101 OldModuleMap . TryAdd ( oldModuleHash , oldModule ) ;
102+ // 延迟3分钟后清理旧模块
80103 _ = Task . Run ( async ( ) =>
81104 {
82105 await Task . Delay ( 1000 * 60 * 3 ) ;
@@ -96,7 +119,7 @@ private static async Task<bool> Load(HotfixModule newModule, AppSetting setting,
96119 }
97120
98121 /// <summary>
99- /// 停止
122+ /// 停止热更新模块
100123 /// </summary>
101124 /// <param name="message">停止原因</param>
102125 /// <returns></returns>
@@ -105,23 +128,29 @@ public static Task Stop(string message = "")
105128 return _module ? . HotfixBridge ? . Stop ( message ) ?? Task . CompletedTask ;
106129 }
107130
131+ /// <summary>
132+ /// 获取组件对应的代理类型
133+ /// </summary>
108134 internal static Type GetAgentType ( Type compType )
109135 {
110136 return _module . GetAgentType ( compType ) ;
111137 }
112138
139+ /// <summary>
140+ /// 获取代理对应的组件类型
141+ /// </summary>
113142 internal static Type GetCompType ( Type agentType )
114143 {
115144 return _module . GetComponentType ( agentType ) ;
116145 }
117146
118147 /// <summary>
119- /// 获取代理
148+ /// 获取组件的代理实例
120149 /// </summary>
121- /// <param name="component"></param>
122- /// <param name="refAssemblyType"></param>
123- /// <typeparam name="T"></typeparam>
124- /// <returns></returns>
150+ /// <param name="component">组件实例 </param>
151+ /// <param name="refAssemblyType">引用程序集类型 </param>
152+ /// <typeparam name="T">代理类型 </typeparam>
153+ /// <returns>返回代理实例 </returns>
125154 public static T GetAgent < T > ( BaseComponent component , Type refAssemblyType ) where T : IComponentAgent
126155 {
127156 if ( ! OldModuleMap . IsEmpty )
@@ -144,8 +173,8 @@ public static T GetAgent<T>(BaseComponent component, Type refAssemblyType) where
144173 /// <summary>
145174 /// 获取TCP消息处理器
146175 /// </summary>
147- /// <param name="msgId"></param>
148- /// <returns></returns>
176+ /// <param name="msgId">消息ID </param>
177+ /// <returns>返回对应的消息处理器 </returns>
149178 public static BaseMessageHandler GetTcpHandler ( int msgId )
150179 {
151180 return _module . GetTcpHandler ( msgId ) ;
@@ -154,37 +183,51 @@ public static BaseMessageHandler GetTcpHandler(int msgId)
154183 /// <summary>
155184 /// 获取HTTP消息处理器
156185 /// </summary>
157- /// <param name="cmd"></param>
158- /// <returns></returns>
186+ /// <param name="cmd">HTTP命令 </param>
187+ /// <returns>返回对应的HTTP处理器 </returns>
159188 public static BaseHttpHandler GetHttpHandler ( string cmd )
160189 {
161190 return _module . GetHttpHandler ( cmd ) ;
162191 }
163192
164193 /// <summary>
165- /// 获取HTTP消息处理器
194+ /// 获取所有HTTP消息处理器列表
166195 /// </summary>
167- /// <returns></returns>
196+ /// <returns>返回HTTP处理器列表 </returns>
168197 public static List < BaseHttpHandler > GetListHttpHandler ( )
169198 {
170199 return _module . GetListHttpHandler ( ) ;
171200 }
172201
173202 /// <summary>
174- /// 获取事件监听器列表
203+ /// 获取指定Actor类型和事件ID的事件监听器列表
175204 /// </summary>
176- /// <param name="actorType"></param>
177- /// <param name="evtId"></param>
178- /// <returns></returns>
179- public static List < IEventListener > FindListeners ( ushort actorType , int evtId )
205+ /// <param name="actorType">Actor类型</param>
206+ /// <param name="eventId">事件ID</param>
207+ /// <returns>返回监听器列表,如果没有则返回空列表</returns>
208+ public static List < IEventListener > FindListeners ( ushort actorType , int eventId )
209+ {
210+ return _module . FindListeners ( actorType , eventId ) ?? EmptyListenerList ;
211+ }
212+
213+ /// <summary>
214+ /// 获取指定事件ID的事件监听器列表
215+ /// </summary>
216+ /// <param name="eventId">事件ID</param>
217+ /// <returns>返回监听器列表,如果没有则返回空列表</returns>
218+ public static List < IEventListener > FindListeners ( int eventId )
180219 {
181- return _module . FindListeners ( actorType , evtId ) ?? EmptyListenerList ;
220+ return _module . FindListeners ( eventId ) ?? EmptyListenerList ;
182221 }
183222
184223 /// <summary>
185- /// 获取实例
186- /// 主要用于获取Event,Timer, Schedule,的Handler实例
224+ /// 获取指定类型的实例
225+ /// 主要用于获取Event,Timer, Schedule的Handler实例
187226 /// </summary>
227+ /// <typeparam name="T">实例类型</typeparam>
228+ /// <param name="typeName">类型名称</param>
229+ /// <param name="refAssemblyType">引用程序集类型</param>
230+ /// <returns>返回指定类型的实例,如果类型名称为空则返回默认值</returns>
188231 public static T GetInstance < T > ( string typeName , Type refAssemblyType = null )
189232 {
190233 if ( string . IsNullOrEmpty ( typeName ) )
0 commit comments