public void OpenUnit<T>(T unitPanel) where T : UIUnitPanel, IUIControlHost
{
foreach(var unit in _OpenedPanelList)
{
if(unit.TryGetComponent(out IUIControlHost host))
host.OnLossControl();
CloseUnit(unit);
}
unitPanel.OnEnabled();
unitPanel.OnGainControl();
_OpenedPanelList.Add(unitPanel);
}
public class UIUnitPanelWithControl : UIUnitPanel, IUIControlHost{}
public void OpenUnit<T>(T unitPanel) where T : UIUnitPanel
{
foreach(var unit in _OpenedPanelList)
{
if(unit is UIUnitPanelWithControl)
unit.OnLossControl();
CloseUnit(unit);
}
unitPanel.OnEnabled();
unitPanel.OnGainControl();
_OpenedPanelList.Add(unitPanel);
}
UI ํ๋ ์์ํฌ์ ๋ฌธ์ ์์ด๊ฐ์ง๊ณ ์๋ณด๋ ์ค์ธ๋ฐ
์๋ ์๋๋ ๋น์ฉ์ฐจ์ด ์๋? ๊ทธ๋ฅ ๋จ์ํ ์ทจํฅ ์ฐจ์ธ๊ฐ
_OpenedPanelList ์๋ฃํ์ List<UIUnitPanel> ์
ํ๋กํ์ผ๋ฌ๋์๊ฒ ๋ฌป๋๊ฒ ๋ง์ง๋ง ์๋ง ์๋๊ฐ ๋ ๋น ๋ฅผ๋ป?
๋ก์ฐ๋ ๋ฒจ๊น์ง ๋ด๋ ค๊ฐ์ ์ฐพ์์ผ๋ ์ ๋๋ฉด ๊ทธ๋ฅ ๋ง์ ๋๋๊ฑฐ ์จ๋ ๋๊ฒ ๋ค ๋ ๋ค ๋ฑํ ์๊ด ์๋๊ฑฐ์ง?
์ฐจ์ด์ ์ด ์ด๋ป๊ฒ ๊ฐ์ ธ์ค๋๋๋ฐ์ ์์ผ๋ ์๊ด์์๋ป ใ ใ
์ต์ ํ๊ฐ ๋ญ์ง๋ ๋ชจ๋ฅด๋๋๋ค์ด๋ ์ด๋์ ์ด์ํ๊ฑฐ ๋ณด๊ณ ์์ ์๋ํฐ ๋ธ์น๋ฉด์ TryGetcomponent์ฐ๋ผํ์ง TryGetcomponent๊ฐ ๋๋ฆฌ๋ฉด ๋๋ฆฌ์ง ๋ ๋น ๋ฅผ ์ด์ ๊ฐ ์์...์ ์ด์ ๊ทธ๊ฒ ๋ ๋นจ๋์ผ๋ฉด ์ ๋ํฐ ๋ด๋ถ์์ ์บ์คํ ์ ํด์ฃผ๊ฒ ์ง
TryGetComponent will attempt to retrieve the component of the given type. The notable difference compared to GameObject.GetComponent is that this method does not allocate in the Editor when the requested component does not exist. ์ค ์ง์ง๋ค? API์ ๊ทธ๋ ๊ฒ ์ ํ์๋ค ์ง์์ด ๋์๋ค