3030// ==========================================================================================
3131
3232using System ;
33- using System . Collections . Generic ;
3433using GameFrameX . Runtime ;
3534
3635namespace GameFrameX . UI . Runtime
@@ -58,12 +57,6 @@ public event EventHandler<CloseUIFormCompleteEventArgs> CloseUIFormComplete
5857 /// <param name="isDispose">是否销毁释放</param>
5958 protected abstract void RecycleUIForm ( IUIForm uiForm , bool isDispose = false ) ;
6059
61- /// <summary>
62- /// 回收界面实例对象到实例池。
63- /// </summary>
64- /// <param name="uiForm">要回收的界面实例对象。</param>
65- protected abstract void RecycleToPoolUIForm ( IUIForm uiForm ) ;
66-
6760 /// <summary>
6861 /// 关闭界面。
6962 /// </summary>
@@ -85,7 +78,8 @@ public void CloseUIForm(int serialId, object userData, bool isNowRecycle = false
8578 var uiForm = GetUIForm ( serialId ) ;
8679 if ( uiForm == null )
8780 {
88- throw new GameFrameworkException ( Utility . Text . Format ( "Can not find UI form '{0}'." , serialId ) ) ;
81+ Log . Error ( Utility . Text . Format ( "Can not find UI form '{0}'." , serialId ) ) ;
82+ return ;
8983 }
9084
9185 CloseUIForm ( uiForm , userData , isNowRecycle ) ;
@@ -137,6 +131,13 @@ public void CloseUIForm<T>(object userData, bool isNowRecycle = false) where T :
137131 public void CloseUIForm ( IUIForm uiForm , object userData , bool isNowRecycle = false )
138132 {
139133 GameFrameworkGuard . NotNull ( uiForm , nameof ( uiForm ) ) ;
134+ var serialId = uiForm . SerialId ;
135+ if ( IsLoadingUIForm ( serialId ) )
136+ {
137+ m_UIFormsToReleaseOnLoad . Add ( serialId ) ;
138+ m_UIFormsBeingLoaded . Remove ( serialId ) ;
139+ return ;
140+ }
140141
141142 if ( uiForm . IsDisableClosing )
142143 {
@@ -145,44 +146,28 @@ public void CloseUIForm(IUIForm uiForm, object userData, bool isNowRecycle = fal
145146
146147 GameFrameworkGuard . NotNull ( uiForm . UIGroup , nameof ( uiForm . UIGroup ) ) ;
147148 var uiGroup = ( UIGroup ) uiForm . UIGroup ;
148- var serialId = uiForm . SerialId ;
149+
149150 if ( uiForm . EnableHideAnimation )
150151 {
151152 uiGroup . RemoveUIForm ( uiForm , true ) ;
152153 uiForm . Hide ( m_UIFormHideHandler , ( ) =>
153154 {
154155 uiForm . OnClose ( m_IsShutdown , userData ) ;
155156 uiGroup . Refresh ( ) ;
157+ if ( isNowRecycle )
158+ {
159+ RecycleUIForm ( uiForm , true ) ;
160+ }
156161 } ) ;
157162 }
158163 else
159164 {
160165 uiGroup . RemoveUIForm ( uiForm ) ;
161166 uiForm . OnClose ( m_IsShutdown , userData ) ;
162167 uiGroup . Refresh ( ) ;
163- }
164-
165- if ( IsLoadingUIForm ( serialId ) )
166- {
167- m_UIFormsToReleaseOnLoad [ serialId ] = uiForm ;
168- m_UIFormsBeingLoaded . Remove ( serialId ) ;
169- }
170-
171- // 回收界面实例对象
172- if ( ! uiForm . IsDisableRecycling )
173- {
174168 if ( isNowRecycle )
175169 {
176- // 立即回收界面实例对象到实例池。
177- RecycleToPoolUIForm ( uiForm ) ;
178170 RecycleUIForm ( uiForm , true ) ;
179- m_UIFormsToReleaseOnLoad . Remove ( serialId ) ;
180- }
181- else
182- {
183- // 界面实例对象未立即回收,需要在实例池回收时间点回收。
184- m_UIFormsToReleaseOnLoad [ serialId ] = uiForm ;
185- RecycleToPoolUIForm ( uiForm ) ;
186171 }
187172 }
188173
@@ -191,6 +176,20 @@ public void CloseUIForm(IUIForm uiForm, object userData, bool isNowRecycle = fal
191176 var closeUIFormCompleteEventArgs = CloseUIFormCompleteEventArgs . Create ( uiForm . SerialId , uiForm . UIFormAssetName , uiGroup , userData ) ;
192177 m_CloseUIFormCompleteEventHandler ( this , closeUIFormCompleteEventArgs ) ;
193178 }
179+
180+ // 判断是否禁用了界面的回收
181+ if ( uiForm . IsDisableRecycling )
182+ {
183+ return ;
184+ }
185+
186+ // 判断是否立即回收界面
187+ if ( isNowRecycle )
188+ {
189+ return ;
190+ }
191+
192+ m_RecycleQueue . Enqueue ( uiForm ) ;
194193 }
195194
196195 /// <summary>
@@ -228,7 +227,7 @@ public void CloseAllLoadingUIForms()
228227 {
229228 foreach ( var uiFormBeingLoaded in m_UIFormsBeingLoaded )
230229 {
231- m_UIFormsToReleaseOnLoad [ uiFormBeingLoaded . Key ] = GetUIForm ( uiFormBeingLoaded . Key ) ;
230+ m_UIFormsToReleaseOnLoad . Add ( uiFormBeingLoaded . Key ) ;
232231 }
233232
234233 m_UIFormsBeingLoaded . Clear ( ) ;
@@ -241,9 +240,9 @@ public void CloseAllLoadingUIForms()
241240 /// <param name="isNowRecycle">是否立即回收界面,默认是否</param>
242241 public void ReleaseAllLoadedUIForms ( bool isNowRecycle = false , object userData = null )
243242 {
244- foreach ( var keyValuePair in m_UIFormsToReleaseOnLoad )
243+ foreach ( var id in m_UIFormsToReleaseOnLoad )
245244 {
246- var uiForm = keyValuePair . Value ;
245+ var uiForm = GetUIForm ( id ) ;
247246 if ( uiForm != null )
248247 {
249248 RecycleUIForm ( uiForm , isNowRecycle ) ;
0 commit comments