#nullable enable using System; using System.Collections.Generic; using UnityEngine; using UnityEngine.UIElements; using UVC.UIToolkit.List; namespace UVC.UIToolkit.Window { /// /// UTKComponentList를 래핑하여 윈도우 형태로 제공하는 컴포넌트입니다. /// /// 개요: /// /// UTKComponentListWindow는 UTKComponentList를 내부에 포함하고 헤더(타이틀, 닫기 버튼)를 추가한 /// 윈도우 형태의 컴포넌트입니다. 모든 트리 관련 기능은 내부 UTKComponentList에 위임됩니다. /// /// /// UXML에서 사용: /// /// /// /// /// 코드에서 사용: /// /// var window = root.Q(); /// window.OnItemSelected += (items) => Debug.Log($"선택: {items[0].name}"); /// window.SetData(treeItems); /// /// [UxmlElement] public partial class UTKComponentListWindow : VisualElement, IDisposable { #region IDisposable private bool _disposed = false; #endregion #region 상수 (Constants) /// 메인 UXML 파일 경로 (Resources 폴더 기준) private const string UXML_PATH = "UIToolkit/Window/UTKComponentListWindow"; #endregion #region UI 컴포넌트 참조 (UI Component References) /// 내부 UTKComponentList 컴포넌트 private UTKComponentList? _componentList; /// 트리 리스트 닫기 버튼 private Button? _closeButton; #endregion #region 공개 속성 (Public Properties) /// /// 항목 삭제 기능 활성화 여부입니다. /// true일 때만 Delete/Backspace 키로 항목 삭제 이벤트가 발생합니다. /// 기본값은 false입니다. /// public bool EnabledDeleteItem { get => _componentList?.EnabledDeleteItem ?? false; set { if (_componentList != null) _componentList.EnabledDeleteItem = value; } } #endregion #region 외부 이벤트 (Public Events) /// /// 메인/검색 리스트에서 항목이 선택될 때 발생합니다. /// public Action>? OnItemSelected { get => _componentList?.OnItemSelected; set { if (_componentList != null) _componentList.OnItemSelected = value; } } /// /// 메인/검색 리스트에서 항목이 선택 해제될 때 발생합니다. /// public Action>? OnItemDeselected { get => _componentList?.OnItemDeselected; set { if (_componentList != null) _componentList.OnItemDeselected = value; } } /// /// 항목의 가시성(눈 아이콘)이 변경될 때 발생합니다. /// public event Action? OnItemVisibilityChanged { add { if (_componentList != null) _componentList.OnItemVisibilityChanged += value; } remove { if (_componentList != null) _componentList.OnItemVisibilityChanged -= value; } } /// /// 메인/검색 리스트에서 항목이 삭제될 때 발생합니다 (Delete 키). /// public Action? OnItemDeleted { get => _componentList?.OnItemDeleted; set { if (_componentList != null) _componentList.OnItemDeleted = value; } } /// /// 메인/검색 리스트에서 항목이 더블클릭될 때 발생합니다. /// public Action? OnItemDoubleClicked { get => _componentList?.OnItemDoubleClicked; set { if (_componentList != null) _componentList.OnItemDoubleClicked = value; } } /// /// 아이콘을 클릭할 때 발생합니다. /// public Action? OnItemIconClicked { get => _componentList?.OnItemIconClicked; set { if (_componentList != null) _componentList.OnItemIconClicked = value; } } /// /// 트리 리스트가 닫힐 때(숨겨질 때) 발생합니다. /// 닫기 버튼 클릭 시 트리거됩니다. /// public event Action? OnClosed; #endregion #region 생성자 (Constructor) /// /// UTKComponentListWindow 컴포넌트를 초기화합니다. /// UXML 템플릿을 로드하고 내부 UTKComponentList를 설정합니다. /// public UTKComponentListWindow() { // 1. 메인 UXML 로드 및 복제 var visualTree = Resources.Load(UXML_PATH); if (visualTree == null) { Debug.LogError($"[UTKComponentListWindow] UXML not found at: {UXML_PATH}"); return; } visualTree.CloneTree(this); // 2. 내부 UTKComponentList 찾기 (UXML의 ui:Instance로 생성된 컴포넌트) _componentList = this.Q(); if (_componentList == null) { Debug.LogError("[UTKComponentListWindow] UTKComponentList not found in UXML"); return; } // 3. 닫기 버튼 찾기 및 이벤트 연결 _closeButton = this.Q