Files
XRLib/Assets/Scripts/Studio/StudioSceneMain.cs
2025-12-16 20:31:27 +09:00

436 lines
20 KiB
C#

using Cysharp.Threading.Tasks;
using System;
using System.Collections.Generic;
using UnityEngine;
using UVC.Core;
using UVC.Data;
using UVC.Data.Core;
using UVC.Locale;
using UVC.Studio.Modal.Settings;
using UVC.UI.Commands;
using UVC.UI.Loading;
using UVC.UI.Menu;
using UVC.UI.Modal;
using UVC.UI.Toolbar.Model;
using UVC.UI.ToolBar;
using UVC.UI.Tooltip;
using UVC.UI.Window.PropertyWindow;
namespace UVC.Studio
{
[DefaultExecutionOrder(90)]
public class StudioSceneMain : SingletonScene<StudioSceneMain>
{
[Inject]
private TopMenuController topMenu;
[Inject]
private Toolbox toolBox;
[Inject]
private StudioSideTabBar sideTabBar;
[Inject]
private PropertyWindow propertyWindow;
public Action Initialized;
/// <summary>
/// 초기 화 메서드입니다.
/// Awake 메서드에서 호출되며, MonoBehaviour가 생성될 때 한 번만 실행됩니다.
/// </summary>
protected override void Init()
{
if (!TooltipManager.Instance.IsInitialized) TooltipManager.Instance.Initialize();
StudioAppMain.Instance.Initialized += OnAppInitialized;
}
private async void OnAppInitialized()
{
// SceneContext 초기화 완료 대기 (Injection이 수행된 후)
var sceneCtx = FindAnyObjectByType<StudioSceneContext>();
if (sceneCtx != null)
{
// Injection이 완료될 때까지 대기
await sceneCtx.WaitForInitializationAsync();
Initialize();
}
}
private void Initialize()
{
SetupTopMenu();
SetupToolBox();
SetupPropertyWindow();
sideTabBar.InitTab();
Initialized?.Invoke();
UILoading.Hide();
}
private void SetupTopMenu()
{
if (topMenu == null)
{
Debug.LogWarning("TopMenuController is not assigned in SceneMain.");
return;
}
topMenu.AddMenuItem(new MenuItemData("file", "menu_file", subMenuItems: new List<MenuItemData>
{
new MenuItemData("file_new", "menu_file_new", new DebugLogCommand("새 파일 선택됨 (Command 실행)")),
new MenuItemData("file_open", "menu_file_open", new DebugLogCommand("파일 열기 선택됨 (Command 실행)")),
new MenuItemData("file_save", "menu_file_save", new DebugLogCommand("파일 저장 선택됨 (Command 실행)")),
new MenuItemData("file_saveas", "menu_file_save_as", new DebugLogCommand("다른 이름으로 저장 선택됨 (Command 실행)")),
new MenuItemData("file_insert_db", "menu_file_insert_db", new DebugLogCommand("데이터베이스 삽입 선택됨 (Command 실행)")),
new MenuItemData("file_export", "menu_file_export", subMenuItems: new List<MenuItemData>
{
new MenuItemData("file_export_layout", "menu_file_export_layout", new DebugLogCommand("Layout Json 내보내기 선택됨 (Command 실행)")),
new MenuItemData("file_export_meta", "menu_file_export_meta", new DebugLogCommand("Meta Data Json 내보내기 선택됨 (Command 실행)")),
new MenuItemData("file_export_gltf", "menu_file_export_gltf", new DebugLogCommand("GLTF 내보내기 선택됨 (Command 실행)")),
}),
}));
// pool 로그
topMenu.AddMenuItem(new MenuItemData("edit", "menu_edit", subMenuItems: new List<MenuItemData>
{
new MenuItemData("edit_undo", "menu_edit_undo", new DebugLogCommand("되돌리기 선택됨 (Command 실행)")),
new MenuItemData("edit_redo", "menu_edit_redo", new DebugLogCommand("다시 실행 선택됨 (Command 실행)")),
new MenuItemData("edit_duplicate", "menu_edit_duplicate", new DebugLogCommand("복제 선택됨 (Command 실행)")),
new MenuItemData("edit_delete", "menu_edit_delete", new DebugLogCommand("삭제 선택됨 (Command 실행)")),
new MenuItemData("edit_create_plane", "menu_edit_create_plane", new DebugLogCommand("평면 생성 선택됨 (Command 실행)")),
}));
topMenu.AddMenuItem(new MenuItemData("setting", "menu_setting", subMenuItems: new List<MenuItemData>
{
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();
}
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 DebugLogCommand("저장 버튼 클릭됨 (Command 실행)"),
tooltip:"tooltip_save");
// undo
toolbarModel.AddStandardButton("button_undo",
"Studio/Images/toolbar_icon_undo_40",
command: new DebugLogCommand("되돌리기 버튼 클릭됨"),
tooltip: "tooltip_undo");
// redo
toolbarModel.AddStandardButton("button_redo",
"Studio/Images/toolbar_icon_redo_40",
command: new DebugLogCommand("다시 실행 버튼 클릭됨"),
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 실행")),
"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 실행")),
"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 실행")),
"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 실행")),
"tooltip_scale_tool");
toolbarModel.AddSeparator();
//duplicate
toolbarModel.AddStandardButton("button_duplicate",
"Studio/Images/toolbar_icon_duplicate_40",
command: new DebugLogCommand("duplicate 버튼 클릭됨"),
tooltip: "tooltip_duplicate");
//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",
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.AddStandardButton("button_snap",
"Studio/Images/toolbar_icon_snap_40",
command: new DebugLogCommand("snap 버튼 클릭됨"),
tooltip: "tooltip_snap");
//guide
toolbarModel.AddStandardButton("button_guide",
"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(() => Debug.Log("Node Tool Command 실행")),
"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(() => Debug.Log("Link Tool Command 실행")),
"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(() => Debug.Log("Arc Tool Command 실행")),
"tooltip_arc_tool");
// --- 툴바 모델 구성 끝 ---
toolBox.SetData(toolbarModel);
toolBox.Initialize();
}
private void SetupPropertyWindow()
{
propertyWindow.LoadProperties(new List<IPropertyItem>
{
new StringProperty("prop1", "String Property", "Initial Value")
{
Description = "This is a sample string property.",
Tooltip = "Enter a string value here.",
IsReadOnly = false
},
new IntProperty("prop2", "Int Property", 42, true)
{
Description = "This is a sample integer property.",
Tooltip = "Enter an integer value here.",
IsReadOnly = false
},
new IntRangeProperty("prop2_range", "Int Range Property", new Tuple<int, int>(0, 100))
{
Description = "This is a sample integer range property.",
Tooltip = "Select an integer value within the range here.",
IsReadOnly = false
},
new FloatRangeProperty("prop3_range", "Float Range Property", new Tuple<float, float>(0.0f, 1.0f))
{
Description = "This is a sample float range property.",
Tooltip = "Select a float value within the range here.",
IsReadOnly = false
},
new FloatProperty("prop3", "Float Property", 0.5f, true)
{
Description = "This is a sample float property.",
Tooltip = "Enter an float value here.",
IsReadOnly = false
},
new BoolProperty("prop4", "Boolean Property", true)
{
Description = "This is a sample boolean property.",
Tooltip = "Toggle the boolean value here.",
IsReadOnly = false
},
new ColorProperty("prop5", "Color Property", Color.red)
{
Description = "This is a sample color property.",
Tooltip = "Select a color here.",
IsReadOnly = false
},
new Vector2Property("prop6_vec2", "Vector2 Property", new Vector2(1, 2))
{
Description = "This is a sample Vector2 property.",
Tooltip = "Enter a Vector2 value here.",
IsReadOnly = false
},
new Vector3Property("prop6_vec3", "Vector3 Property", new Vector3(1, 2, 3))
{
Description = "This is a sample Vector3 property.",
Tooltip = "Enter a Vector3 value here.",
IsReadOnly = false
},
new DateProperty("prop6_date", "Date Property", System.DateTime.Now)
{
//Description = "This is a sample date property.",
Tooltip = "Select a date here.",
IsReadOnly = false
},
new DateTimeProperty("prop6_datetime", "DateTime Property", System.DateTime.Now)
{
Description = "This is a sample date-time property.",
Tooltip = "Select a date and time here.",
IsReadOnly = false
},
new DateRangeProperty("prop6_daterange", "Date Range Property", new Tuple<DateTime, DateTime>(DateTime.Now.AddDays(-7), DateTime.Now))
{
Description = "This is a sample date range property.",
Tooltip = "Select a date range here.",
IsReadOnly = false
},
new DateTimeRangeProperty("prop6_datetimerange", "DateTime Range Property", new Tuple<DateTime, DateTime>(DateTime.Now.AddHours(-1), DateTime.Now))
{
Description = "This is a sample date-time range property.",
Tooltip = "Select a date-time range here.",
IsReadOnly = false
},
new EnumProperty("prop6", "Enum Property", SampleEnum.Option1)
{
Description = "This is a sample enum property.",
Tooltip = "Select an option here.",
IsReadOnly = false
},
new ListProperty("prop7", "List Property", new List<string> { "Item1", "Item2", "Item3" }, "Item1")
{
Description = "This is a sample list property.",
Tooltip = "Manage the list items here.",
IsReadOnly = false
},
new RadioGroupProperty("prop8", "Radio Group Property", new List<string> { "Option1", "Option2", "Option3" }, "Option1")
{
Description = "This is a sample radio group property.",
Tooltip = "Select one option here.",
IsReadOnly = false
}
});
propertyWindow.PropertyValueChanged += (sender, e) =>
{
Debug.Log($"Property Id:{e.PropertyId}, type:{e.PropertyType}, newValue: {e.NewValue}");
};
}
enum SampleEnum
{
Option1,
Option2,
Option3
}
}
}