주석추가
This commit is contained in:
@@ -217,6 +217,9 @@ namespace UVC.UI.Toolbar.View
|
||||
RenderToolbar();
|
||||
}
|
||||
|
||||
// 현재 열린 하위 메뉴의 원인 제공자(확장 버튼 모델) 추적용
|
||||
protected ToolbarExpandableButton _ownerOfCurrentSubMenu;
|
||||
|
||||
/// <summary>
|
||||
/// 현재 툴바에 표시된 모든 UI 요소들을 제거하고, 관련된 이벤트 구독을 해제합니다.
|
||||
/// _modelToGameObjectMap, _toggleGroups를 비우고, 열려있는 하위 메뉴(currentSubMenu)도 파괴합니다.
|
||||
@@ -236,6 +239,22 @@ namespace UVC.UI.Toolbar.View
|
||||
}
|
||||
if (pair.Value != null) // UI GameObject 파괴
|
||||
{
|
||||
// UI 컴포넌트의 이벤트 리스너 명시적 해제
|
||||
// ToggleButton 또는 RadioButton의 경우 Toggle 컴포넌트 리스너 해제
|
||||
Toggle toggleComponent = pair.Value.GetComponent<Toggle>();
|
||||
if (toggleComponent != null)
|
||||
{
|
||||
toggleComponent.onValueChanged.RemoveAllListeners();
|
||||
}
|
||||
|
||||
// StandardButton 또는 ExpandableButton의 경우 Button 컴포넌트 리스너 해제
|
||||
// (필요에 따라 다른 버튼 타입의 리스너도 유사하게 처리)
|
||||
Button buttonComponent = pair.Value.GetComponent<Button>();
|
||||
if (buttonComponent != null)
|
||||
{
|
||||
buttonComponent.onClick.RemoveAllListeners();
|
||||
}
|
||||
|
||||
TooltipHandler handler = pair.Value.GetComponent<TooltipHandler>();
|
||||
if (handler != null) // 툴팁 핸들러 이벤트도 정리 (필요시)
|
||||
{
|
||||
@@ -259,8 +278,7 @@ namespace UVC.UI.Toolbar.View
|
||||
|
||||
if (currentSubMenu != null) // 열려있는 하위 메뉴 파괴
|
||||
{
|
||||
Destroy(currentSubMenu);
|
||||
currentSubMenu = null;
|
||||
DestroyCurrentSubMenuAndClearListeners(); // 헬퍼 메서드 사용
|
||||
}
|
||||
|
||||
if (TooltipManager.Instance != null && TooltipManager.Instance.IsInitialized) // 툴팁 숨기기
|
||||
@@ -479,6 +497,41 @@ namespace UVC.UI.Toolbar.View
|
||||
return group;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 현재 열려있는 하위 메뉴(currentSubMenu)의 자식 UI 요소들의 이벤트 리스너를 제거하고,
|
||||
/// 하위 메뉴 GameObject를 파괴한 후 currentSubMenu 참조를 null로 설정합니다.
|
||||
/// </summary>
|
||||
protected void DestroyCurrentSubMenuAndClearListeners()
|
||||
{
|
||||
if (currentSubMenu == null) return;
|
||||
|
||||
// currentSubMenu의 자식들을 순회하며 Button 리스너 제거
|
||||
Button[] subButtons = currentSubMenu.GetComponentsInChildren<Button>(true);
|
||||
foreach (Button btn in subButtons)
|
||||
{
|
||||
btn.onClick.RemoveAllListeners();
|
||||
}
|
||||
|
||||
// currentSubMenu의 자식들을 순회하며 Toggle 리스너 제거
|
||||
Toggle[] subToggles = currentSubMenu.GetComponentsInChildren<Toggle>(true);
|
||||
foreach (Toggle tgl in subToggles)
|
||||
{
|
||||
tgl.onValueChanged.RemoveAllListeners();
|
||||
}
|
||||
|
||||
// currentSubMenu의 자식들에 있는 TooltipHandler 정리 (필요시)
|
||||
TooltipHandler[] subTooltipHandlers = currentSubMenu.GetComponentsInChildren<TooltipHandler>(true);
|
||||
foreach (TooltipHandler handler in subTooltipHandlers)
|
||||
{
|
||||
handler.OnPointerEnterAction = null;
|
||||
handler.OnPointerExitAction = null;
|
||||
}
|
||||
|
||||
Destroy(currentSubMenu);
|
||||
currentSubMenu = null;
|
||||
_ownerOfCurrentSubMenu = null; // 하위 메뉴 소유자 참조도 초기화
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 현재 열려있는 하위 메뉴 UI GameObject입니다. 없으면 null입니다.
|
||||
/// </summary>
|
||||
@@ -493,11 +546,16 @@ namespace UVC.UI.Toolbar.View
|
||||
/// <param name="expandableButtonObj">주 확장 버튼의 UI GameObject로, 하위 메뉴 위치 결정에 사용됩니다.</param>
|
||||
internal void ToggleSubMenu(ToolbarExpandableButton expandableButtonModel, GameObject expandableButtonObj)
|
||||
{
|
||||
bool closeOnly = false;
|
||||
// 이미 다른 하위 메뉴가 열려있거나, 현재 클릭한 버튼의 하위 메뉴가 열려있다면 닫습니다.
|
||||
if (currentSubMenu != null)
|
||||
{
|
||||
Destroy(currentSubMenu);
|
||||
currentSubMenu = null;
|
||||
// 현재 열린 하위 메뉴가 지금 클릭한 확장 버튼에 의해 열린 것인지 확인
|
||||
if (_ownerOfCurrentSubMenu == expandableButtonModel)
|
||||
{
|
||||
closeOnly = true; // 같은 버튼을 다시 클릭했으므로 닫기만 함
|
||||
}
|
||||
DestroyCurrentSubMenuAndClearListeners(); // 기존 하위 메뉴 정리 (리스너 포함)
|
||||
// 만약 현재 클릭한 버튼의 하위 메뉴가 이미 열려있어서 닫는 경우라면, 여기서 함수 종료
|
||||
// (다시 열리지 않도록). 이 로직은 currentSubMenu가 어떤 버튼에 의해 열렸는지 알아야 함.
|
||||
// 간단하게는, 어떤 확장 버튼이든 클릭하면 기존 서브메뉴는 닫고, 필요하면 새로 연다.
|
||||
@@ -514,6 +572,11 @@ namespace UVC.UI.Toolbar.View
|
||||
// 지금은 닫고, 아래에서 다시 열 수 있게 함.
|
||||
}
|
||||
|
||||
if (closeOnly)
|
||||
{
|
||||
return; // 닫기만 하고 새로운 메뉴를 열지 않음
|
||||
}
|
||||
|
||||
// 새 하위 메뉴를 열 조건 확인 (닫혀 있었고, 프리팹과 하위 버튼이 있는 경우)
|
||||
if (subMenuPanelPrefab == null)
|
||||
{
|
||||
@@ -530,6 +593,7 @@ namespace UVC.UI.Toolbar.View
|
||||
// 생성 위치는 일단 ToolbarView의 자식으로 하고, 이후 위치 조정
|
||||
currentSubMenu = Instantiate(subMenuPanelPrefab, transform);
|
||||
currentSubMenu.name = $"SubMenu_{expandableButtonModel.Text}";
|
||||
_ownerOfCurrentSubMenu = expandableButtonModel; // 새 하위 메뉴의 소유자 설정
|
||||
|
||||
RectTransform panelRect = currentSubMenu.GetComponent<RectTransform>();
|
||||
if (panelRect == null)
|
||||
@@ -710,8 +774,7 @@ namespace UVC.UI.Toolbar.View
|
||||
if (!RectTransformUtility.RectangleContainsScreenPoint(subMenuRect, Input.mousePosition, eventCamera))
|
||||
{
|
||||
// 하위 메뉴 영역 바깥을 클릭한 경우, 하위 메뉴를 닫습니다.
|
||||
Destroy(currentSubMenu);
|
||||
currentSubMenu = null;
|
||||
DestroyCurrentSubMenuAndClearListeners();
|
||||
if (TooltipManager.Instance != null && TooltipManager.Instance.IsInitialized) TooltipManager.Instance.HideTooltip();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user