UTKAccodion 완료. UTKComponentList 수정 중

This commit is contained in:
logonkhi
2026-01-22 20:12:22 +09:00
parent e00953de52
commit 59d473c87b
59 changed files with 2482 additions and 498 deletions

View File

@@ -22,6 +22,113 @@ namespace UVC.UIToolkit
/// <item>드래그 앤 드롭 이벤트 전달</item>
/// </list>
///
/// <para><b>UXML 사용 예시:</b></para>
/// <code><![CDATA[
/// <!-- UXML 파일에서 UTKAccordionListWindow 사용 -->
/// <ui:UXML xmlns:utk="UVC.UIToolkit">
/// <utk:UTKAccordionListWindow name="accordion-window" />
/// </ui:UXML>
/// ]]></code>
///
/// <para><b>C# 사용 예시:</b></para>
/// <code><![CDATA[
/// // 1. 윈도우 참조 획득
/// var accordionWindow = root.Q<UTKAccordionListWindow>("accordion-window");
///
/// // 2. 윈도우 제목 설정
/// accordionWindow.Title = "프리팹 라이브러리";
///
/// // 3. 닫기 버튼 표시 설정
/// accordionWindow.ShowCloseButton = true;
///
/// // 4. 데이터 구성 및 설정
/// var data = new List<UTKAccordionItemData>
/// {
/// new UTKAccordionItemData
/// {
/// nodeType = UTKAccordionNodeType.Section,
/// name = "가구",
/// isExpanded = true,
/// children = new List<UTKAccordionItemData>
/// {
/// new UTKAccordionItemData
/// {
/// nodeType = UTKAccordionNodeType.GridItem,
/// name = "의자",
/// imagePath = "Prefabs/Thumbnails/chair",
/// prefabPath = "Prefabs/Furniture/Chair"
/// }
/// }
/// }
/// };
/// accordionWindow.SetData(data);
///
/// // 5. 아이템 클릭 이벤트 구독 (통합 API)
/// accordionWindow.OnItemClick += (item) =>
/// {
/// Debug.Log($"클릭된 아이템: {item.name}");
/// };
///
/// // 6. 드래그 앤 드롭 이벤트 구독
/// accordionWindow.OnItemBeginDrag += (item, screenPos) =>
/// {
/// Debug.Log($"드래그 시작: {item.name}");
/// };
///
/// accordionWindow.OnItemDrop += (item) =>
/// {
/// // 프리팹 인스턴스화
/// if (!string.IsNullOrEmpty(item.prefabPath))
/// {
/// var prefab = Resources.Load<GameObject>(item.prefabPath);
/// Instantiate(prefab, dropPosition, Quaternion.identity);
/// }
/// };
///
/// // 7. 리스트 영역 밖으로 드래그 시 3D 미리보기 표시
/// accordionWindow.OnDragExitList += (gridItem, screenPos) =>
/// {
/// Show3DPreview(gridItem.PrefabPath, screenPos);
/// };
///
/// // 8. 리스트 영역으로 다시 들어오면 미리보기 숨김
/// accordionWindow.OnDragEnterList += (gridItem, screenPos) =>
/// {
/// Hide3DPreview();
/// };
///
/// // 9. 섹션 펼침/접힘 이벤트
/// accordionWindow.OnSectionToggled += (section, isExpanded) =>
/// {
/// Debug.Log($"섹션 '{section.Title}': {(isExpanded ? "펼침" : "접힘")}");
/// };
///
/// // 10. 윈도우 닫힘 이벤트
/// accordionWindow.OnClosed += () =>
/// {
/// Debug.Log("윈도우가 닫혔습니다.");
/// };
///
/// // 11. 드래그 고스트 이미지 설정
/// accordionWindow.ShowDragGhost = true;
///
/// // 12. 검색 실행
/// accordionWindow.Search("의자");
/// accordionWindow.ClearSearch();
///
/// // 13. 섹션 제어
/// accordionWindow.ExpandAll();
/// accordionWindow.CollapseAll();
/// accordionWindow.SetSectionExpanded(sectionId, true);
///
/// // 14. 윈도우 표시/닫기
/// accordionWindow.Show();
/// accordionWindow.Close();
///
/// // 15. 리소스 해제 (OnDestroy에서 호출)
/// accordionWindow.Dispose();
/// ]]></code>
///
/// <para><b>관련 리소스:</b></para>
/// <list type="bullet">
/// <item>Resources/UIToolkit/Window/UTKAccordionListWindow.uxml - 윈도우 레이아웃</item>
@@ -34,13 +141,14 @@ namespace UVC.UIToolkit
#region (Constants)
private const string UXML_PATH = "UIToolkit/Window/UTKAccordionListWindow";
private const string USS_PATH = "UIToolkit/Window/UTKAccordionListWindowUss";
#endregion
#region UI (UI Component References)
private UTKAccordionList? _accordionList;
private Button? _closeButton;
private UTKButton? _closeButton;
private Label? _titleLabel;
#endregion
@@ -226,6 +334,17 @@ namespace UVC.UIToolkit
}
visualTree.CloneTree(this);
// 테마 적용 및 변경 구독
UTKThemeManager.Instance.ApplyThemeToElement(this);
SubscribeToThemeChanges();
// USS 로드 (테마 변수 스타일시트 이후에 로드되어야 변수가 해석됨)
var uss = Resources.Load<StyleSheet>(USS_PATH);
if (uss != null)
{
styleSheets.Add(uss);
}
// 내부 UTKAccordionList 찾기
_accordionList = this.Q<UTKAccordionList>();
if (_accordionList == null)
@@ -240,12 +359,13 @@ namespace UVC.UIToolkit
// 헤더 요소 참조
_titleLabel = this.Q<Label>("title");
_closeButton = this.Q<Button>("close-btn");
_closeButton = this.Q<UTKButton>("close-btn");
// 닫기 버튼 이벤트
// 닫기 버튼 설정 및 이벤트 연결
if (_closeButton != null)
{
_closeButton.clicked += OnCloseButtonClicked;
_closeButton.SetMaterialIcon(UTKMaterialIcons.Close, 16);
_closeButton.OnClicked += OnCloseButtonClicked;
}
}
@@ -326,6 +446,24 @@ namespace UVC.UIToolkit
#endregion
#region (Theme)
private void SubscribeToThemeChanges()
{
UTKThemeManager.Instance.OnThemeChanged += OnThemeChanged;
RegisterCallback<DetachFromPanelEvent>(_ =>
{
UTKThemeManager.Instance.OnThemeChanged -= OnThemeChanged;
});
}
private void OnThemeChanged(UTKTheme theme)
{
UTKThemeManager.Instance.ApplyThemeToElement(this);
}
#endregion
#region IDisposable
public void Dispose()
@@ -333,14 +471,18 @@ namespace UVC.UIToolkit
if (_disposed) return;
_disposed = true;
// 테마 변경 이벤트 해제
UTKThemeManager.Instance.OnThemeChanged -= OnThemeChanged;
// 내부 UTKAccordionList 정리
_accordionList?.Dispose();
_accordionList = null;
// 닫기 버튼 이벤트 해제
// 닫기 버튼 이벤트 해제 및 정리
if (_closeButton != null)
{
_closeButton.clicked -= OnCloseButtonClicked;
_closeButton.OnClicked -= OnCloseButtonClicked;
_closeButton.Dispose();
}
// 외부 이벤트 정리

View File

@@ -14,17 +14,119 @@ namespace UVC.UIToolkit
/// 윈도우 형태의 컴포넌트입니다. 모든 트리 관련 기능은 내부 UTKComponentList에 위임됩니다.
/// </para>
///
/// <para><b>UXML에서 사용:</b></para>
/// <code>
/// <UVC.UIToolkit.Window.UTKComponentListWindow name="tree-list-window" />
/// </code>
/// <para><b>UXML 사용 예시:</b></para>
/// <code><![CDATA[
/// <!-- UXML 파일에서 UTKComponentListWindow 사용 -->
/// <ui:UXML xmlns:utk="UVC.UIToolkit">
/// <utk:UTKComponentListWindow name="component-window" />
/// </ui:UXML>
/// ]]></code>
///
/// <para><b>코드에서 사용:</b></para>
/// <code>
/// var window = root.Q<UTKComponentListWindow>();
/// window.OnItemSelected += (items) => Debug.Log($"선택: {items[0].name}");
/// window.SetData(treeItems);
/// </code>
/// <para><b>C# 사용 예시:</b></para>
/// <code><![CDATA[
/// // 1. 윈도우 참조 획득
/// var componentWindow = root.Q<UTKComponentListWindow>("component-window");
///
/// // 2. 윈도우 제목 및 닫기 버튼 설정
/// componentWindow.Title = "모델 리스트";
/// componentWindow.ShowCloseButton = true;
///
/// // 3. 데이터 구성 - 카테고리와 아이템
/// var data = new List<UTKComponentListItemDataBase>
/// {
/// new UTKComponentListCategoryData
/// {
/// name = "캐릭터",
/// isExpanded = true,
/// children = new List<UTKComponentListItemDataBase>
/// {
/// new UTKComponentListItemData
/// {
/// name = "플레이어",
/// ExternalKey = "player_001",
/// IsVisible = true
/// },
/// new UTKComponentListItemData
/// {
/// name = "NPC",
/// ExternalKey = "npc_001",
/// IsVisible = true
/// }
/// }
/// }
/// };
/// componentWindow.SetData(data);
///
/// // 4. 선택 이벤트 구독
/// componentWindow.OnItemSelected = (selectedItems) =>
/// {
/// foreach (var item in selectedItems)
/// {
/// Debug.Log($"선택됨: {item.name}");
/// // 3D 뷰에서 해당 모델 하이라이트
/// HighlightModel(item.ExternalKey);
/// }
/// };
///
/// // 5. 선택 해제 이벤트
/// componentWindow.OnItemDeselected = (deselectedItems) =>
/// {
/// foreach (var item in deselectedItems)
/// {
/// UnhighlightModel(item.ExternalKey);
/// }
/// };
///
/// // 6. 가시성 변경 이벤트 (눈 아이콘)
/// componentWindow.OnItemVisibilityChanged += (item, isVisible) =>
/// {
/// var gameObject = FindGameObjectByKey(item.ExternalKey);
/// if (gameObject != null)
/// {
/// gameObject.SetActive(isVisible);
/// }
/// };
///
/// // 7. 삭제 이벤트 (Delete/Backspace 키)
/// componentWindow.EnabledDeleteItem = true;
/// componentWindow.OnItemDeleted = (item) =>
/// {
/// Debug.Log($"삭제 요청: {item.name}");
/// componentWindow.DeleteItem(item);
/// };
///
/// // 8. 더블클릭 이벤트
/// componentWindow.OnItemDoubleClicked = (item) =>
/// {
/// // 카메라 포커스
/// FocusCameraOn(item.ExternalKey);
/// };
///
/// // 9. 윈도우 닫힘 이벤트
/// componentWindow.OnClosed += () =>
/// {
/// Debug.Log("윈도우가 닫혔습니다.");
/// };
///
/// // 10. 프로그래밍 방식 선택
/// componentWindow.SelectItem("플레이어", notify: true);
/// componentWindow.DeselectItem("플레이어", notify: false);
/// componentWindow.ClearSelection();
/// componentWindow.SelectByItemId(itemId);
///
/// // 11. 아이템 추가/삭제
/// var newItem = new UTKComponentListItemData { name = "새 캐릭터" };
/// componentWindow.AddItem(newItem);
/// componentWindow.AddItem(categoryData, newItem);
/// componentWindow.DeleteItem(newItem);
/// componentWindow.SetItemName(newItem, "수정된 이름");
///
/// // 12. 윈도우 표시
/// componentWindow.Show();
///
/// // 13. 리소스 해제 (OnDestroy에서 호출)
/// componentWindow.Dispose();
/// ]]></code>
/// </summary>
[UxmlElement]
public partial class UTKComponentListWindow : VisualElement, IDisposable
@@ -36,14 +138,20 @@ namespace UVC.UIToolkit
#region (Constants)
/// <summary>메인 UXML 파일 경로 (Resources 폴더 기준)</summary>
private const string UXML_PATH = "UIToolkit/Window/UTKComponentListWindow";
/// <summary>USS 파일 경로 (Resources 폴더 기준)</summary>
private const string USS_PATH = "UIToolkit/Window/UTKComponentListWindowUss";
#endregion
#region UI (UI Component References)
/// <summary>내부 UTKComponentList 컴포넌트</summary>
private UTKComponentList? _componentList;
/// <summary>트리 리스트 닫기 버튼</summary>
private Button? _closeButton;
/// <summary>트리 리스트 닫기 버튼 (UTKButton)</summary>
private UTKButton? _closeButton;
/// <summary>윈도우 제목 라벨</summary>
private Label? _titleLabel;
#endregion
#region (Public Properties)
@@ -57,6 +165,20 @@ namespace UVC.UIToolkit
get => _componentList?.EnabledDeleteItem ?? false;
set { if (_componentList != null) _componentList.EnabledDeleteItem = value; }
}
/// <summary>윈도우 제목을 가져오거나 설정합니다.</summary>
public string Title
{
get => _titleLabel?.text ?? string.Empty;
set { if (_titleLabel != null) _titleLabel.text = value; }
}
/// <summary>닫기 버튼 표시 여부를 설정합니다.</summary>
public bool ShowCloseButton
{
get => _closeButton?.style.display == DisplayStyle.Flex;
set { if (_closeButton != null) _closeButton.style.display = value ? DisplayStyle.Flex : DisplayStyle.None; }
}
#endregion
#region (Public Events)
@@ -145,17 +267,35 @@ namespace UVC.UIToolkit
return;
}
// 3. 닫기 버튼 찾기 및 이벤트 연결
_closeButton = this.Q<Button>("close-btn");
// 3. 테마 적용 및 변경 구독
UTKThemeManager.Instance.ApplyThemeToElement(this);
SubscribeToThemeChanges();
// USS 로드 (테마 변수 스타일시트 이후에 로드되어야 변수가 해석됨)
var uss = Resources.Load<StyleSheet>(USS_PATH);
if (uss != null)
{
styleSheets.Add(uss);
}
// 4. 헤더 요소 참조
_titleLabel = this.Q<Label>("title");
_closeButton = this.Q<UTKButton>("close-btn");
// 5. 닫기 버튼 설정 및 이벤트 연결
if (_closeButton != null)
{
_closeButton.clicked += () =>
{
this.style.display = DisplayStyle.None;
OnClosed?.Invoke();
};
_closeButton.SetMaterialIcon(UTKMaterialIcons.Close, 16);
_closeButton.OnClicked += OnCloseButtonClicked;
}
}
/// <summary>닫기 버튼 클릭 이벤트 핸들러</summary>
private void OnCloseButtonClicked()
{
this.style.display = DisplayStyle.None;
OnClosed?.Invoke();
}
#endregion
#region (Public Methods)
@@ -263,6 +403,24 @@ namespace UVC.UIToolkit
}
#endregion
#region (Theme)
private void SubscribeToThemeChanges()
{
UTKThemeManager.Instance.OnThemeChanged += OnThemeChanged;
RegisterCallback<DetachFromPanelEvent>(_ =>
{
UTKThemeManager.Instance.OnThemeChanged -= OnThemeChanged;
});
}
private void OnThemeChanged(UTKTheme theme)
{
UTKThemeManager.Instance.ApplyThemeToElement(this);
}
#endregion
#region IDisposable
/// <summary>
/// 리소스를 해제하고 이벤트 핸들러를 정리합니다.
@@ -272,15 +430,26 @@ namespace UVC.UIToolkit
if (_disposed) return;
_disposed = true;
// 테마 변경 이벤트 해제
UTKThemeManager.Instance.OnThemeChanged -= OnThemeChanged;
// 내부 UTKComponentList 정리
_componentList?.Dispose();
_componentList = null;
// 닫기 버튼 이벤트 해제 및 정리
if (_closeButton != null)
{
_closeButton.OnClicked -= OnCloseButtonClicked;
_closeButton.Dispose();
}
// 외부 이벤트 구독자 정리
OnClosed = null;
// UI 참조 정리
_closeButton = null;
_titleLabel = null;
}
#endregion
}

View File

@@ -15,18 +15,132 @@ namespace UVC.UIToolkit
/// 탭 버튼들을 추가한 윈도우 형태의 컴포넌트입니다. 탭을 통해 카테고리별 필터링이 가능합니다.
/// </para>
///
/// <para><b>UXML에서 사용:</b></para>
/// <code>
/// <UVC.UIToolkit.Window.UTKComponentTabListWindow name="tab-list-window" />
/// </code>
/// <para><b>UXML 사용 예시:</b></para>
/// <code><![CDATA[
/// <!-- UXML 파일에서 UTKComponentTabListWindow 사용 -->
/// <ui:UXML xmlns:utk="UVC.UIToolkit">
/// <utk:UTKComponentTabListWindow name="tab-list-window" />
/// </ui:UXML>
/// ]]></code>
///
/// <para><b>코드에서 사용:</b></para>
/// <code>
/// var window = root.Q<UTKComponentTabListWindow>();
/// window.OnItemSelected += (items) => Debug.Log($"선택: {items[0].name}");
/// window.SetData(treeItems);
/// window.SelectTab(0); // 첫 번째 카테고리 탭 선택
/// </code>
/// <para><b>C# 사용 예시:</b></para>
/// <code><![CDATA[
/// // 1. 윈도우 참조 획득
/// var tabWindow = root.Q<UTKComponentTabListWindow>("tab-list-window");
///
/// // 2. 윈도우 제목 및 닫기 버튼 설정
/// tabWindow.Title = "에셋 라이브러리";
/// tabWindow.ShowCloseButton = true;
///
/// // 3. 데이터 구성 - 카테고리별로 자동 탭 생성됨
/// var data = new List<UTKComponentListItemDataBase>
/// {
/// // 첫 번째 카테고리 → "캐릭터" 탭 자동 생성
/// new UTKComponentListCategoryData
/// {
/// name = "캐릭터",
/// isExpanded = true,
/// children = new List<UTKComponentListItemDataBase>
/// {
/// new UTKComponentListItemData { name = "플레이어", ExternalKey = "player" },
/// new UTKComponentListItemData { name = "NPC", ExternalKey = "npc" }
/// }
/// },
/// // 두 번째 카테고리 → "오브젝트" 탭 자동 생성
/// new UTKComponentListCategoryData
/// {
/// name = "오브젝트",
/// isExpanded = true,
/// children = new List<UTKComponentListItemDataBase>
/// {
/// new UTKComponentListItemData { name = "상자", ExternalKey = "box" },
/// new UTKComponentListItemData { name = "나무", ExternalKey = "tree" }
/// }
/// }
/// };
/// tabWindow.SetData(data);
/// // → "All" 탭과 "캐릭터", "오브젝트" 탭이 자동 생성됨
///
/// // 4. 탭 선택 (프로그래밍 방식)
/// tabWindow.SelectTab(-1); // -1 = "All" 전체 탭
/// tabWindow.SelectTab(0); // 0 = 첫 번째 카테고리 ("캐릭터")
/// tabWindow.SelectTab(1); // 1 = 두 번째 카테고리 ("오브젝트")
///
/// // 5. 선택 이벤트 구독
/// tabWindow.OnItemSelected = (selectedItems) =>
/// {
/// foreach (var item in selectedItems)
/// {
/// Debug.Log($"선택됨: {item.name}");
/// }
/// };
///
/// // 6. 선택 해제 이벤트
/// tabWindow.OnItemDeselected = (deselectedItems) =>
/// {
/// foreach (var item in deselectedItems)
/// {
/// Debug.Log($"선택 해제: {item.name}");
/// }
/// };
///
/// // 7. 가시성 변경 이벤트 (눈 아이콘)
/// tabWindow.OnItemVisibilityChanged += (item, isVisible) =>
/// {
/// var gameObject = FindGameObjectByKey(item.ExternalKey);
/// if (gameObject != null)
/// {
/// gameObject.SetActive(isVisible);
/// }
/// };
///
/// // 8. 삭제 이벤트 (Delete/Backspace 키)
/// tabWindow.EnabledDeleteItem = true;
/// tabWindow.OnItemDeleted = (item) =>
/// {
/// Debug.Log($"삭제 요청: {item.name}");
/// tabWindow.DeleteItem(item); // 탭 목록도 자동 갱신됨
/// };
///
/// // 9. 더블클릭 이벤트
/// tabWindow.OnItemDoubleClicked = (item) =>
/// {
/// FocusCameraOn(item.ExternalKey);
/// };
///
/// // 10. 윈도우 닫힘 이벤트
/// tabWindow.OnClosed += () =>
/// {
/// Debug.Log("윈도우가 닫혔습니다.");
/// };
///
/// // 11. 프로그래밍 방식 선택
/// tabWindow.SelectItem("플레이어", notify: true);
/// tabWindow.DeselectItem("플레이어", notify: false);
/// tabWindow.ClearSelection();
///
/// // 12. 아이템 추가/삭제 (탭 자동 갱신)
/// var newCategory = new UTKComponentListCategoryData { name = "이펙트" };
/// tabWindow.AddItem(newCategory); // "이펙트" 탭 자동 생성
///
/// var newItem = new UTKComponentListItemData { name = "폭발" };
/// tabWindow.AddItem(newCategory, newItem); // 카테고리에 아이템 추가
///
/// tabWindow.DeleteItem(newItem); // 아이템 삭제
///
/// // 13. 윈도우 표시
/// tabWindow.Show();
///
/// // 14. 리소스 해제 (OnDestroy에서 호출)
/// tabWindow.Dispose();
/// ]]></code>
///
/// <para><b>탭 동작 설명:</b></para>
/// <list type="bullet">
/// <item>"All" 탭: 모든 카테고리와 아이템을 표시합니다.</item>
/// <item>카테고리 탭: 해당 카테고리의 자식 아이템만 표시합니다 (부모 카테고리 없이).</item>
/// <item>탭별 검색어가 저장되어, 탭 전환 시 해당 탭의 검색어가 복원됩니다.</item>
/// </list>
/// </summary>
[UxmlElement]
public partial class UTKComponentTabListWindow : VisualElement, IDisposable
@@ -39,6 +153,9 @@ namespace UVC.UIToolkit
/// <summary>메인 UXML 파일 경로 (Resources 폴더 기준)</summary>
private const string UXML_PATH = "UIToolkit/Window/UTKComponentTabListWindow";
/// <summary>USS 파일 경로 (Resources 폴더 기준)</summary>
private const string USS_PATH = "UIToolkit/Window/UTKComponentListWindowUss";
/// <summary>"전체" 탭을 나타내는 인덱스</summary>
private const int ALL_TAB_INDEX = -1;
#endregion
@@ -50,8 +167,11 @@ namespace UVC.UIToolkit
/// <summary>탭 버튼 컨테이너</summary>
private VisualElement? _tabContainer;
/// <summary>트리 리스트 닫기 버튼</summary>
private Button? _closeButton;
/// <summary>트리 리스트 닫기 버튼 (UTKButton)</summary>
private UTKButton? _closeButton;
/// <summary>윈도우 제목 라벨</summary>
private Label? _titleLabel;
#endregion
#region (Tab Data)
@@ -79,6 +199,20 @@ namespace UVC.UIToolkit
get => _componentList?.EnabledDeleteItem ?? false;
set { if (_componentList != null) _componentList.EnabledDeleteItem = value; }
}
/// <summary>윈도우 제목을 가져오거나 설정합니다.</summary>
public string Title
{
get => _titleLabel?.text ?? string.Empty;
set { if (_titleLabel != null) _titleLabel.text = value; }
}
/// <summary>닫기 버튼 표시 여부를 설정합니다.</summary>
public bool ShowCloseButton
{
get => _closeButton?.style.display == DisplayStyle.Flex;
set { if (_closeButton != null) _closeButton.style.display = value ? DisplayStyle.Flex : DisplayStyle.None; }
}
#endregion
#region (Public Events)
@@ -167,20 +301,38 @@ namespace UVC.UIToolkit
return;
}
// 3. 탭 관련 요소 찾기
// 3. 테마 적용 및 변경 구독
UTKThemeManager.Instance.ApplyThemeToElement(this);
SubscribeToThemeChanges();
// USS 로드 (테마 변수 스타일시트 이후에 로드되어야 변수가 해석됨)
var uss = Resources.Load<StyleSheet>(USS_PATH);
if (uss != null)
{
styleSheets.Add(uss);
}
// 4. 탭 관련 요소 찾기
_tabContainer = this.Q<VisualElement>("tab-container");
// 4. 닫기 버튼 찾기 및 이벤트 연결
_closeButton = this.Q<Button>("close-btn");
// 5. 헤더 요소 참조
_titleLabel = this.Q<Label>("title");
_closeButton = this.Q<UTKButton>("close-btn");
// 6. 닫기 버튼 설정 및 이벤트 연결
if (_closeButton != null)
{
_closeButton.clicked += () =>
{
this.style.display = DisplayStyle.None;
OnClosed?.Invoke();
};
_closeButton.SetMaterialIcon(UTKMaterialIcons.Close, 16);
_closeButton.OnClicked += OnCloseButtonClicked;
}
}
/// <summary>닫기 버튼 클릭 이벤트 핸들러</summary>
private void OnCloseButtonClicked()
{
this.style.display = DisplayStyle.None;
OnClosed?.Invoke();
}
#endregion
#region (Public Methods)
@@ -507,6 +659,24 @@ namespace UVC.UIToolkit
}
#endregion
#region (Theme)
private void SubscribeToThemeChanges()
{
UTKThemeManager.Instance.OnThemeChanged += OnThemeChanged;
RegisterCallback<DetachFromPanelEvent>(_ =>
{
UTKThemeManager.Instance.OnThemeChanged -= OnThemeChanged;
});
}
private void OnThemeChanged(UTKTheme theme)
{
UTKThemeManager.Instance.ApplyThemeToElement(this);
}
#endregion
#region IDisposable
/// <summary>
/// 리소스를 해제하고 이벤트 핸들러를 정리합니다.
@@ -516,6 +686,9 @@ namespace UVC.UIToolkit
if (_disposed) return;
_disposed = true;
// 테마 변경 이벤트 해제
UTKThemeManager.Instance.OnThemeChanged -= OnThemeChanged;
// 내부 UTKComponentList 정리
_componentList?.Dispose();
_componentList = null;
@@ -524,6 +697,13 @@ namespace UVC.UIToolkit
_tabButtons.Clear();
_tabContainer = null;
// 닫기 버튼 이벤트 해제 및 정리
if (_closeButton != null)
{
_closeButton.OnClicked -= OnCloseButtonClicked;
_closeButton.Dispose();
}
// 외부 이벤트 구독자 정리
OnClosed = null;
@@ -533,6 +713,7 @@ namespace UVC.UIToolkit
// UI 참조 정리
_closeButton = null;
_titleLabel = null;
}
#endregion
}

View File

@@ -22,17 +22,116 @@ namespace UVC.UIToolkit
/// <item>드래그 앤 드롭 이벤트 전달</item>
/// </list>
///
/// <para><b>UXML에서 사용:</b></para>
/// <code>
/// <uvc:UTKImageListWindow name="library-window" />
/// </code>
/// <para><b>UXML 사용 예시:</b></para>
/// <code><![CDATA[
/// <!-- UXML 파일에서 UTKImageListWindow 사용 -->
/// <ui:UXML xmlns:utk="UVC.UIToolkit">
/// <utk:UTKImageListWindow name="library-window" />
/// </ui:UXML>
/// ]]></code>
///
/// <para><b>코드에서 사용:</b></para>
/// <code>
/// var window = root.Q<UTKImageListWindow>();
/// window.OnItemClick += (item) => Debug.Log($"클릭: {item.itemName}");
/// window.SetData(imageItems);
/// </code>
/// <para><b>C# 사용 예시:</b></para>
/// <code><![CDATA[
/// // 1. 윈도우 참조 획득
/// var imageWindow = root.Q<UTKImageListWindow>("library-window");
///
/// // 2. 윈도우 제목 및 닫기 버튼 설정
/// imageWindow.Title = "프리팹 라이브러리";
/// imageWindow.ShowCloseButton = true;
///
/// // 3. 데이터 구성 - 이미지와 이름을 가진 아이템들
/// var data = new List<UTKImageListItemData>
/// {
/// new UTKImageListItemData
/// {
/// itemName = "의자",
/// imagePath = "Prefabs/Thumbnails/chair",
/// prefabPath = "Prefabs/Furniture/Chair"
/// },
/// new UTKImageListItemData
/// {
/// itemName = "책상",
/// imagePath = "Prefabs/Thumbnails/desk",
/// prefabPath = "Prefabs/Furniture/Desk"
/// }
/// };
/// imageWindow.SetData(data);
///
/// // 4. 아이템 클릭 이벤트 구독
/// imageWindow.OnItemClick = (item) =>
/// {
/// Debug.Log($"클릭된 아이템: {item.itemName}");
/// };
///
/// // 5. 드래그 시작 이벤트
/// imageWindow.OnItemBeginDrag = (item, screenPos) =>
/// {
/// Debug.Log($"드래그 시작: {item.itemName}");
/// };
///
/// // 6. 드래그 중 이벤트
/// imageWindow.OnItemDrag = (item, screenPos) =>
/// {
/// // 드래그 중 위치 업데이트
/// };
///
/// // 7. 드래그 종료 이벤트
/// imageWindow.OnItemEndDrag = (item, screenPos) =>
/// {
/// Debug.Log($"드래그 종료: {item.itemName}");
/// };
///
/// // 8. 드롭 이벤트 (프리팹 인스턴스화)
/// imageWindow.OnItemDrop = (item) =>
/// {
/// if (!string.IsNullOrEmpty(item.prefabPath))
/// {
/// var prefab = Resources.Load<GameObject>(item.prefabPath);
/// Instantiate(prefab, dropPosition, Quaternion.identity);
/// }
/// };
///
/// // 9. 리스트 영역 밖으로 드래그 시 3D 미리보기 표시
/// imageWindow.OnDragExitList = (item, screenPos) =>
/// {
/// // 리스트 밖 = 3D 씬 영역
/// Show3DPreview(item.prefabPath, screenPos);
/// };
///
/// // 10. 리스트 영역으로 다시 들어오면 미리보기 숨김
/// imageWindow.OnDragEnterList = (item, screenPos) =>
/// {
/// Hide3DPreview();
/// };
///
/// // 11. 윈도우 닫힘 이벤트
/// imageWindow.OnClosed += () =>
/// {
/// Debug.Log("윈도우가 닫혔습니다.");
/// };
///
/// // 12. 드래그 고스트 이미지 설정
/// imageWindow.DragImageFollowCursor = true;
///
/// // 13. 검색 실행
/// imageWindow.ApplySearch("의자");
///
/// // 14. 아이템 추가/제거
/// var newItem = new UTKImageListItemData { itemName = "새 아이템" };
/// imageWindow.AddItem(newItem);
/// imageWindow.RemoveItem(newItem);
/// imageWindow.Clear();
///
/// // 15. 아이템 개수 확인
/// int count = imageWindow.ItemCount;
///
/// // 16. 윈도우 표시/닫기
/// imageWindow.Show();
/// imageWindow.Close();
///
/// // 17. 리소스 해제 (OnDestroy에서 호출)
/// imageWindow.Dispose();
/// ]]></code>
///
/// <para><b>관련 리소스:</b></para>
/// <list type="bullet">
@@ -48,6 +147,9 @@ namespace UVC.UIToolkit
/// <summary>메인 UXML 파일 경로 (Resources 폴더 기준)</summary>
private const string UXML_PATH = "UIToolkit/Window/UTKImageListWindow";
/// <summary>USS 파일 경로 (Resources 폴더 기준)</summary>
private const string USS_PATH = "UIToolkit/Window/UTKImageListWindowUss";
#endregion
#region UI (UI Component References)
@@ -55,8 +157,8 @@ namespace UVC.UIToolkit
/// <summary>내부 UTKImageList 컴포넌트</summary>
private UTKImageList? _imageList;
/// <summary>윈도우 닫기 버튼</summary>
private Button? _closeButton;
/// <summary>윈도우 닫기 버튼 (UTKButton)</summary>
private UTKButton? _closeButton;
/// <summary>윈도우 제목 라벨</summary>
private Label? _titleLabel;
@@ -214,7 +316,18 @@ namespace UVC.UIToolkit
}
visualTree.CloneTree(this);
// 2. 내부 UTKImageList 찾기 (UXML에서 생성된 컴포넌트)
// 2. 테마 적용 및 변경 구독
UTKThemeManager.Instance.ApplyThemeToElement(this);
SubscribeToThemeChanges();
// USS 로드 (테마 변수 스타일시트 이후에 로드되어야 변수가 해석됨)
var uss = Resources.Load<StyleSheet>(USS_PATH);
if (uss != null)
{
styleSheets.Add(uss);
}
// 3. 내부 UTKImageList 찾기 (UXML에서 생성된 컴포넌트)
_imageList = this.Q<UTKImageList>();
if (_imageList == null)
{
@@ -226,14 +339,15 @@ namespace UVC.UIToolkit
_imageList.DragBoundsElement = this;
}
// 3. 헤더 요소 참조
// 4. 헤더 요소 참조
_titleLabel = this.Q<Label>("title");
_closeButton = this.Q<Button>("close-btn");
_closeButton = this.Q<UTKButton>("close-btn");
// 4. 닫기 버튼 이벤트 연결
// 5. 닫기 버튼 설정 및 이벤트 연결
if (_closeButton != null)
{
_closeButton.clicked += OnCloseButtonClicked;
_closeButton.SetMaterialIcon(UTKMaterialIcons.Close, 16);
_closeButton.OnClicked += OnCloseButtonClicked;
}
}
@@ -320,6 +434,24 @@ namespace UVC.UIToolkit
#endregion
#region (Theme)
private void SubscribeToThemeChanges()
{
UTKThemeManager.Instance.OnThemeChanged += OnThemeChanged;
RegisterCallback<DetachFromPanelEvent>(_ =>
{
UTKThemeManager.Instance.OnThemeChanged -= OnThemeChanged;
});
}
private void OnThemeChanged(UTKTheme theme)
{
UTKThemeManager.Instance.ApplyThemeToElement(this);
}
#endregion
#region IDisposable
/// <summary>
@@ -330,14 +462,18 @@ namespace UVC.UIToolkit
if (_disposed) return;
_disposed = true;
// 테마 변경 이벤트 해제
UTKThemeManager.Instance.OnThemeChanged -= OnThemeChanged;
// 내부 UTKImageList 정리
_imageList?.Dispose();
_imageList = null;
// 닫기 버튼 이벤트 해제
// 닫기 버튼 이벤트 해제 및 정리
if (_closeButton != null)
{
_closeButton.clicked -= OnCloseButtonClicked;
_closeButton.OnClicked -= OnCloseButtonClicked;
_closeButton.Dispose();
}
// 외부 이벤트 구독자 정리

View File

@@ -13,9 +13,9 @@ namespace UVC.UIToolkit
///
/// <para><b>개요:</b></para>
/// <para>
/// TreeListWindow는 Unity UI Toolkit의 TreeView를 래핑하여 검색, 가시성 토글,
/// UTKTreeListWindow는 Unity UI Toolkit의 TreeView를 래핑하여 검색, 가시성 토글,
/// 닫기 기능 등을 제공하는 재사용 가능한 컴포넌트입니다.
/// UXML 파일(TreeListWindow.uxml, TreeListItem.uxml)과 함께 사용됩니다.
/// UXML 파일(UTKTreeListWindow.uxml, UTKTreeListItem.uxml)과 함께 사용됩니다.
/// </para>
///
/// <para><b>주요 기능:</b></para>
@@ -23,21 +23,116 @@ namespace UVC.UIToolkit
/// <item>계층적 트리 구조 표시 (펼치기/접기 지원)</item>
/// <item>실시간 검색 필터링</item>
/// <item>항목별 가시성(눈 아이콘) 토글</item>
/// <item>선택 이벤트 처리</item>
/// <item>다중 선택 지원</item>
/// <item>삭제 기능 (Delete/Backspace 키)</item>
/// </list>
///
/// <para><b>UXML에서 사용:</b></para>
/// <code>
/// <UVC.UIToolkit.Window.UTKTreeListWindow name="tree-list" />
/// </code>
/// <para><b>UXML 사용 예시:</b></para>
/// <code><![CDATA[
/// <!-- UXML 파일에서 UTKTreeListWindow 사용 -->
/// <ui:UXML xmlns:utk="UVC.UIToolkit">
/// <utk:UTKTreeListWindow name="tree-list-window" />
/// </ui:UXML>
/// ]]></code>
///
/// <para><b>코드에서 사용:</b></para>
/// <code>
/// var treeList = root.Q<UTKTreeListWindow>();
/// treeList.OnSelectionChanged += (item) => Debug.Log($"선택: {item.name}");
/// treeList.OnVisibilityChanged += (item) => model.SetActive(item.id, item.IsVisible);
/// treeList.SetData(treeItems);
/// </code>
/// <para><b>C# 사용 예시:</b></para>
/// <code><![CDATA[
/// // 1. 윈도우 참조 획득
/// var treeWindow = root.Q<UTKTreeListWindow>("tree-list-window");
///
/// // 2. 윈도우 제목 및 닫기 버튼 설정
/// treeWindow.Title = "씬 계층구조";
/// treeWindow.ShowCloseButton = true;
///
/// // 3. 데이터 구성 - 계층적 트리 구조
/// var data = new List<UTKTreeListItemData>
/// {
/// new UTKTreeListItemData
/// {
/// name = "루트 오브젝트",
/// isExpanded = true,
/// IsVisible = true,
/// children = new List<UTKTreeListItemData>
/// {
/// new UTKTreeListItemData
/// {
/// name = "자식 오브젝트 1",
/// IsVisible = true
/// },
/// new UTKTreeListItemData
/// {
/// name = "자식 오브젝트 2",
/// IsVisible = false,
/// children = new List<UTKTreeListItemData>
/// {
/// new UTKTreeListItemData { name = "손자 오브젝트" }
/// }
/// }
/// }
/// }
/// };
/// treeWindow.SetData(data);
///
/// // 4. 선택 변경 이벤트 구독 (선택 및 해제 모두)
/// treeWindow.OnSelectionChanged += (selectedItems) =>
/// {
/// Debug.Log($"선택된 아이템 수: {selectedItems.Count}");
/// foreach (var item in selectedItems)
/// {
/// Debug.Log($"선택: {item.name}");
/// }
/// };
///
/// // 5. 가시성 변경 이벤트 (눈 아이콘 클릭)
/// treeWindow.OnVisibilityChanged += (item) =>
/// {
/// Debug.Log($"{item.name} 가시성: {item.IsVisible}");
/// // 3D 씬에서 해당 오브젝트 활성화/비활성화
/// var gameObject = FindGameObjectByName(item.name);
/// if (gameObject != null)
/// {
/// gameObject.SetActive(item.IsVisible);
/// }
/// };
///
/// // 6. 삭제 이벤트 (Delete/Backspace 키)
/// treeWindow.EnabledDeleteItem = true;
/// treeWindow.OnItemDeleted += (item) =>
/// {
/// Debug.Log($"삭제 요청: {item.name}");
/// // 데이터에서 제거 후 UI 갱신
/// RemoveFromData(item);
/// treeWindow.Rebuild();
/// };
///
/// // 7. 윈도우 닫힘 이벤트
/// treeWindow.OnClosed += () =>
/// {
/// Debug.Log("윈도우가 닫혔습니다.");
/// };
///
/// // 8. 검색 실행
/// treeWindow.ApplySearch("자식");
/// // 검색어는 SearchQuery 속성으로 확인 가능
/// string currentQuery = treeWindow.SearchQuery;
///
/// // 9. 프로그래밍 방식 선택
/// treeWindow.SelectByItemId(itemId);
///
/// // 10. 전체 펼치기/접기
/// treeWindow.ExpandAll();
/// treeWindow.CollapseAll();
///
/// // 11. TreeView 갱신 (데이터 변경 후)
/// treeWindow.Rebuild();
///
/// // 12. 윈도우 표시/숨김
/// treeWindow.Show();
/// treeWindow.Hide();
///
/// // 13. 리소스 해제 (OnDestroy에서 호출)
/// treeWindow.Dispose();
/// ]]></code>
///
/// <para><b>관련 리소스:</b></para>
/// <list type="bullet">
@@ -60,7 +155,9 @@ namespace UVC.UIToolkit
#region (Constants)
/// <summary>메인 UXML 파일 경로 (Resources 폴더 기준)</summary>
private const string UXML_PATH = "UIToolkit/Window/UTKTreeListWindow";
/// <summary>USS 파일 경로 (Resources 폴더 기준)</summary>
private const string USS_PATH = "UIToolkit/Window/UTKTreeListWindowUss";
#endregion
#region UI (UI Component References)
@@ -70,11 +167,14 @@ namespace UVC.UIToolkit
/// <summary>Unity UI Toolkit의 TreeView 컴포넌트</summary>
private TreeView? _treeView;
/// <summary>트리 리스트 닫기 버튼</summary>
private Button? _closeButton;
/// <summary>트리 리스트 닫기 버튼 (UTKButton)</summary>
private UTKButton? _closeButton;
/// <summary>검색어 지우기 버튼</summary>
private Button? _clearButton;
/// <summary>검색어 지우기 버튼 (UTKButton)</summary>
private UTKButton? _clearButton;
/// <summary>윈도우 제목 라벨</summary>
private Label? _titleLabel;
#endregion
#region (Internal Data)
@@ -124,6 +224,20 @@ namespace UVC.UIToolkit
/// 기본값은 true입니다.
/// </summary>
public bool EnabledDeleteItem { get; set; } = true;
/// <summary>윈도우 제목</summary>
public string Title
{
get => _titleLabel?.text ?? string.Empty;
set { if (_titleLabel != null) _titleLabel.text = value; }
}
/// <summary>닫기 버튼 표시 여부</summary>
public bool ShowCloseButton
{
get => _closeButton?.style.display == DisplayStyle.Flex;
set { if (_closeButton != null) _closeButton.style.display = value ? DisplayStyle.Flex : DisplayStyle.None; }
}
#endregion
#region (Public Events)
@@ -177,14 +291,36 @@ namespace UVC.UIToolkit
}
visualTree!.CloneTree(this);
// 2. 테마 적용
UTKThemeManager.Instance.ApplyThemeToElement(this);
// 2. 자식 요소 참조 획득 (UXML의 name 속성으로 찾음)
// USS 로드 (테마 변수 스타일시트 이후에 로드되어야 변수가 해석됨)
var uss = Resources.Load<StyleSheet>(USS_PATH);
if (uss != null)
{
styleSheets.Add(uss);
}
// 3. 자식 요소 참조 획득 (UXML의 name 속성으로 찾음)
_searchField = this.Q<TextField>("search-field");
_treeView = this.Q<TreeView>("main-tree-view");
_closeButton = this.Q<Button>("close-btn");
_clearButton = this.Q<Button>("clear-btn");
_titleLabel = this.Q<Label>("title");
_closeButton = this.Q<UTKButton>("close-btn");
_clearButton = this.Q<UTKButton>("clear-btn");
// 3. 이벤트 연결 및 로직 초기화
// 4. 닫기 버튼 아이콘 설정
if (_closeButton != null)
{
_closeButton.SetMaterialIcon(UTKMaterialIcons.Close, 16);
}
// 5. Clear 버튼 아이콘 설정
if (_clearButton != null)
{
_clearButton.SetMaterialIcon(UTKMaterialIcons.Close, 12);
}
// 6. 이벤트 연결 및 로직 초기화
InitializeLogic();
}
#endregion
@@ -218,26 +354,14 @@ namespace UVC.UIToolkit
// 닫기 버튼: 트리 리스트를 숨기고 이벤트 발생
if (_closeButton != null)
{
_closeButton.clicked += () =>
{
this.style.display = DisplayStyle.None;
OnClosed?.Invoke();
};
_closeButton.OnClicked += OnCloseButtonClicked;
}
// 검색어 지우기 버튼
if(_clearButton != null)
{
_clearButton.style.display = DisplayStyle.None; // 초기에는 숨김
_clearButton.clicked += () =>
{
if (_searchField.value.Length > 0)
{
_searchField.value = string.Empty;
OnSearch(string.Empty);
}
_clearButton.style.display = DisplayStyle.None; // 클리어 후 숨김
};
_clearButton.OnClicked += OnClearButtonClicked;
}
// 스크롤바 hover/active 색상 설정
@@ -1095,6 +1219,33 @@ namespace UVC.UIToolkit
}
#endregion
#region (Button Event Handlers)
/// <summary>
/// 닫기 버튼 클릭 이벤트를 처리합니다.
/// </summary>
private void OnCloseButtonClicked()
{
this.style.display = DisplayStyle.None;
OnClosed?.Invoke();
}
/// <summary>
/// Clear 버튼 클릭 이벤트를 처리합니다.
/// </summary>
private void OnClearButtonClicked()
{
if (_searchField != null && _searchField.value.Length > 0)
{
_searchField.value = string.Empty;
OnSearch(string.Empty);
}
if (_clearButton != null)
{
_clearButton.style.display = DisplayStyle.None;
}
}
#endregion
#region (Search Functionality)
/// <summary>
/// 검색 필드에서 Enter 키를 눌렀을 때 검색을 실행합니다.
@@ -1270,6 +1421,20 @@ namespace UVC.UIToolkit
_treeView.makeItem = null;
}
// 닫기 버튼 이벤트 해제 및 정리
if (_closeButton != null)
{
_closeButton.OnClicked -= OnCloseButtonClicked;
_closeButton.Dispose();
}
// Clear 버튼 이벤트 해제 및 정리
if (_clearButton != null)
{
_clearButton.OnClicked -= OnClearButtonClicked;
_clearButton.Dispose();
}
// 외부 이벤트 구독자 정리
OnItemVisibilityChanged = null;
OnClosed = null;
@@ -1290,6 +1455,7 @@ namespace UVC.UIToolkit
// UI 참조 정리
_searchField = null;
_treeView = null;
_titleLabel = null;
_closeButton = null;
_clearButton = null;
}