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; // 테스트용 버튼 참조 private ToolbarToggleButton _toolbarToggleButton; private ToolbarRadioButton _toolbarTopViewRadio; private ToolbarRadioButton _toolbarQuarterViewRadio; private ToolbarRadioButton _toolbarFrontViewRadio; private ToolbarToggleButton _toolboxToggleButton; private ToolbarRadioButton _toolboxTopViewRadio; private ToolbarRadioButton _toolboxQuarterViewRadio; private ToolbarRadioButton _toolboxFrontViewRadio; private const string CAMERA_GROUP_NAME = "CameraControlGroup"; // 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(); // OnAction 이벤트 구독 toolbar.OnAction += OnToolbarAction; toolBox.OnAction += OnToolboxAction; } void OnDestroy() { // 이벤트 구독 해제 if (toolbar != null) toolbar.OnAction -= OnToolbarAction; if (toolBox != null) toolBox.OnAction -= OnToolboxAction; } /// /// Toolbar의 OnAction 이벤트 핸들러 /// private void OnToolbarAction(ToolbarActionEventArgs args) { Debug.Log($"[Toolbar OnAction] ActionType: {args.ActionType}, Text: {args.Text}, Value: {args.Value}"); } /// /// Toolbox의 OnAction 이벤트 핸들러 /// private void OnToolboxAction(ToolbarActionEventArgs args) { Debug.Log($"[Toolbox OnAction] ActionType: {args.ActionType}, Text: {args.Text}, Value: {args.Value}"); } void Update() { // 테스트용 키 입력 처리 HandleTestInputs(); } /// /// 테스트용 키 입력을 처리합니다. /// private void HandleTestInputs() { // === Toolbar 테스트 === // 1: TopView 선택 (이벤트 발생) if (Input.GetKeyDown(KeyCode.Alpha1)) { Debug.Log("[Test] Toolbar: TopView 선택 (raiseEvent=true)"); toolbar.SetRadioButtonSelection(CAMERA_GROUP_NAME, _toolbarTopViewRadio, true); } // 2: QuarterView 선택 (이벤트 발생) if (Input.GetKeyDown(KeyCode.Alpha2)) { Debug.Log("[Test] Toolbar: QuarterView 선택 (raiseEvent=true)"); toolbar.SetRadioButtonSelection(CAMERA_GROUP_NAME, _toolbarQuarterViewRadio, true); } // 3: FrontView 선택 (이벤트 없이) if (Input.GetKeyDown(KeyCode.Alpha3)) { Debug.Log("[Test] Toolbar: FrontView 선택 (raiseEvent=false)"); toolbar.SetRadioButtonSelection(CAMERA_GROUP_NAME, _toolbarFrontViewRadio, false); } // 4: 라디오 버튼 선택 해제 (이벤트 발생) if (Input.GetKeyDown(KeyCode.Alpha4)) { Debug.Log("[Test] Toolbar: 라디오 버튼 선택 해제 (raiseEvent=true)"); toolbar.ClearRadioButtonSelection(CAMERA_GROUP_NAME, true); } // 5: 라디오 버튼 선택 해제 (이벤트 없이) if (Input.GetKeyDown(KeyCode.Alpha5)) { Debug.Log("[Test] Toolbar: 라디오 버튼 선택 해제 (raiseEvent=false)"); toolbar.ClearRadioButtonSelection(CAMERA_GROUP_NAME, false); } // T: 토글 버튼 ON (이벤트 발생) if (Input.GetKeyDown(KeyCode.T)) { Debug.Log("[Test] Toolbar: 토글 버튼 ON (raiseEvent=true)"); toolbar.SetToggleButtonState(_toolbarToggleButton, true, true); } // Y: 토글 버튼 OFF (이벤트 발생) if (Input.GetKeyDown(KeyCode.Y)) { Debug.Log("[Test] Toolbar: 토글 버튼 OFF (raiseEvent=true)"); toolbar.SetToggleButtonState(_toolbarToggleButton, false, true); } // U: 토글 버튼 ON (이벤트 없이) if (Input.GetKeyDown(KeyCode.U)) { Debug.Log("[Test] Toolbar: 토글 버튼 ON (raiseEvent=false)"); toolbar.SetToggleButtonState(_toolbarToggleButton, true, false); } // I: 토글 버튼 OFF (이벤트 없이) if (Input.GetKeyDown(KeyCode.I)) { Debug.Log("[Test] Toolbar: 토글 버튼 OFF (raiseEvent=false)"); toolbar.SetToggleButtonState(_toolbarToggleButton, false, false); } // === Toolbox 테스트 === // Q: TopView 선택 (이벤트 발생) if (Input.GetKeyDown(KeyCode.Q)) { Debug.Log("[Test] Toolbox: TopView 선택 (raiseEvent=true)"); toolBox.SetRadioButtonSelection(CAMERA_GROUP_NAME, _toolboxTopViewRadio, true); } // W: QuarterView 선택 (이벤트 없이) if (Input.GetKeyDown(KeyCode.W)) { Debug.Log("[Test] Toolbox: QuarterView 선택 (raiseEvent=false)"); toolBox.SetRadioButtonSelection(CAMERA_GROUP_NAME, _toolboxQuarterViewRadio, false); } // E: 라디오 버튼 선택 해제 (이벤트 발생) if (Input.GetKeyDown(KeyCode.E)) { Debug.Log("[Test] Toolbox: 라디오 버튼 선택 해제 (raiseEvent=true)"); toolBox.ClearRadioButtonSelection(CAMERA_GROUP_NAME, true); } // R: 토글 버튼 토글 (이벤트 발생) if (Input.GetKeyDown(KeyCode.R)) { bool newState = !_toolboxToggleButton.IsSelected; Debug.Log($"[Test] Toolbox: 토글 버튼 -> {newState} (raiseEvent=true)"); toolBox.SetToggleButtonState(_toolboxToggleButton, newState, true); } // F: 토글 버튼 토글 (이벤트 없이) if (Input.GetKeyDown(KeyCode.F)) { bool newState = !_toolboxToggleButton.IsSelected; Debug.Log($"[Test] Toolbox: 토글 버튼 -> {newState} (raiseEvent=false)"); toolBox.SetToggleButtonState(_toolboxToggleButton, newState, false); } // === Text 기반 API 테스트 === // 6: Text로 TopView 선택 (이벤트 발생) if (Input.GetKeyDown(KeyCode.Alpha6)) { Debug.Log("[Test] Toolbar: Text로 'Top View' 선택 (raiseEvent=true)"); toolbar.SetRadioButtonSelection(CAMERA_GROUP_NAME, "Top View", true); } // 7: Text로 QuarterView 선택 (이벤트 없이) if (Input.GetKeyDown(KeyCode.Alpha7)) { Debug.Log("[Test] Toolbar: Text로 'Quarter View' 선택 (raiseEvent=false)"); toolbar.SetRadioButtonSelection(CAMERA_GROUP_NAME, "Quarter View", false); } // 8: Text로 라디오 버튼 선택 해제 (빈 문자열) if (Input.GetKeyDown(KeyCode.Alpha8)) { Debug.Log("[Test] Toolbar: Text로 라디오 버튼 선택 해제 (raiseEvent=true)"); toolbar.SetRadioButtonSelection(CAMERA_GROUP_NAME, "", true); } // 9: Text로 토글 버튼 ON if (Input.GetKeyDown(KeyCode.Alpha9)) { Debug.Log("[Test] Toolbar: Text로 토글 버튼 ON (raiseEvent=true)"); toolbar.SetToggleButtonState("button_record_screen", true, true); } // 0: Text로 토글 버튼 OFF if (Input.GetKeyDown(KeyCode.Alpha0)) { Debug.Log("[Test] Toolbar: Text로 토글 버튼 OFF (raiseEvent=true)"); toolbar.SetToggleButtonState("button_record_screen", false, true); } // H: 도움말 출력 if (Input.GetKeyDown(KeyCode.H)) { PrintHelp(); } } /// /// 테스트 키 도움말을 출력합니다. /// private void PrintHelp() { Debug.Log("=== Toolbar/Toolbox 테스트 키 도움말 ==="); Debug.Log("--- Toolbar 라디오 버튼 (객체 참조) ---"); Debug.Log("1: TopView 선택 (이벤트 O)"); Debug.Log("2: QuarterView 선택 (이벤트 O)"); Debug.Log("3: FrontView 선택 (이벤트 X)"); Debug.Log("4: 선택 해제 (이벤트 O)"); Debug.Log("5: 선택 해제 (이벤트 X)"); Debug.Log("--- Toolbar 라디오/토글 버튼 (Text 기반) ---"); Debug.Log("6: Text로 TopView 선택 (이벤트 O)"); Debug.Log("7: Text로 QuarterView 선택 (이벤트 X)"); Debug.Log("8: Text로 선택 해제 (이벤트 O)"); Debug.Log("9: Text로 토글 ON (이벤트 O)"); Debug.Log("0: Text로 토글 OFF (이벤트 O)"); Debug.Log("--- Toolbar 토글 버튼 (객체 참조) ---"); Debug.Log("T: ON (이벤트 O)"); Debug.Log("Y: OFF (이벤트 O)"); Debug.Log("U: ON (이벤트 X)"); Debug.Log("I: OFF (이벤트 X)"); Debug.Log("--- Toolbox ---"); Debug.Log("Q: TopView 선택 (이벤트 O)"); Debug.Log("W: QuarterView 선택 (이벤트 X)"); Debug.Log("E: 선택 해제 (이벤트 O)"); Debug.Log("R: 토글 버튼 토글 (이벤트 O)"); Debug.Log("F: 토글 버튼 토글 (이벤트 X)"); Debug.Log("H: 이 도움말 출력"); } 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) - 참조 저장 _toolbarToggleButton = 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((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 샘플 - 참조 저장 _toolbarTopViewRadio = 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 시점으로 변경합니다."); _toolbarQuarterViewRadio = 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 시점으로 변경합니다."); _toolbarFrontViewRadio = 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) - 참조 저장 _toolboxToggleButton = 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((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 샘플 - 참조 저장 _toolboxTopViewRadio = 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 시점으로 변경합니다."); _toolboxQuarterViewRadio = 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 시점으로 변경합니다."); _toolboxFrontViewRadio = 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; } }