Files
XRLib/Assets/Scripts/UVC/UI/ToolBar/Toolbar.cs
2025-12-08 21:06:05 +09:00

198 lines
8.1 KiB
C#

using UnityEngine;
using UVC.UI.List.ComponentList;
using UVC.Factory.Playback;
using UVC.Locale;
using UVC.UI.Commands;
using UVC.UI.Toolbar.Model;
using UVC.UI.Toolbar.View;
using UVC.UI.Window;
using UVC.Factory.Component;
using System.Collections.Generic;
namespace UVC.UI.Toolbar
{
public class Toolbar : MonoBehaviour
{
protected ToolbarModel model;
protected ToolbarView view;
protected void Awake()
{
// 1. 이 GameObject에 연결된 ToolbarView 컴포넌트를 찾습니다.
view = GetComponent<ToolbarView>();
// 2. 만약 현재 GameObject에 없다면, 자식 GameObject들 중에서 ToolbarView 컴포넌트를 찾습니다.
if (view == null)
{
view = GetComponentInChildren<ToolbarView>();
}
}
/// <summary>
/// 툴바 모델을 설정합니다.
/// </summary>
/// <param name="toolbarModel"></param>
public void SetData(ToolbarModel toolbarModel)
{
if (view == null)
{
Debug.LogError("ToolbarView가 할당되지 않았습니다.");
return;
}
model = toolbarModel;
}
/// <summary>
/// 툴바를 초기화합니다.
/// </summary>
public void Initialize()
{
if (view == null)
{
Debug.LogError("ToolbarView가 할당되지 않았습니다.");
return;
}
if (model == null)
{
Debug.LogError("ToolbarModel이 할당되지 않았습니다.");
return;
}
// ToolbarView 초기화 및 렌더링
view.Initialize(model);
}
private ToolbarModel generateModel()
{
var toolbarModel = new ToolbarModel();
// --- 툴바 모델 구성 ---
// 컴포넌트 목록
toolbarModel.AddStandardButton("컴포넌트 목록",
"Prefabs/UI/Toolbar/images/ic_menu_elements",
new ActionCommand(() => {
// if (!ComponentListWindow.Instance.gameObject.activeSelf) ComponentListWindow.Instance.Show();
// var infos = ComponentList.GenerateData();
// ComponentListWindow.Instance.SetupData(infos);
}),
"컴포넌트 목록 창을 엽니다.");
// playback
toolbarModel.AddStandardButton("Playback",
"Prefabs/UI/Toolbar/images/ic_menu_playback",
new PlaybackCommand(),
"Playback을 실행 시킵니다.");
// 화면 캡처
toolbarModel.AddStandardButton("button_capture_screen",
"Prefabs/UI/Toolbar/images/ic_menu_capture",
new ActionCommand(() => Debug.Log("화면 캡처 버튼 클릭됨")),
"tooltip_capture_screen");
// 화면 녹화 시작/중지 (ToggleButton)
toolbarModel.AddToggleButton("button_record_screen", false,
"Prefabs/UI/Toolbar/images/ic_menu_camera_on",
"Prefabs/UI/Toolbar/images/ic_menu_camera_off",
(isSelected) => Debug.Log($"화면 녹화 상태: {(isSelected ? " " : "")} (OnToggle 콜백)"),
new ActionCommand<bool>((isRecording) => Debug.Log($"화면 녹화 Command 실행: {(isRecording ? " " : " ")}")),
"tooltip_record_screen");
// 화면 확대
toolbarModel.AddStandardButton("화면 확대",
"Prefabs/UI/Toolbar/images/ic_menu_zoom_in",
new ActionCommand(() => Debug.Log("화면 확대 버튼 클릭됨")),
"화면을 한 단계 확대 합니다.");
//화면 축소
toolbarModel.AddStandardButton("화면 축소",
"Prefabs/UI/Toolbar/images/ic_menu_zoom_out",
new ActionCommand(() => Debug.Log("화면 축소 버튼 클릭됨")),
"화면을 한 단계 축소 합니다.");
// 구분선
toolbarModel.AddSeparator();
// RadioButtonGroup 샘플
toolbarModel.AddRadioButton("CameraControlGroup", "Top View", true,
"Prefabs/UI/Toolbar/images/ic_camera_top_on",
"Prefabs/UI/Toolbar/images/ic_camera_top_off_white",
(isSelected) => { if (isSelected) Debug.Log("탑뷰 카메라 선택됨"); },
new ActionCommand(() => Debug.Log("탑뷰 카메라 Command 실행")),
"Top View 시점으로 변경합니다.");
toolbarModel.AddRadioButton("CameraControlGroup", "Quarter View", false,
"Prefabs/UI/Toolbar/images/ic_camera_quarter_on",
"Prefabs/UI/Toolbar/images/ic_camera_quarter_off_white",
(isSelected) => { if (isSelected) Debug.Log("쿼터뷰 카메라 선택됨"); },
new ActionCommand(() => Debug.Log("쿼터뷰 카메라 Command 실행")),
"Quarter View 시점으로 변경합니다.");
toolbarModel.AddRadioButton("CameraControlGroup", "Front View", false,
"Prefabs/UI/Toolbar/images/ic_camera_top_on",
"Prefabs/UI/Toolbar/images/ic_camera_top_off_white",
(isSelected) => { if (isSelected) Debug.Log("프런트뷰 카메라 선택됨"); },
new ActionCommand(() => Debug.Log("프런트뷰 카메라 Command 실행")),
"Front View 시점으로 변경합니다.");
// 구분선
toolbarModel.AddSeparator();
// 기존 확장 버튼 (예시로 남겨두거나 필요에 따라 수정/제거)
var expandableBtnModel = toolbarModel.AddExpandableButton("button_brush_size",
"Prefabs/UI/Toolbar/images/ic_brush_default_white",
new ActionCommand(() => Debug.Log("브러시 크기 주 버튼 클릭됨 (Command)")),
"붓 사이즈 선택 합니다.");
var smallBrushCmd = new ActionCommand(() => Debug.Log($"작은 브러시 선택됨"));
var smallBrush = new ToolbarStandardButton
{
Text = "brush_size_small",
IconSpritePath = "Prefabs/UI/Toolbar/images/ic_brush_small_white",
Tooltip = "tooltip_brush_small",
ClickCommand = smallBrushCmd
};
expandableBtnModel.SubButtons.Add(smallBrush);
var mediumBrush = new ToolbarStandardButton
{
Text = "brush_size_medium",
IconSpritePath = "Prefabs/UI/Toolbar/images/ic_brush_medium_white",
Tooltip = "tooltip_brush_medium",
ClickCommand = new ActionCommand(() => Debug.Log("중간 브러시 선택됨 (Sub-Command 실행)"))
};
expandableBtnModel.SubButtons.Add(mediumBrush);
expandableBtnModel.OnSubButtonSelected = (selectedSubButtonModel) =>
{
string localizedSubButtonText = LocalizationManager.Instance != null ? LocalizationManager.Instance.GetString(selectedSubButtonModel.Text) : selectedSubButtonModel.Text;
Debug.Log($"브러시 크기 '{localizedSubButtonText}' 선택됨 (OnSubButtonSelected 콜백). 주 버튼 업데이트 로직 실행 가능.");
};
// --- 툴바 모델 구성 끝 ---
return toolbarModel;
}
protected void OnDestroy()
{
model = null;
view = null;
}
// System.Collections.IEnumerator TestModelChange(ToolbarStandardButton standard, ToolbarToggleButton toggle)
// {
// yield return new WaitForSeconds(2f);
// Debug.Log("모델 변경 테스트: 저장 버튼 비활성화 및 텍스트 변경");
// standard.Text = "저장됨";
// standard.IsEnabled = false;
//
// yield return new WaitForSeconds(2f);
// Debug.Log("모델 변경 테스트: 음소거 토글 상태 변경");
// toggle.IsSelected = true;
// }
}
}