#nullable enable using Cysharp.Threading.Tasks; using System; using System.Collections.Generic; using UnityEngine; using UVC.Core; using UVC.Data.Core; using UVC.Locale; using UVC.Studio.Command; using UVC.Studio.Config; using UVC.Studio.Manager; using UVC.Studio.Modal.Settings; using UVC.UI.Commands; using UVC.UI.Loading; using UVC.UI.Menu; using UVC.UI.Toolbar; using UVC.UI.Toolbar.Model; using UVC.UI.ToolBar; using UVC.UI.Tooltip; using UVC.UI.Window.PropertyWindow; using UVC.Util; using ActionCommand = UVC.UI.Commands.ActionCommand; namespace UVC.Studio { [DefaultExecutionOrder(90)] public class StudioSceneMain : SingletonScene { [SerializeField] private GameObject? stage; /// /// Stage GameObject에 대한 외부 접근 프로퍼티 /// public GameObject? Stage => stage; [Inject] private TopMenuController? topMenu; [Inject] private Toolbox? toolBox; [Inject] private StudioSideTabBar? sideTabBar; [Inject] private PropertyWindow? propertyWindow; [Inject] private Setting? setting; [Inject] private SelectionManager? selectionManager; [Inject] private StageObjectManager? stageObjectManager; // 단축키 관리자 private ShortcutManager? shortcutManager; public Action? Initialized; /// /// 초기 화 메서드입니다. /// Awake 메서드에서 호출되며, MonoBehaviour가 생성될 때 한 번만 실행됩니다. /// protected override void Init() { if (!TooltipManager.Instance.IsInitialized) TooltipManager.Instance.Initialize(); StudioAppMain.Instance.Initialized += OnAppInitialized; } private async void OnAppInitialized() { // 초기화 완료 대기 (Injection이 수행된 후) await InjectorAppContext.Instance.WaitForInitializationAsync(); Initialize(); } private void Initialize() { SetupTopMenu(); SetupToolBox(); SetupShortcutManager(); sideTabBar?.InitTab(); // SelectionManager 기즈모 초기화 if (selectionManager != null) { selectionManager.InitializeGizmos(); } Initialized?.Invoke(); UILoading.Hide(); } private void SetupTopMenu() { if (topMenu == null) { Debug.LogWarning("TopMenuController is not assigned in SceneMain."); return; } // Setting에서 단축키 정보 가져오기 // Scene Injection이 실패할 경우 App 레벨에서 직접 가져오기 Setting? currentSetting = setting; if (currentSetting == null && InjectorAppContext.Instance != null) { currentSetting = InjectorAppContext.Instance.Get(); } MenuShortcuts? menuShortcuts = currentSetting?.Data?.shortcuts?.menu; if (menuShortcuts == null) { Debug.LogWarning("[SetupTopMenu] Setting 또는 shortcuts.menu가 null입니다. 단축키가 표시되지 않습니다."); } // File 메뉴 topMenu.AddMenuItem(new MenuItemData("file", "menu_file", subMenuItems: new List { new MenuItemData("file_new", "menu_file_new", new FileNewCommand(), shortcut: menuShortcuts?.newProject?.GetDisplayString()), new MenuItemData("file_open", "menu_file_open", new FileOpenCommand(), shortcut: menuShortcuts?.openProject?.GetDisplayString()), new MenuItemData("file_save", "menu_file_save", new FileSaveCommand(), shortcut: menuShortcuts?.saveProject?.GetDisplayString()), new MenuItemData("file_saveas", "menu_file_save_as", new FileSaveAsCommand(), shortcut: menuShortcuts?.saveAsProject?.GetDisplayString()), new MenuItemData("file_insert_db", "menu_file_insert_db", new FileInsertDbCommand(), shortcut: menuShortcuts?.insertDb?.GetDisplayString()), new MenuItemData("file_export", "menu_file_export", subMenuItems: new List { new MenuItemData("file_export_layout", "menu_file_export_layout", new FileExportLayoutCommand(), shortcut: menuShortcuts?.exportLayout?.GetDisplayString()), new MenuItemData("file_export_meta", "menu_file_export_meta", new FileExportMetaCommand(), shortcut: menuShortcuts?.exportMeta?.GetDisplayString()), new MenuItemData("file_export_gltf", "menu_file_export_gltf", new FileExportGltfCommand(), shortcut: menuShortcuts?.exportGltf?.GetDisplayString()), }), })); // Edit 메뉴 topMenu.AddMenuItem(new MenuItemData("edit", "menu_edit", subMenuItems: new List { new MenuItemData("edit_undo", "menu_edit_undo", new EditUndoCommand(), shortcut: menuShortcuts?.undo?.GetDisplayString()), new MenuItemData("edit_redo", "menu_edit_redo", new EditRedoCommand(), shortcut: menuShortcuts?.redo?.GetDisplayString()), new MenuItemData("edit_duplicate", "menu_edit_duplicate", new EditDuplicateCommand(selectionManager!, stageObjectManager!), shortcut: menuShortcuts?.duplicate?.GetDisplayString()), new MenuItemData("edit_delete", "menu_edit_delete", new EditDeleteCommand(selectionManager!, stageObjectManager!), shortcut: menuShortcuts?.delete?.GetDisplayString()), new MenuItemData("edit_create_plane", "menu_edit_create_plane", new EditCreatePlaneCommand(stageObjectManager!), shortcut: menuShortcuts?.createPlane?.GetDisplayString()), })); // Setting 메뉴 topMenu.AddMenuItem(new MenuItemData("setting", "menu_setting", subMenuItems: new List { new MenuItemData("setting_db", "menu_setting_db", new SettingOpenCommand("shortcut:Database")), new MenuItemData("setting_general", "menu_setting_general", new SettingOpenCommand("shortcut:General")), new MenuItemData("setting_library", "menu_setting_library", new SettingOpenCommand("shortcut:Library")), new MenuItemData("setting_shortcut", "menu_setting_shortcut", new SettingOpenCommand("shortcut:Shortcut")), })); topMenu.Initialize(); } /// /// Setting에서 단축키가 변경된 후 TopMenu의 단축키를 갱신합니다. /// public void RefreshMenuShortcuts() { if (topMenu == null) return; Setting? currentSetting = setting; if (currentSetting == null && InjectorAppContext.Instance != null) { currentSetting = InjectorAppContext.Instance.Get(); } MenuShortcuts? menuShortcuts = currentSetting?.Data?.shortcuts?.menu; if (menuShortcuts == null) { Debug.LogWarning("[RefreshMenuShortcuts] Setting 또는 shortcuts.menu가 null입니다."); return; } // File 메뉴 단축키 업데이트 topMenu.SetMenuItemShortcut("file_new", menuShortcuts.newProject?.GetDisplayString()); topMenu.SetMenuItemShortcut("file_open", menuShortcuts.openProject?.GetDisplayString()); topMenu.SetMenuItemShortcut("file_save", menuShortcuts.saveProject?.GetDisplayString()); topMenu.SetMenuItemShortcut("file_saveas", menuShortcuts.saveAsProject?.GetDisplayString()); topMenu.SetMenuItemShortcut("file_insert_db", menuShortcuts.insertDb?.GetDisplayString()); topMenu.SetMenuItemShortcut("file_export_layout", menuShortcuts.exportLayout?.GetDisplayString()); topMenu.SetMenuItemShortcut("file_export_meta", menuShortcuts.exportMeta?.GetDisplayString()); topMenu.SetMenuItemShortcut("file_export_gltf", menuShortcuts.exportGltf?.GetDisplayString()); // Edit 메뉴 단축키 업데이트 topMenu.SetMenuItemShortcut("edit_undo", menuShortcuts.undo?.GetDisplayString()); topMenu.SetMenuItemShortcut("edit_redo", menuShortcuts.redo?.GetDisplayString()); topMenu.SetMenuItemShortcut("edit_duplicate", menuShortcuts.duplicate?.GetDisplayString()); topMenu.SetMenuItemShortcut("edit_delete", menuShortcuts.delete?.GetDisplayString()); topMenu.SetMenuItemShortcut("edit_create_plane", menuShortcuts.createPlane?.GetDisplayString()); // ShortcutManager 갱신 shortcutManager?.RefreshShortcuts(); Debug.Log("[RefreshMenuShortcuts] TopMenu 단축키가 갱신되었습니다."); } /// /// 단축키 관리자를 설정합니다. /// private void SetupShortcutManager() { // StudioShortcutManager 생성 또는 가져오기 shortcutManager = ShortcutManager.Instance; if (shortcutManager == null) { var go = new GameObject("StudioShortcutManager"); shortcutManager = go.AddComponent(); DontDestroyOnLoad(go); } // Setting 주입 Setting? currentSetting = setting; if (currentSetting == null && InjectorAppContext.Instance != null) { currentSetting = InjectorAppContext.Instance.Get(); } if (currentSetting != null) { shortcutManager.SetSetting(currentSetting); } // 메뉴 단축키 등록 RegisterMenuShortcuts(); // 도구 단축키 등록 RegisterToolShortcuts(); Debug.Log("[SetupShortcutManager] 단축키 관리자가 설정되었습니다."); } /// /// 메뉴 단축키를 등록합니다. /// private void RegisterMenuShortcuts() { if (shortcutManager == null) return; // File 메뉴 shortcutManager.RegisterMenuShortcut("newProject", new FileNewCommand()); shortcutManager.RegisterMenuShortcut("openProject", new FileOpenCommand()); shortcutManager.RegisterMenuShortcut("saveProject", new FileSaveCommand()); shortcutManager.RegisterMenuShortcut("saveAsProject", new FileSaveAsCommand()); shortcutManager.RegisterMenuShortcut("insertDb", new FileInsertDbCommand()); shortcutManager.RegisterMenuShortcut("exportLayout", new FileExportLayoutCommand()); shortcutManager.RegisterMenuShortcut("exportMeta", new FileExportMetaCommand()); shortcutManager.RegisterMenuShortcut("exportGltf", new FileExportGltfCommand()); // Edit 메뉴 shortcutManager.RegisterMenuShortcut("undo", new EditUndoCommand()); shortcutManager.RegisterMenuShortcut("redo", new EditRedoCommand()); shortcutManager.RegisterMenuShortcut("duplicate", new EditDuplicateCommand(selectionManager!, stageObjectManager!)); shortcutManager.RegisterMenuShortcut("delete", new EditDeleteCommand(selectionManager!, stageObjectManager!)); shortcutManager.RegisterMenuShortcut("createPlane", new EditCreatePlaneCommand(stageObjectManager!)); } /// /// 도구 단축키를 등록합니다. /// private void RegisterToolShortcuts() { if (shortcutManager == null) return; // 도구 단축키 - SelectionManager를 통해 기즈모 제어 shortcutManager.RegisterToolShortcut("select", () => { if (selectionManager != null) selectionManager.SetActiveTool(TransformToolType.Select); if (toolBox != null) toolBox.SetRadioButtonSelection("SizeControlGroup", "Selection Tool"); }); shortcutManager.RegisterToolShortcut("move", () => { if (selectionManager != null) selectionManager.SetActiveTool(TransformToolType.Move); if (toolBox != null) toolBox.SetRadioButtonSelection("SizeControlGroup", "Movement Tool"); }); shortcutManager.RegisterToolShortcut("rotate", () => { if (selectionManager != null) selectionManager.SetActiveTool(TransformToolType.Rotate); if (toolBox != null) toolBox.SetRadioButtonSelection("SizeControlGroup", "Rotation Tool"); }); shortcutManager.RegisterToolShortcut("scale", () => { if (selectionManager != null) selectionManager.SetActiveTool(TransformToolType.Scale); if (toolBox != null) toolBox.SetRadioButtonSelection("SizeControlGroup", "Scale Tool"); }); shortcutManager.RegisterToolShortcut("snap", () => { Debug.Log("[Shortcut] Snap Tool 토글"); if( toolBox != null) toolBox.SetToggleButtonState("button_snap", !toolBox.GetToggleButtonState("button_snap")); }); shortcutManager.RegisterToolShortcut("guide", () => { Debug.Log("[Shortcut] Guide Tool 토글"); if( toolBox != null) toolBox.SetToggleButtonState("button_guide", !toolBox.GetToggleButtonState("button_guide")); }); shortcutManager.RegisterToolShortcut("node", () => { if (toolBox != null) toolBox.SetRadioButtonSelection("NodeControlGroup", "Node Tool"); CursorManager.Instance.SetCursor(CursorType.Node); }); shortcutManager.RegisterToolShortcut("link", () => { if (toolBox != null) toolBox.SetRadioButtonSelection("NodeControlGroup", "Link Tool"); CursorManager.Instance.SetCursor(CursorType.Link); }); shortcutManager.RegisterToolShortcut("arc", () => { if (toolBox != null) toolBox.SetRadioButtonSelection("NodeControlGroup", "Arc Tool"); CursorManager.Instance.SetCursor(CursorType.Arc); }); } private void SetupToolBox() { // ToolbarModel 인스턴스 생성 var toolbarModel = new ToolbarModel(); // --- 툴바 모델 구성 시작 --- // 저장 toolbarModel.AddToggleButton("button_save", false, "Studio/Images/toolbar_icon_save_on_40", "Studio/Images/toolbar_icon_save_off_40", onToggle: (isSelected) => Debug.Log($"화면 녹화 상태: {(isSelected ? "녹화 중" : "중지")} (OnToggle 콜백)"), command: new FileSaveCommand(), tooltip: "tooltip_save"); // undo toolbarModel.AddStandardButton("button_undo", "Studio/Images/toolbar_icon_undo_40", command: new EditUndoCommand(), tooltip: "tooltip_undo"); // redo toolbarModel.AddStandardButton("button_redo", "Studio/Images/toolbar_icon_redo_40", command: new EditRedoCommand(), tooltip: "tooltip_redo"); toolbarModel.AddSeparator(); //select toolbarModel.AddRadioButton("SizeControlGroup", "Selection Tool", true, "Studio/Images/toolbar_icon_select_on_40", "Studio/Images/toolbar_icon_select_off_40", onToggle: (isSelected) => { if (isSelected) Debug.Log("Selection Tool 선택됨"); }, command: new ActionCommand(() => { Debug.Log("Selection Tool Command 실행"); if (selectionManager != null) selectionManager.SetActiveTool(TransformToolType.Select); }), "tooltip_selection_tool"); // move toolbarModel.AddRadioButton("SizeControlGroup", "Movement Tool", false, "Studio/Images/toolbar_icon_move_on_40", "Studio/Images/toolbar_icon_move_off_40", onToggle: (isSelected) => { if (isSelected) Debug.Log("Movement Tool 선택됨"); }, command: new ActionCommand(() => { Debug.Log("Movement Tool Command 실행"); if (selectionManager != null) selectionManager.SetActiveTool(TransformToolType.Move); }), "tooltip_movement_tool"); // rotate toolbarModel.AddRadioButton("SizeControlGroup", "Rotation Tool", false, "Studio/Images/toolbar_icon_rotate_on_40", "Studio/Images/toolbar_icon_rotate_off_40", onToggle: (isSelected) => { if (isSelected) Debug.Log("Rotation Tool 선택됨"); }, command: new ActionCommand(() => { Debug.Log("Rotation Tool Command 실행"); if (selectionManager != null) selectionManager.SetActiveTool(TransformToolType.Rotate); }), "tooltip_rotation_tool"); //scale toolbarModel.AddRadioButton("SizeControlGroup", "Scale Tool", false, "Studio/Images/toolbar_icon_scale_on_40", "Studio/Images/toolbar_icon_scale_off_40", onToggle: (isSelected) => { if (isSelected) Debug.Log("Scale Tool 선택됨"); }, command: new ActionCommand(() => { Debug.Log("Scale Tool Command 실행"); if (selectionManager != null) selectionManager.SetActiveTool(TransformToolType.Scale); }), "tooltip_scale_tool"); toolbarModel.AddSeparator(); //duplicate toolbarModel.AddStandardButton("button_duplicate", "Studio/Images/toolbar_icon_duplicate_40", command: new EditDuplicateCommand(selectionManager!, stageObjectManager!), tooltip: "tooltip_duplicate"); //delete toolbarModel.AddStandardButton("button_delete", "Studio/Images/toolbar_icon_delete_40", command: new EditDeleteCommand(selectionManager!, stageObjectManager!), tooltip: "tooltip_delete"); //align var alignBtnModel = new ToolbarExpandableButton { Text = "button_align", IconSpritePath = "Studio/Images/toolbar_icon_align_40", ClickCommand = new ActionCommand(() => Debug.Log("align 주 버튼 클릭됨 (Command)")), Tooltip = "tooltip_align", UpdateIconOnSelection = false, OnSubButtonSelected = (selectedSubButtonModel) => { // LocalizationManager를 사용하여 텍스트를 현재 언어에 맞게 가져올 수 있습니다. string localizedSubButtonText = LocalizationManager.Instance != null ? LocalizationManager.Instance.GetString(selectedSubButtonModel.Text) : selectedSubButtonModel.Text; Debug.Log($"정렬 옵션 '{localizedSubButtonText}' 선택됨 (OnSubButtonSelected 콜백). 주 버튼 업데이트 로직 실행 가능."); } }; // 확장 버튼 모델에 하위 버튼 추가 alignBtnModel.SubButtons.Add(new ToolbarStandardButton { Text = "horizontal_left", // 하위 버튼 텍스트/키 IconSpritePath = "Studio/Images/toolbar_icon_align_hl_40", // 하위 버튼 아이콘 Tooltip = "tooltip_horizontal_left", // 하위 버튼 툴팁 ClickCommand = new DebugLogCommand("왼쪽 정렬 선택됨 (Sub-Command 실행)") }); alignBtnModel.SubButtons.Add(new ToolbarStandardButton { Text = "horizontal_center", // 하위 버튼 텍스트/키 IconSpritePath = "Studio/Images/toolbar_icon_align_hc_40", // 하위 버튼 아이콘 Tooltip = "tooltip_horizontal_center", // 하위 버튼 툴팁 ClickCommand = new DebugLogCommand("중앙 정렬 선택됨 (Sub-Command 실행)") }); alignBtnModel.SubButtons.Add(new ToolbarStandardButton { Text = "horizontal_right", // 하위 버튼 텍스트/키 IconSpritePath = "Studio/Images/toolbar_icon_align_hr_40", // 하위 버튼 아이콘 Tooltip = "tooltip_horizontal_right", // 하위 버튼 툴팁 ClickCommand = new DebugLogCommand("오른쪽 정렬 선택됨 (Sub-Command 실행)") }); alignBtnModel.SubButtons.Add(new ToolbarStandardButton { Text = "vertical_top", // 하위 버튼 텍스트/키 IconSpritePath = "Studio/Images/toolbar_icon_align_vt_40", // 하위 버튼 아이콘 Tooltip = "tooltip_vertical_top", // 하위 버튼 툴팁 ClickCommand = new DebugLogCommand("위쪽 정렬 선택됨 (Sub-Command 실행)") }); alignBtnModel.SubButtons.Add(new ToolbarStandardButton { Text = "vertical_middle", // 하위 버튼 텍스트/키 IconSpritePath = "Studio/Images/toolbar_icon_align_vm_40", // 하위 버튼 아이콘 Tooltip = "tooltip_vertical_middle", // 하위 버튼 툴팁 ClickCommand = new DebugLogCommand("중앙 정렬 선택됨 (Sub-Command 실행)") }); alignBtnModel.SubButtons.Add(new ToolbarStandardButton { Text = "vertical_bottom", // 하위 버튼 텍스트/키 IconSpritePath = "Studio/Images/toolbar_icon_align_vb_40", // 하위 버튼 아이콘 Tooltip = "tooltip_vertical_bottom", // 하위 버튼 툴팁 ClickCommand = new DebugLogCommand("아래쪽 정렬 선택됨 (Sub-Command 실행)") }); alignBtnModel.SubButtons.Add(new ToolbarStandardButton { Text = "horizontal_even", // 하위 버튼 텍스트/키 IconSpritePath = "Studio/Images/toolbar_icon_align_he_40", // 하위 버튼 아이콘 Tooltip = "tooltip_horizontal_even", // 하위 버튼 툴팁 ClickCommand = new DebugLogCommand("가로 균등 정렬 선택됨 (Sub-Command 실행)") }); alignBtnModel.SubButtons.Add(new ToolbarStandardButton { Text = "vertical_even", // 하위 버튼 텍스트/키 IconSpritePath = "Studio/Images/toolbar_icon_align_ve_40", // 하위 버튼 아이콘 Tooltip = "tooltip_vertical_even", // 하위 버튼 툴팁 ClickCommand = new DebugLogCommand("세로 균등 정렬 선택됨 (Sub-Command 실행)") }); toolbarModel.AddItem(alignBtnModel); //snap toolbarModel.AddToggleButton("button_snap", true, "Studio/Images/toolbar_icon_snap_40", "Studio/Images/toolbar_icon_snap_40", command: new DebugLogCommand("snap 버튼 클릭됨"), tooltip: "tooltip_snap"); //guide toolbarModel.AddToggleButton("button_guide", true, "Studio/Images/toolbar_icon_guide_40", "Studio/Images/toolbar_icon_guide_40", command: new DebugLogCommand("guide 버튼 클릭됨"), tooltip: "tooltip_guide"); toolbarModel.AddSeparator(); //node toolbarModel.AddRadioButton("NodeControlGroup", "Node Tool", false, "Studio/Images/toolbar_icon_node_on_40", "Studio/Images/toolbar_icon_node_off_40", onToggle: (isSelected) => { if (isSelected) Debug.Log("Node Tool 선택됨"); }, command: new ActionCommand(() => CursorManager.Instance.SetCursor(CursorType.Node)), "tooltip_node_tool"); //link toolbarModel.AddRadioButton("NodeControlGroup", "Link Tool", false, "Studio/Images/toolbar_icon_link_on_40", "Studio/Images/toolbar_icon_link_off_40", onToggle: (isSelected) => { if (isSelected) Debug.Log("Link Tool 선택됨"); }, command: new ActionCommand(() => CursorManager.Instance.SetCursor(CursorType.Link)), "tooltip_link_tool"); //arc toolbarModel.AddRadioButton("NodeControlGroup", "Arc Tool", false, "Studio/Images/toolbar_icon_arc_on_40", "Studio/Images/toolbar_icon_arc_off_40", onToggle: (isSelected) => { if (isSelected) Debug.Log("Arc Tool 선택됨"); }, command: new ActionCommand(() => CursorManager.Instance.SetCursor(CursorType.Arc)), "tooltip_arc_tool"); // --- 툴바 모델 구성 끝 --- toolBox?.SetData(toolbarModel); toolBox?.Initialize(); toolBox!.OnAction += (itemModel) => { Debug.Log($"툴박스 아이템 '{itemModel.Text}' 실행됨 (OnAction 콜백). 추가 동작 로직 실행 가능."); if (itemModel.ActionType == ToolbarActionType.Radio) { if (itemModel.Text == "SizeControlGroup") { // 선택, 이동, 회전, 크기 조절 툴 관련 동작 처리 toolBox.ClearRadioButtonSelection("NodeControlGroup"); CursorManager.Instance.SetDefaultCursor(); } else if (itemModel.Text == "NodeControlGroup") { // 노드, 링크, 아크 툴 관련 동작 처리 toolBox.ClearRadioButtonSelection("SizeControlGroup"); } } }; } } }