Files
XRLib/Assets/Scripts/UVC/UI/ToolBar/Toolbar.cs

163 lines
7.5 KiB
C#
Raw Normal View History

2025-08-05 20:18:01 +09:00
using UnityEngine;
2025-08-11 18:30:13 +09:00
using UVC.UI.List.ComponentList;
2025-08-05 20:18:01 +09:00
using UVC.Factory.Playback;
2025-06-16 19:30:01 +09:00
using UVC.Locale;
using UVC.UI.Commands;
2025-06-18 00:16:49 +09:00
using UVC.UI.Toolbar.Model;
using UVC.UI.Toolbar.View;
2025-09-25 19:58:30 +09:00
using UVC.UI.Window;
2025-06-16 19:30:01 +09:00
namespace UVC.UI.Toolbar
{
2025-06-18 00:16:49 +09:00
public class Toolbar : MonoBehaviour
2025-06-16 19:30:01 +09:00
{
protected ToolbarModel mainToolbar;
protected ToolbarView mainToolbarView;
protected virtual void Awake()
{
// 1. 이 GameObject에 연결된 ToolbarView 컴포넌트를 찾습니다.
mainToolbarView = GetComponent<ToolbarView>();
// 2. 만약 현재 GameObject에 없다면, 자식 GameObject들 중에서 ToolbarView 컴포넌트를 찾습니다.
if (mainToolbarView == null)
{
mainToolbarView = GetComponentInChildren<ToolbarView>();
}
}
protected virtual void Start()
{
mainToolbar = new ToolbarModel();
// ToolbarView에 프리팹 설정은 ToolbarView 내부에서 처리하거나 Inspector에서 직접 할당합니다.
if (mainToolbarView == null)
{
Debug.LogError("ToolbarView가 할당되지 않았습니다.");
return;
}
// --- 툴바 모델 구성 ---
2025-08-05 20:18:01 +09:00
// 컴포넌트 목록
mainToolbar.AddStandardButton("컴포넌트 목록",
"Prefabs/UI/Toolbar/images/ic_menu_elements",
2025-09-25 19:58:30 +09:00
new ActionCommand(() => { if (!ComponentListWindow.Instance.gameObject.activeSelf) ComponentListWindow.Instance.Show(); ComponentListWindow.Instance.SetupData(); }),
2025-08-05 20:18:01 +09:00
"컴포넌트 목록 창을 엽니다.");
// playback
mainToolbar.AddStandardButton("Playback",
"Prefabs/UI/Toolbar/images/ic_menu_playback",
new PlaybackCommand(),
"Playback을 실행 시킵니다.");
// 화면 캡처
mainToolbar.AddStandardButton("button_capture_screen",
"Prefabs/UI/Toolbar/images/ic_menu_capture",
new ActionCommand(() => Debug.Log("화면 캡처 버튼 클릭됨")),
"tooltip_capture_screen");
2025-06-16 19:30:01 +09:00
2025-08-05 20:18:01 +09:00
// 화면 녹화 시작/중지 (ToggleButton)
mainToolbar.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");
// 화면 확대
mainToolbar.AddStandardButton("화면 확대",
"Prefabs/UI/Toolbar/images/ic_menu_zoom_in",
new ActionCommand(() => Debug.Log("화면 확대 버튼 클릭됨")),
"화면을 한 단계 확대 합니다.");
//화면 축소
mainToolbar.AddStandardButton("화면 축소",
"Prefabs/UI/Toolbar/images/ic_menu_zoom_out",
new ActionCommand(() => Debug.Log("화면 축소 버튼 클릭됨")),
"화면을 한 단계 축소 합니다.");
2025-08-06 19:16:41 +09:00
// 구분선
mainToolbar.AddSeparator();
2025-08-05 20:18:01 +09:00
// RadioButtonGroup 샘플
2025-06-16 19:30:01 +09:00
mainToolbar.AddRadioButton("CameraControlGroup", "Top View", true,
"Prefabs/UI/Toolbar/images/ic_camera_top_on",
2025-08-05 20:18:01 +09:00
"Prefabs/UI/Toolbar/images/ic_camera_top_off_white",
2025-06-16 19:30:01 +09:00
(isSelected) => { if (isSelected) Debug.Log("탑뷰 카메라 선택됨"); },
new ActionCommand(() => Debug.Log("탑뷰 카메라 Command 실행")),
"Top View 시점으로 변경합니다.");
mainToolbar.AddRadioButton("CameraControlGroup", "Quarter View", false,
"Prefabs/UI/Toolbar/images/ic_camera_quarter_on",
2025-08-05 20:18:01 +09:00
"Prefabs/UI/Toolbar/images/ic_camera_quarter_off_white",
2025-06-16 19:30:01 +09:00
(isSelected) => { if (isSelected) Debug.Log("쿼터뷰 카메라 선택됨"); },
new ActionCommand(() => Debug.Log("쿼터뷰 카메라 Command 실행")),
"Quarter View 시점으로 변경합니다.");
mainToolbar.AddRadioButton("CameraControlGroup", "Front View", false,
"Prefabs/UI/Toolbar/images/ic_camera_top_on",
2025-08-05 20:18:01 +09:00
"Prefabs/UI/Toolbar/images/ic_camera_top_off_white",
2025-06-16 19:30:01 +09:00
(isSelected) => { if (isSelected) Debug.Log("프런트뷰 카메라 선택됨"); },
new ActionCommand(() => Debug.Log("프런트뷰 카메라 Command 실행")),
"Front View 시점으로 변경합니다.");
2025-08-05 20:18:01 +09:00
// 구분선
2025-06-16 19:30:01 +09:00
mainToolbar.AddSeparator();
// 기존 확장 버튼 (예시로 남겨두거나 필요에 따라 수정/제거)
var expandableBtnModel = mainToolbar.AddExpandableButton("button_brush_size",
"Prefabs/UI/Toolbar/images/ic_brush_default_white",
2025-06-16 19:30:01 +09:00
new ActionCommand(() => Debug.Log("브러시 크기 주 버튼 클릭됨 (Command)")),
"붓 사이즈 선택 합니다.");
var smallBrushCmd = new ActionCommand(() => Debug.Log($"작은 브러시 선택됨"));
2025-06-16 19:30:01 +09:00
var smallBrush = new ToolbarStandardButton
{
Text = "brush_size_small",
IconSpritePath = "Prefabs/UI/Toolbar/images/ic_brush_small_white",
2025-06-18 00:16:49 +09:00
Tooltip = "tooltip_brush_small",
2025-06-16 19:30:01 +09:00
ClickCommand = smallBrushCmd
};
expandableBtnModel.SubButtons.Add(smallBrush);
var mediumBrush = new ToolbarStandardButton
{
Text = "brush_size_medium",
IconSpritePath = "Prefabs/UI/Toolbar/images/ic_brush_medium_white",
2025-06-18 00:16:49 +09:00
Tooltip = "tooltip_brush_medium",
2025-06-16 19:30:01 +09:00
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 콜백). 주 버튼 업데이트 로직 실행 가능.");
};
// --- 툴바 모델 구성 끝 ---
// ToolbarView 초기화 및 렌더링
mainToolbarView.Initialize(mainToolbar);
// 예시: 모델 상태를 코드로 변경하고 UI가 업데이트되는지 테스트
// StartCoroutine(TestModelChange(saveBtnModel, muteToggleModel));
}
2025-08-08 18:33:29 +09:00
2025-06-16 19:30:01 +09:00
// 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;
// }
}
}