Skip to content

Commit fcf7f7b

Browse files
committed
refactor(UIManager): 优化界面关闭和回收逻辑
- 将原有的嵌套条件判断重构为早期返回模式,提高代码可读性 - 分离界面回收逻辑到独立方法 RecycleToPoolUIForm - 添加更清晰的注释说明方法用途 GameFrameX/GameFrameX.Unity#35
1 parent f9a11b6 commit fcf7f7b

1 file changed

Lines changed: 42 additions & 16 deletions

File tree

Runtime/UIManager.Close.cs

Lines changed: 42 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -49,23 +49,49 @@ protected override void RecycleUIForm(IUIForm uiForm, bool isDispose = false)
4949
{
5050
uiForm.OnRecycle();
5151
var formHandle = uiForm.Handle as GameObject;
52-
if (formHandle)
52+
if (!formHandle)
5353
{
54-
var displayObjectInfo = formHandle.GetComponent<DisplayObjectInfo>();
55-
if (displayObjectInfo)
56-
{
57-
if (displayObjectInfo.displayObject.gOwner is GComponent component)
58-
{
59-
if (isDispose)
60-
{
61-
component.Dispose();
62-
}
63-
else
64-
{
65-
m_InstancePool.Unspawn(component);
66-
}
67-
}
68-
}
54+
return;
55+
}
56+
57+
var displayObjectInfo = formHandle.GetComponent<DisplayObjectInfo>();
58+
if (!displayObjectInfo)
59+
{
60+
return;
61+
}
62+
63+
if (displayObjectInfo.displayObject.gOwner is not GComponent component)
64+
{
65+
return;
66+
}
67+
68+
if (isDispose)
69+
{
70+
component.Dispose();
71+
}
72+
}
73+
74+
/// <summary>
75+
/// 回收界面实例对象到实例池。
76+
/// </summary>
77+
/// <param name="uiForm">要回收的界面实例对象。</param>
78+
protected override void RecycleToPoolUIForm(IUIForm uiForm)
79+
{
80+
var formHandle = uiForm.Handle as GameObject;
81+
if (!formHandle)
82+
{
83+
return;
84+
}
85+
86+
var displayObjectInfo = formHandle.GetComponent<DisplayObjectInfo>();
87+
if (!displayObjectInfo)
88+
{
89+
return;
90+
}
91+
92+
if (displayObjectInfo.displayObject.gOwner is GComponent component)
93+
{
94+
m_InstancePool.Unspawn(component);
6995
}
7096
}
7197
}

0 commit comments

Comments
 (0)