220 lines
11 KiB
C#
220 lines
11 KiB
C#
|
|
using UnityEngine;
|
||
|
|
using UVC.Locale;
|
||
|
|
using UVC.UI.Commands;
|
||
|
|
using UVC.UI.Toolbar;
|
||
|
|
using UVC.UI.Toolbar.Model;
|
||
|
|
using UVC.UI.ToolBar;
|
||
|
|
|
||
|
|
public class ToolBarSample : MonoBehaviour
|
||
|
|
{
|
||
|
|
|
||
|
|
[SerializeField]
|
||
|
|
private Toolbar toolbar;
|
||
|
|
|
||
|
|
[SerializeField]
|
||
|
|
private Toolbox toolBox;
|
||
|
|
|
||
|
|
// Start is called once before the first execution of Update after the MonoBehaviour is created
|
||
|
|
void Start()
|
||
|
|
{
|
||
|
|
ToolbarModel toolbarModel = generateToolBarModel();
|
||
|
|
toolbar.SetData(toolbarModel);
|
||
|
|
toolbar.Initialize();
|
||
|
|
|
||
|
|
ToolbarModel toolBoxModel = generateToolBoxModel();
|
||
|
|
toolBox.SetData(toolBoxModel);
|
||
|
|
toolBox.Initialize();
|
||
|
|
}
|
||
|
|
|
||
|
|
private ToolbarModel generateToolBarModel()
|
||
|
|
{
|
||
|
|
var toolbarModel = new ToolbarModel();
|
||
|
|
|
||
|
|
// --- 툴바 모델 구성 ---
|
||
|
|
|
||
|
|
// 화면 캡처
|
||
|
|
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;
|
||
|
|
}
|
||
|
|
|
||
|
|
private ToolbarModel generateToolBoxModel()
|
||
|
|
{
|
||
|
|
// ToolbarModel 인스턴스 생성
|
||
|
|
var toolbarModel = new ToolbarModel();
|
||
|
|
|
||
|
|
// --- 툴바 모델 구성 시작 ---
|
||
|
|
|
||
|
|
// 화면 캡처
|
||
|
|
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();
|
||
|
|
|
||
|
|
// 예시 : 확장 버튼 (브러시 크기 선택)
|
||
|
|
// AddExpandableButton으로 주 버튼을 만들고, 반환된 객체의 SubButtons 리스트에 하위 버튼들을 추가합니다.
|
||
|
|
var expandableBtnModel = toolbarModel.AddExpandableButton("button_brush_size", // 주 버튼 텍스트/키
|
||
|
|
"Prefabs/UI/Toolbar/images/ic_brush_default_white", // 주 버튼 기본 아이콘
|
||
|
|
new ActionCommand(() => Debug.Log("브러시 크기 주 버튼 클릭됨 (Command)")), // 주 버튼 자체의 커맨드
|
||
|
|
"붓 사이즈 선택 합니다."); // 주 버튼 툴팁
|
||
|
|
|
||
|
|
// 하위 버튼1: 작은 브러시 (ToolbarStandardButton 사용)
|
||
|
|
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); // 확장 버튼 모델에 하위 버튼 추가
|
||
|
|
|
||
|
|
// 하위 버튼2: 중간 브러시
|
||
|
|
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) =>
|
||
|
|
{
|
||
|
|
// LocalizationManager를 사용하여 텍스트를 현재 언어에 맞게 가져올 수 있습니다.
|
||
|
|
string localizedSubButtonText = LocalizationManager.Instance != null ? LocalizationManager.Instance.GetString(selectedSubButtonModel.Text) : selectedSubButtonModel.Text;
|
||
|
|
Debug.Log($"브러시 크기 '{localizedSubButtonText}' 선택됨 (OnSubButtonSelected 콜백). 주 버튼 업데이트 로직 실행 가능.");
|
||
|
|
};
|
||
|
|
// --- 툴바 모델 구성 끝 ---
|
||
|
|
|
||
|
|
return toolbarModel;
|
||
|
|
}
|
||
|
|
}
|