Skip to content

Commit 92811a2

Browse files
committed
[修改]1. 修改代码分离
1 parent 104631b commit 92811a2

9 files changed

+1031
-887
lines changed

Runtime/UIManager.Close.cs

Lines changed: 305 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,305 @@
1+
//------------------------------------------------------------
2+
// Game Framework
3+
// Copyright © 2013-2021 Jiang Yin. All rights reserved.
4+
// Homepage: https://gameframework.cn/
5+
// Feedback: mailto:[email protected]
6+
//------------------------------------------------------------
7+
8+
using System;
9+
using System.Collections.Generic;
10+
using System.IO;
11+
using System.Threading.Tasks;
12+
using Cysharp.Threading.Tasks;
13+
using FairyGUI;
14+
using GameFrameX.Asset.Runtime;
15+
using GameFrameX.ObjectPool;
16+
using GameFrameX.Runtime;
17+
using GameFrameX.UI.Runtime;
18+
using UnityEngine;
19+
20+
namespace GameFrameX.UI.FairyGUI.Runtime
21+
{
22+
/// <summary>
23+
/// 界面管理器。
24+
/// </summary>
25+
internal sealed partial class UIManager
26+
{
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+
38+
/// <summary>
39+
/// 回收界面实例对象。
40+
/// </summary>
41+
/// <param name="uiForm"></param>
42+
private void RecycleUIForm(IUIForm uiForm)
43+
{
44+
uiForm.OnRecycle();
45+
var formHandle = uiForm.Handle as GameObject;
46+
if (formHandle)
47+
{
48+
var displayObjectInfo = formHandle.GetComponent<DisplayObjectInfo>();
49+
if (displayObjectInfo)
50+
{
51+
if (displayObjectInfo.displayObject.gOwner is GComponent component)
52+
{
53+
m_InstancePool.Unspawn(component);
54+
}
55+
}
56+
}
57+
}
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+
}
304+
}
305+
}

Runtime/UIManager.Close.cs.meta

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)