Files
XRLib/Assets/Scripts/Factory/FactorySideTabBar.cs
2025-12-12 19:28:20 +09:00

86 lines
3.1 KiB
C#

#nullable enable
using System.Collections.Generic;
using System.Linq;
using UnityEngine;
using UnityEngine.EventSystems;
using UVC.Core;
using UVC.Factory;
using UVC.Factory.Cameras;
using UVC.Factory.Component;
using UVC.UI.List.ComponentList;
using UVC.UI.Tab;
namespace Factory
{
public class FactorySideTabBar : SingletonScene<FactorySideTabBar>, IPointerEnterHandler, IPointerExitHandler
{
[SerializeField]
private TabController? tabController;
protected override void Init()
{
if (tabController == null)
{
Debug.LogError("SideTabBar: TabController가 할당되지 않았습니다.");
return;
}
}
public void InitTab()
{
var infos = FactoryObjectManager.Instance.GetFactoryObjectInfosByCategory();
//SortedDictionary<string, List<ComponentListItemData>>로 변환
SortedDictionary<string, List<ComponentListItemData>> sortedInfos = new SortedDictionary<string, List<ComponentListItemData>>();
foreach (var info in infos)
{
var itemList = info.Value.Select(factoryInfo => new ComponentListItemData
{
Id = factoryInfo.Id,
Name = factoryInfo.Name,
CategoryName = factoryInfo.Category,
Option = factoryInfo.Floor
}).ToList();
sortedInfos.Add(info.Key, itemList);
}
// 1. TabConfig 설정
tabController?.AddTabConfig("Explorer", "탐색기", "Factory/Prefabs/Tab/TabContentComponentListTab", "Prefabs/UI/Images/icon_side_tab_explorer_24", sortedInfos, true);
tabController?.AddTabConfig("Library", "라이브러리", "Factory/Prefabs/Tab/TabContentLibraryGrid", "Prefabs/UI/Images/icon_side_tab_library_24", "라이브러리", true);
// 2. 컨트롤러 초기화
tabController?.Initialize();
if (tabController != null)
{
tabController.OnTabChanged += (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; // 카메라 컨트롤러 활성화
}
}
}