Files
EnglewoodLAB/Assets/Scripts/UI/LeftSidePanel.cs
2026-03-09 17:00:30 +09:00

153 lines
5.5 KiB
C#

using UnityEngine;
using Cysharp.Threading.Tasks;
using UVC.UI.Toolbar;
using UVC.UI.Toolbar.Model;
using UVC.UI.Commands;
using EnglewoodLAB.Management;
using EnglewoodLAB.Command;
namespace EnglewoodLAB.UI
{
public class LeftSidePanel : UIPanel
{
[SerializeField]
private Toolbar toolbar;
[SerializeField]
private BottomLeftToolbar bottomLeftToolBar;
[SerializeField]
private SideTabBar sideTabBar;
public SideTabBar SideTabBar { get { return sideTabBar; } }
public bool isActive;
public override async UniTask Init()
{
bool hasError = false;
toolbar = transform.GetComponentInChildren<Toolbar>();
if (toolbar == null)
{
Debug.LogError("[LeftSidePanel] Prefab Error: 'Toolbar' component not found in children. Please check the prefab structure.", this.gameObject);
hasError = true;
}
bottomLeftToolBar = transform.GetComponentInChildren<BottomLeftToolbar>();
if (bottomLeftToolBar == null)
{
Debug.LogError("[LeftSidePanel] Prefab Error: 'BottomLeftToolbar' component not found in children. Please check the prefab structure.", this.gameObject);
hasError = true;
}
sideTabBar = transform.GetComponentInChildren<SideTabBar>();
if (sideTabBar == null)
{
Debug.LogError("[LeftSidePanel] Prefab Error: 'SideTabBar' component not found in children. Please check the prefab structure.", this.gameObject);
hasError = true;
}
if (hasError)
{
// Stop further execution if components are missing
return;
}
// Initialize the child component before using it
await bottomLeftToolBar.Init();
SetupToolBox();
await UniTask.CompletedTask;
}
private void SetupToolBox()
{
// 1. 탭 정의 및 초기화
sideTabBar.InitTab();
// 2. TabController 가져오기
var tabController = sideTabBar.TabController;
if(tabController == null)
{
Debug.LogError("[LeftSidePanel] TabController not found on SideTabBar!", sideTabBar);
return;
}
// 3. 상단 툴바 모델 생성 (TabController에서 "Setting" 탭을 제외하고 동적으로 생성)
var toolbarModel = new ToolbarModel();
var allTabs = tabController.GetAllTabConfigs();
foreach (var tabConfig in allTabs)
{
// "Setting" 탭은 하단 툴바에서 별도로 처리하므로 여기서는 건너뜁니다.
if (tabConfig.tabID == "Setting") continue;
toolbarModel.AddStandardButton(
tabConfig.tabName,
tabConfig.tabIconPath,
new ActivateTabCommand(tabController, tabConfig.tabID),
null
);
}
toolbar.SetData(toolbarModel);
toolbar.Initialize();
// 4. 하단 툴바 모델 생성
var bottomLeftToolbarModel = new ToolbarModel();
// 메뉴 여닫기
bottomLeftToolbarModel.AddToggleButton("메뉴 열기", false,
"UI/Sprites/ic-tabClose",
"UI/Sprites/ic-tabOpen",
(isSelected) =>
{
var tabView = sideTabBar.GetComponentInChildren<UVC.UI.Tab.TabView>();
if (tabView != null)
{
tabView.ToggleMenuSizeAsync(isSelected).Forget();
}
},
null,
"사이드 패널을 열고 닫습니다.");
// 층 선택
bottomLeftToolbarModel.AddCameraRadioButton("CameraController", "Floor Controller", false,
"UI/Sprites/IMG_FloorController_on",
"UI/Sprites/IMG_FloorController_off",
(isSelected) =>
{
var floorControl = SceneMain.Instance.uiManager.GetCanvas<PopupCanvas>().GetPanel<FloorControlPanel>();
if (!isSelected)
{
floorControl.Close();
}
else
{
floorControl.Open();
}
},
new ActionCommand(() => { Debug.Log("층 전환 버튼 클릭"); }),
"층 조절 UI를 활성화/비활성화 합니다.");
// 설정 (Tab ID: "Setting")
bottomLeftToolbarModel.AddStandardButton("설정",
"UI/Sprites/ic-setting",
new ActivateTabCommand(tabController, "Setting"),
null
);
if (bottomLeftToolBar.view == null)
{
Debug.LogError("[LeftSidePanel] Prefab Error: The 'view' field on the 'BottomLeftToolbar' component is not assigned. Please assign it in the Unity Inspector.", bottomLeftToolBar);
return;
}
bottomLeftToolBar.view.Initialize(bottomLeftToolbarModel);
}
public void DeactiveSideToolButton()
{
toolbar.SetToggleButtonState("button_icon_control", false, true);
toolbar.SetRadioButtonSelection("CameraControlGroup", "Quarter View", true);
}
}
}