118 lines
3.9 KiB
C#
118 lines
3.9 KiB
C#
#nullable enable
|
|
using Cysharp.Threading.Tasks;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using UnityEngine;
|
|
using UnityEngine.EventSystems;
|
|
using UVC.Factory;
|
|
using UVC.Factory.Cameras;
|
|
using UVC.Factory.Component;
|
|
using UVC.UI.List.ComponentList;
|
|
using UVC.UI.Tab;
|
|
|
|
namespace Factory.Tab
|
|
{
|
|
public class TabContentComponentListTab : MonoBehaviour, ITabContent, IPointerEnterHandler, IPointerExitHandler
|
|
{
|
|
[SerializeField]
|
|
private TabController? tabController;
|
|
|
|
private SortedDictionary<string, List<ComponentListItemData>>? sortedInfos;
|
|
|
|
protected void Awake()
|
|
{
|
|
if (tabController == null)
|
|
{
|
|
Debug.LogError("TabContentComponentListTab: TabController가 할당되지 않았습니다.");
|
|
return;
|
|
}
|
|
}
|
|
|
|
private void Init()
|
|
{
|
|
if(sortedInfos == null) return;
|
|
|
|
// 1. TabConfig 설정
|
|
tabController?.AddTabConfig("ALL", "ALL", "Factory/Prefabs/Tab/TabContentComponentList", "", sortedInfos, true);
|
|
foreach (var info in sortedInfos)
|
|
{
|
|
//info.Key 카테고리 이름
|
|
tabController?.AddTabConfig(info.Key, info.Key, "Factory/Prefabs/Tab/TabContentComponentList", "", info.Value, true);
|
|
}
|
|
|
|
// 2. 컨트롤러 초기화
|
|
tabController?.Initialize();
|
|
|
|
if (tabController != null)
|
|
{
|
|
tabController.OnTabChanged += OnTabChanged;
|
|
}
|
|
}
|
|
|
|
private void OnTabChanged(int index)
|
|
{
|
|
Debug.Log($"탭이 변경되었습니다: {index}");
|
|
}
|
|
|
|
/// <summary>
|
|
/// 마우스 포인터가 이 UI 요소의 영역 안으로 들어왔을 때 호출됩니다.
|
|
/// UI와 상호작용하는 동안 3D 뷰의 카메라가 움직이지 않도록 컨트롤러를 비활성화합니다.
|
|
/// </summary>
|
|
public virtual void OnPointerEnter(PointerEventData eventData)
|
|
{
|
|
FactoryCameraController.Instance.Enable = false; // 카메라 컨트롤러 비활성화
|
|
}
|
|
|
|
/// <summary>
|
|
/// 마우스 포인터가 이 UI 요소의 영역 밖으로 나갔을 때 호출됩니다.
|
|
/// 카메라 컨트롤을 다시 활성화하여 3D 뷰를 조작할 수 있도록 합니다.
|
|
/// </summary>
|
|
public virtual void OnPointerExit(PointerEventData eventData)
|
|
{
|
|
FactoryCameraController.Instance.Enable = true; // 카메라 컨트롤러 활성화
|
|
}
|
|
|
|
private void OnDestroy()
|
|
{
|
|
if (tabController != null)
|
|
{
|
|
tabController.OnTabChanged -= OnTabChanged;
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 탭 콘텐츠에 데이터를 전달합니다.
|
|
/// </summary>
|
|
/// <param name="data">전달할 데이터 객체</param>
|
|
public void SetContentData(object? data)
|
|
{
|
|
if(data is SortedDictionary<string, List<ComponentListItemData>> sortedData)
|
|
{
|
|
if(sortedInfos == null){
|
|
sortedInfos = sortedData;
|
|
Init();
|
|
}
|
|
}
|
|
|
|
}
|
|
|
|
/// <summary>
|
|
/// 탭 전환 시 데이터가 있는 경우 전달 되는 데이터. SetContentData 이후 호출 됨
|
|
/// </summary>
|
|
/// <param name="data">전달할 데이터 객체</param>
|
|
public void UpdateContentData(object? data)
|
|
{
|
|
}
|
|
|
|
/// <summary>
|
|
/// 닫힐 때 실행되는 로직을 처리합니다.
|
|
/// </summary>
|
|
/// <returns>비동기 닫기 작업을 나타내는 <see cref="UniTask"/>입니다.</returns>
|
|
public UniTask OnCloseAsync()
|
|
{
|
|
Debug.Log("TabContentComponentListTab: OnClose called");
|
|
return UniTask.CompletedTask;
|
|
}
|
|
}
|
|
}
|