77
88using System ;
99using System . Collections . Generic ;
10- using System . IO ;
11- using System . Threading . Tasks ;
12- using Cysharp . Threading . Tasks ;
1310using FairyGUI ;
14- using GameFrameX . Asset . Runtime ;
15- using GameFrameX . ObjectPool ;
1611using GameFrameX . Runtime ;
1712using GameFrameX . UI . Runtime ;
1813using UnityEngine ;
@@ -24,22 +19,12 @@ namespace GameFrameX.UI.FairyGUI.Runtime
2419 /// </summary>
2520 internal sealed partial class UIManager
2621 {
27- private EventHandler < CloseUIFormCompleteEventArgs > m_CloseUIFormCompleteEventHandler ;
28-
29- /// <summary>
30- /// 关闭界面完成事件。
31- /// </summary>
32- public event EventHandler < CloseUIFormCompleteEventArgs > CloseUIFormComplete
33- {
34- add { m_CloseUIFormCompleteEventHandler += value ; }
35- remove { m_CloseUIFormCompleteEventHandler -= value ; }
36- }
37-
3822 /// <summary>
3923 /// 回收界面实例对象。
4024 /// </summary>
4125 /// <param name="uiForm"></param>
42- private void RecycleUIForm ( IUIForm uiForm )
26+ /// <param name="isDispose">是否销毁释放</param>
27+ protected override void RecycleUIForm ( IUIForm uiForm , bool isDispose = false )
4328 {
4429 uiForm . OnRecycle ( ) ;
4530 var formHandle = uiForm . Handle as GameObject ;
@@ -50,256 +35,17 @@ private void RecycleUIForm(IUIForm uiForm)
5035 {
5136 if ( displayObjectInfo . displayObject . gOwner is GComponent component )
5237 {
53- m_InstancePool . Unspawn ( component ) ;
38+ if ( isDispose )
39+ {
40+ component . Dispose ( ) ;
41+ }
42+ else
43+ {
44+ m_InstancePool . Unspawn ( component ) ;
45+ }
5446 }
5547 }
5648 }
5749 }
58-
59- /// <summary>
60- /// 回收界面实例对象。
61- /// </summary>
62- /// <param name="uiForm"></param>
63- private void RecycleUIFormNow ( IUIForm uiForm )
64- {
65- uiForm . OnRecycle ( ) ;
66- var formHandle = uiForm . Handle as GameObject ;
67- if ( formHandle )
68- {
69- var displayObjectInfo = formHandle . GetComponent < DisplayObjectInfo > ( ) ;
70- if ( displayObjectInfo )
71- {
72- if ( displayObjectInfo . displayObject . gOwner is GComponent component )
73- {
74- component . Dispose ( ) ;
75- // m_InstancePool.Unspawn(component);
76- }
77- }
78- }
79- }
80-
81- /// <summary>
82- /// 关闭界面。
83- /// </summary>
84- /// <param name="serialId">要关闭界面的序列编号。</param>
85- public void CloseUIForm ( int serialId )
86- {
87- CloseUIForm ( serialId , null ) ;
88- }
89-
90- /// <summary>
91- /// 关闭界面。
92- /// </summary>
93- /// <param name="serialId">要关闭界面的序列编号。</param>
94- /// <param name="userData">用户自定义数据。</param>
95- public void CloseUIForm ( int serialId , object userData )
96- {
97- if ( IsLoadingUIForm ( serialId ) )
98- {
99- m_UIFormsToReleaseOnLoad . Add ( serialId ) ;
100- m_UIFormsBeingLoaded . Remove ( serialId ) ;
101- return ;
102- }
103-
104- IUIForm uiForm = GetUIForm ( serialId ) ;
105- if ( uiForm == null )
106- {
107- throw new GameFrameworkException ( Utility . Text . Format ( "Can not find UI form '{0}'." , serialId ) ) ;
108- }
109-
110- CloseUIForm ( uiForm , userData ) ;
111- }
112-
113- /// <summary>
114- /// 关闭界面。
115- /// </summary>
116- /// <param name="uiForm">要关闭的界面。</param>
117- public void CloseUIForm ( IUIForm uiForm )
118- {
119- CloseUIForm ( uiForm , null ) ;
120- }
121-
122- /// <summary>
123- /// 关闭界面。
124- /// </summary>
125- /// <param name="userData">用户自定义数据。</param>
126- /// <typeparam name="T"></typeparam>
127- public void CloseUIForm < T > ( object userData ) where T : IUIForm
128- {
129- var fullName = typeof ( T ) . FullName ;
130- IUIForm [ ] uiForms = GetAllLoadedUIForms ( ) ;
131- foreach ( IUIForm uiForm in uiForms )
132- {
133- if ( uiForm . FullName != fullName )
134- {
135- continue ;
136- }
137-
138- if ( ! HasUIFormFullName ( uiForm . FullName ) )
139- {
140- continue ;
141- }
142-
143- CloseUIForm ( uiForm , userData ) ;
144- break ;
145- }
146- }
147-
148- /// <summary>
149- /// 关闭界面。
150- /// </summary>
151- /// <param name="uiForm">要关闭的界面。</param>
152- /// <param name="userData">用户自定义数据。</param>
153- public void CloseUIForm ( IUIForm uiForm , object userData )
154- {
155- GameFrameworkGuard . NotNull ( uiForm , nameof ( uiForm ) ) ;
156- GameFrameworkGuard . NotNull ( uiForm . UIGroup , nameof ( uiForm . UIGroup ) ) ;
157- UIGroup uiGroup = ( UIGroup ) uiForm . UIGroup ;
158-
159- uiGroup . RemoveUIForm ( uiForm ) ;
160- uiForm . OnClose ( m_IsShutdown , userData ) ;
161- uiGroup . Refresh ( ) ;
162-
163- if ( m_CloseUIFormCompleteEventHandler != null )
164- {
165- CloseUIFormCompleteEventArgs closeUIFormCompleteEventArgs = CloseUIFormCompleteEventArgs . Create ( uiForm . SerialId , uiForm . UIFormAssetName , uiGroup , userData ) ;
166- m_CloseUIFormCompleteEventHandler ( this , closeUIFormCompleteEventArgs ) ;
167- // ReferencePool.Release(closeUIFormCompleteEventArgs);
168- }
169-
170- m_RecycleQueue . Enqueue ( uiForm ) ;
171- }
172-
173-
174- /// <summary>
175- /// 关闭界面。
176- /// </summary>
177- /// <param name="serialId">要关闭界面的序列编号。</param>
178- public void CloseUIFormNow ( int serialId )
179- {
180- CloseUIFormNow ( serialId , null ) ;
181- }
182-
183- /// <summary>
184- /// 关闭界面。
185- /// </summary>
186- /// <param name="serialId">要关闭界面的序列编号。</param>
187- /// <param name="userData">用户自定义数据。</param>
188- public void CloseUIFormNow ( int serialId , object userData )
189- {
190- if ( IsLoadingUIForm ( serialId ) )
191- {
192- m_UIFormsToReleaseOnLoad . Add ( serialId ) ;
193- m_UIFormsBeingLoaded . Remove ( serialId ) ;
194- return ;
195- }
196-
197- IUIForm uiForm = GetUIForm ( serialId ) ;
198- if ( uiForm == null )
199- {
200- throw new GameFrameworkException ( Utility . Text . Format ( "Can not find UI form '{0}'." , serialId ) ) ;
201- }
202-
203- CloseUIFormNow ( uiForm , userData ) ;
204- }
205-
206- /// <summary>
207- /// 关闭界面。
208- /// </summary>
209- /// <param name="uiForm">要关闭的界面。</param>
210- public void CloseUIFormNow ( IUIForm uiForm )
211- {
212- CloseUIFormNow ( uiForm , null ) ;
213- }
214-
215- /// <summary>
216- /// 关闭界面。
217- /// </summary>
218- /// <param name="userData">用户自定义数据。</param>
219- /// <typeparam name="T"></typeparam>
220- public void CloseUIFormNow < T > ( object userData ) where T : IUIForm
221- {
222- var fullName = typeof ( T ) . FullName ;
223- IUIForm [ ] uiForms = GetAllLoadedUIForms ( ) ;
224- foreach ( IUIForm uiForm in uiForms )
225- {
226- if ( uiForm . FullName != fullName )
227- {
228- continue ;
229- }
230-
231- if ( ! HasUIFormFullName ( uiForm . FullName ) )
232- {
233- continue ;
234- }
235-
236- CloseUIFormNow ( uiForm , userData ) ;
237- break ;
238- }
239- }
240-
241- /// <summary>
242- /// 关闭界面。
243- /// </summary>
244- /// <param name="uiForm">要关闭的界面。</param>
245- /// <param name="userData">用户自定义数据。</param>
246- public void CloseUIFormNow ( IUIForm uiForm , object userData )
247- {
248- GameFrameworkGuard . NotNull ( uiForm , nameof ( uiForm ) ) ;
249- GameFrameworkGuard . NotNull ( uiForm . UIGroup , nameof ( uiForm . UIGroup ) ) ;
250- UIGroup uiGroup = ( UIGroup ) uiForm . UIGroup ;
251-
252- uiGroup . RemoveUIForm ( uiForm ) ;
253- uiForm . OnClose ( m_IsShutdown , userData ) ;
254- uiGroup . Refresh ( ) ;
255-
256- if ( m_CloseUIFormCompleteEventHandler != null )
257- {
258- CloseUIFormCompleteEventArgs closeUIFormCompleteEventArgs = CloseUIFormCompleteEventArgs . Create ( uiForm . SerialId , uiForm . UIFormAssetName , uiGroup , userData ) ;
259- m_CloseUIFormCompleteEventHandler ( this , closeUIFormCompleteEventArgs ) ;
260- // ReferencePool.Release(closeUIFormCompleteEventArgs);
261- }
262-
263- RecycleUIFormNow ( uiForm ) ;
264- }
265-
266- /// <summary>
267- /// 关闭所有已加载的界面。
268- /// </summary>
269- public void CloseAllLoadedUIForms ( )
270- {
271- CloseAllLoadedUIForms ( null ) ;
272- }
273-
274- /// <summary>
275- /// 关闭所有已加载的界面。
276- /// </summary>
277- /// <param name="userData">用户自定义数据。</param>
278- public void CloseAllLoadedUIForms ( object userData )
279- {
280- IUIForm [ ] uiForms = GetAllLoadedUIForms ( ) ;
281- foreach ( IUIForm uiForm in uiForms )
282- {
283- if ( ! HasUIForm ( uiForm . SerialId ) )
284- {
285- continue ;
286- }
287-
288- CloseUIForm ( uiForm , userData ) ;
289- }
290- }
291-
292- /// <summary>
293- /// 关闭所有正在加载的界面。
294- /// </summary>
295- public void CloseAllLoadingUIForms ( )
296- {
297- foreach ( KeyValuePair < int , string > uiFormBeingLoaded in m_UIFormsBeingLoaded )
298- {
299- m_UIFormsToReleaseOnLoad . Add ( uiFormBeingLoaded . Key ) ;
300- }
301-
302- m_UIFormsBeingLoaded . Clear ( ) ;
303- }
30450 }
30551}
0 commit comments