#nullable enable using Cysharp.Threading.Tasks; using System; using System.Collections.Generic; using UnityEngine; using UVC.UI.List.ComponentList; using UVC.UI.Tab; namespace UVC.UI.Window { public class ComponentListTabWindow : MonoBehaviour, ITabContent, IDisposable { [SerializeField] private TabController? tabController; private SortedDictionary> data = new SortedDictionary>(); private bool _isDisposed = false; protected void Awake() { if (tabController == null) { Debug.LogError("TabContentTabComponentList: TabController가 할당되지 않았습니다."); return; } } /// /// 탭 콘텐츠에 데이터를 전달합니다. /// /// public void SetupData(SortedDictionary> objectsData) { data = objectsData; // 1. TabConfig 설정 tabController?.AddTabConfig("ALL", "ALL", "Prefabs/UI/List/ComponentList", "", objectsData, true); foreach (var info in objectsData) { //info.Key 카테고리 이름 tabController?.AddTabConfig(info.Key, info.Key, "Prefabs/UI/List/ComponentList", "", info.Value, true); } // 2. 컨트롤러 초기화 tabController?.Initialize(); if (tabController != null) { tabController.OnTabChanged += OnTabChanged; } } private void OnTabChanged(int index) { Debug.Log($"탭이 변경되었습니다: {index}"); } /// /// 탭 콘텐츠에 데이터를 전달합니다. /// /// 전달할 데이터 객체 public void SetContentData(object? data) { Debug.Log("TabContentTabComponentList: SetContentData called"); } /// /// 탭 전환 시 데이터가 있는 경우 전달 되는 데이터. SetContentData 이후 호출 됨 /// /// 전달할 데이터 객체 public void UpdateContentData(object? data) { } /// /// 닫힐 때 실행되는 로직을 처리합니다. /// /// 비동기 닫기 작업을 나타내는 입니다. public UniTask OnCloseAsync() { Debug.Log("TabContentTabComponentList: OnClose called"); return UniTask.CompletedTask; } /// /// 메모리 정리를 수행합니다. /// public void Dispose() { if (_isDisposed) return; // 이벤트 핸들러 해제 if (tabController != null) { tabController.OnTabChanged -= OnTabChanged; } // 데이터 정리 data.Clear(); _isDisposed = true; } private void OnDestroy() { Dispose(); } } }