using UnityEngine; using UVC.Factory.Modal.ComponentList; using UVC.Factory.Playback; using UVC.Locale; using UVC.UI.Commands; using UVC.UI.Toolbar.Model; using UVC.UI.Toolbar.View; namespace UVC.UI.Toolbar { public class Toolbar : MonoBehaviour { protected ToolbarModel mainToolbar; protected ToolbarView mainToolbarView; protected virtual void Awake() { // 1. 이 GameObject에 연결된 ToolbarView 컴포넌트를 찾습니다. mainToolbarView = GetComponent(); // 2. 만약 현재 GameObject에 없다면, 자식 GameObject들 중에서 ToolbarView 컴포넌트를 찾습니다. if (mainToolbarView == null) { mainToolbarView = GetComponentInChildren(); } } protected virtual void Start() { mainToolbar = new ToolbarModel(); // ToolbarView에 프리팹 설정은 ToolbarView 내부에서 처리하거나 Inspector에서 직접 할당합니다. if (mainToolbarView == null) { Debug.LogError("ToolbarView가 할당되지 않았습니다."); return; } // --- 툴바 모델 구성 --- // 컴포넌트 목록 mainToolbar.AddStandardButton("컴포넌트 목록", "Prefabs/UI/Toolbar/images/ic_menu_elements", new ActionCommand(() => { if (!ComponentList.Instance.gameObject.activeSelf) ComponentList.Instance.gameObject.SetActive(true); ComponentList.Instance.SetupData(); }), "컴포넌트 목록 창을 엽니다."); // 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"); // 화면 녹화 시작/중지 (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((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("화면 축소 버튼 클릭됨")), "화면을 한 단계 축소 합니다."); // 구분선 mainToolbar.AddSeparator(); // RadioButtonGroup 샘플 mainToolbar.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 시점으로 변경합니다."); mainToolbar.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 시점으로 변경합니다."); mainToolbar.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 시점으로 변경합니다."); // 구분선 mainToolbar.AddSeparator(); // 기존 확장 버튼 (예시로 남겨두거나 필요에 따라 수정/제거) var expandableBtnModel = mainToolbar.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 콜백). 주 버튼 업데이트 로직 실행 가능."); }; // --- 툴바 모델 구성 끝 --- // ToolbarView 초기화 및 렌더링 mainToolbarView.Initialize(mainToolbar); // 예시: 모델 상태를 코드로 변경하고 UI가 업데이트되는지 테스트 // StartCoroutine(TestModelChange(saveBtnModel, muteToggleModel)); } // 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; // } } }