using UnityEngine; using UVC.Locale; namespace UVC.UI.ToolBar { public class ToolbarManager : MonoBehaviour { public Toolbar mainToolbar; public ToolbarView mainToolbarView; // Unity 에디터에서 할당 public Transform toolbarContainer; // Unity 에디터에서 할당 (툴바 UI가 생성될 부모) // 여기에 HorizontalLayoutGroup 또는 VerticalLayoutGroup을 추가하는 것을 권장합니다. // 버튼 프리팹들은 ToolbarView로 옮겨서 관리하는 것이 더 깔끔할 수 있습니다. // 현재는 ToolbarManager에서 할당하여 ToolbarView로 전달하는 방식입니다. public GameObject standardButtonPrefab; public GameObject toggleButtonPrefab; public GameObject radioButtonPrefab; public GameObject expandableButtonPrefab; public GameObject separatorPrefab; public GameObject subMenuPanelPrefab; void Start() { mainToolbar = new Toolbar(); // ToolbarView에 프리팹 설정 if (mainToolbarView != null) { mainToolbarView.standardButtonPrefab = standardButtonPrefab; mainToolbarView.toggleButtonPrefab = toggleButtonPrefab; mainToolbarView.radioButtonPrefab = radioButtonPrefab; mainToolbarView.expandableButtonPrefab = expandableButtonPrefab; mainToolbarView.separatorPrefab = separatorPrefab; mainToolbarView.subMenuPanelPrefab = subMenuPanelPrefab; } else { Debug.LogError("ToolbarView가 할당되지 않았습니다."); return; } // --- 툴바 모델 구성 --- // "저장" 대신 다국어 키 "button_save" 사용 mainToolbar.AddStandardButton("button_save", null, () => Debug.Log("저장 버튼 클릭됨"), "tooltip_save_button"); // "음소거" 대신 다국어 키 "button_mute" 사용 mainToolbar.AddToggleButton("button_mute", false, null, (isSelected) => Debug.Log($"음소거: {isSelected}"), "tooltip_mute_button"); mainToolbar.AddSeparator(); // "펜" 대신 다국어 키 "tool_pen" 사용 mainToolbar.AddRadioButton("ToolGroup", "tool_pen", true, null, (isSelected) => { if (isSelected) Debug.Log("펜 도구 선택됨"); }, "tooltip_pen_tool"); // "지우개" 대신 다국어 키 "tool_eraser" 사용 mainToolbar.AddRadioButton("ToolGroup", "tool_eraser", false, null, (isSelected) => { if (isSelected) Debug.Log("지우개 도구 선택됨"); }, "tooltip_eraser_tool"); mainToolbar.AddSeparator(); // "브러시 크기" 대신 다국어 키 "button_brush_size" 사용 var expandableBtnModel = mainToolbar.AddExpandableButton("button_brush_size", null, null, "tooltip_brush_size"); // 하위 버튼도 다국어 키 사용 var smallBrush = new ToolbarStandardButton { Text = "brush_size_small", TooltipKey = "tooltip_brush_small" }; expandableBtnModel.SubButtons.Add(smallBrush); expandableBtnModel.SubButtons.Add(new ToolbarStandardButton { Text = "brush_size_medium", TooltipKey = "tooltip_brush_medium" }); expandableBtnModel.OnSubButtonSelected = (selectedSubButton) => { // selectedSubButton.Text 에는 이제 다국어 키가 들어있습니다. // 실제 표시된 텍스트를 로그로 남기려면 LocalizationManager를 사용해야 합니다. string localizedSubButtonText = LocalizationManager.Instance != null ? LocalizationManager.Instance.GetString(selectedSubButton.Text) : selectedSubButton.Text; Debug.Log($"브러시 크기 '{localizedSubButtonText}' 선택됨 (주 버튼 업데이트)"); }; // --- 툴바 모델 구성 끝 --- // ToolbarView 초기화 및 렌더링 if (toolbarContainer != null) { mainToolbarView.Initialize(mainToolbar, toolbarContainer); } else { Debug.LogError("ToolbarContainer가 할당되지 않았습니다."); } // 예시: 모델 상태를 코드로 변경하고 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; // } } }