190 lines
10 KiB
C#
190 lines
10 KiB
C#
using Cysharp.Threading.Tasks;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
using UVC.Data.Core;
|
|
using UVC.Locale;
|
|
using UVC.UI.Commands;
|
|
using UVC.UI.Menu;
|
|
using UVC.UI.Modal;
|
|
using UVC.Util;
|
|
|
|
public class MenuSample : MonoBehaviour
|
|
{
|
|
|
|
[SerializeField]
|
|
private TopMenuController topMenu;
|
|
|
|
[SerializeField]
|
|
private TopMenuController modalMenu;
|
|
|
|
// Start is called once before the first execution of Update after the MonoBehaviour is created
|
|
void Start()
|
|
{
|
|
SettupConfigAsync().ContinueWith(() =>
|
|
{
|
|
SetupTopMenu();
|
|
SetupSideMenu();
|
|
}).Forget();
|
|
}
|
|
|
|
private async UniTask SettupConfigAsync()
|
|
{
|
|
// if (FactoryAppConfig.LoadConfig())
|
|
// {
|
|
// Application.targetFrameRate = FactoryAppConfig.Config.TargetFrameRate;
|
|
|
|
// //기본 언어 설정
|
|
// bool success = LocalizationManager.Instance.LoadDefaultLocalizationData(FactoryAppConfig.Config.Language);
|
|
// Debug.Log($"LocalizationManager: LoadDefaultLocalizationData success: {success}");
|
|
// if (!Application.isEditor && Application.platform == RuntimePlatform.WindowsPlayer)
|
|
// {
|
|
// //창 설정
|
|
// if (FactoryAppConfig.Config.Window != null)
|
|
// {
|
|
// WindowTools.Instance.Init(FactoryAppConfig.Config.Window);
|
|
// }
|
|
// }
|
|
|
|
// FactoryConstants.API_DOMAIN = FactoryAppConfig.Config.Api;
|
|
// FactoryConstants.MQTT_DOMAIN = FactoryAppConfig.Config.Mqtt.Domain;
|
|
// FactoryConstants.MQTT_PORT = FactoryAppConfig.Config.Mqtt.Port;
|
|
// FactoryConstants.MQTT_DATA_KEY = FactoryAppConfig.Config.Mqtt.DataKey;
|
|
// FactoryConstants.MQTT_MESSAGEPACK_ENABLED = FactoryAppConfig.Config.Mqtt.MessagePack;
|
|
// }
|
|
}
|
|
|
|
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", subMenuItems: new List<MenuItemData>
|
|
{
|
|
new MenuItemData("file_new_project", "menu_file_new_project", new DebugLogCommand("새 프로젝트 선택됨 (Command 실행)")),
|
|
new MenuItemData("file_new_file", "menu_file_new_file",
|
|
new ActionCommand(() => Debug.Log(" 새 파일 선택됨")))
|
|
}),
|
|
new MenuItemData("file_open", "menu_file_open",
|
|
new ActionCommand<string>((path) => Debug.Log($" 파일 열기 선택됨: {path}"), "sample.txt"),
|
|
commandParameter: "another_sample.txt", // 이 파라미터가 HandleMenuItemClicked에서 사용됨
|
|
isEnabled: false), // "파일 열기"는 비활성화 상태로 시작
|
|
MenuItemData.CreateSeparator("file_sep1"), // 구분선 추가
|
|
new MenuItemData("file_save", "menu_file_save", command: new DebugLogCommand("저장 선택됨 (Command 실행)") , subMenuItems: new List<MenuItemData>
|
|
{
|
|
new MenuItemData("file_save_as", "menu_file_save_as", new DebugLogCommand("다른 이름으로 저장 선택됨 (Command 실행)"))
|
|
}),
|
|
MenuItemData.CreateSeparator("file_sep2"), // 또 다른 구분선 추가
|
|
new MenuItemData("file_exit", "menu_file_exit", new QuitApplicationCommand()) // 애플리케이션 종료 명령 연결
|
|
}));
|
|
topMenu.AddMenuItem(new MenuItemData("Playback", "Playback", new ActionCommand(() => Debug.Log("Playback"))));
|
|
// pool 로그
|
|
topMenu.AddMenuItem(new MenuItemData("log", "Log", subMenuItems: new List<MenuItemData>
|
|
{
|
|
new MenuItemData("dataArray", "DataArray", new ActionCommand(() => Debug.Log($"DataArrayPool stats: {DataArrayPool.GetStats()}"))),
|
|
new MenuItemData("dataObject", "DataObjet", new ActionCommand(() => Debug.Log($"DataObjectPool stats: {DataObjectPool.GetStats()}"))),
|
|
}));
|
|
topMenu.AddMenuItem(new MenuItemData("modal", "모달", subMenuItems: new List<MenuItemData>
|
|
{
|
|
new MenuItemData("alert", "Alert", new ActionCommand(async () => {
|
|
await Alert.Show("알림", "이것은 간단한 알림 메시지입니다.");
|
|
await Alert.Show("경고", "데이터를 저장할 수 없습니다.", "알겠습니다");
|
|
await Alert.Show("error", "error_network_not", "button_retry");
|
|
})),
|
|
new MenuItemData("confirm", "Confirm", new ActionCommand(async () => {
|
|
bool result = await Confirm.Show("확인", "이것은 간단한 알림 메시지입니다.");
|
|
Debug.Log($"사용자가 확인 버튼을 눌렀나요? {result}");
|
|
result = await Confirm.Show("경고", "데이터를 저장할 수 없습니다.", "알겠습니다~~~~", "아니요");
|
|
Debug.Log($"사용자가 알림을 확인했나요? {result}");
|
|
result = await Confirm.Show("error", "error_network_not", "button_retry", "button_cancel");
|
|
Debug.Log($"사용자가 네트워크 오류 알림을 확인했나요? {result}");
|
|
}))
|
|
}));
|
|
|
|
topMenu.AddMenuItem(new MenuItemData("Settings", "Settings", new ActionCommand(() => Debug.Log("Settings"))));
|
|
|
|
topMenu.Initialize();
|
|
}
|
|
|
|
|
|
private void SetupSideMenu()
|
|
{
|
|
if (modalMenu == null)
|
|
{
|
|
Debug.LogError("SideMenuController is not assigned in SceneMain.");
|
|
return;
|
|
}
|
|
|
|
modalMenu.AddMenuItem(new MenuItemData("menu", "menu", new DebugLogCommand(" 프로젝트 설정 선택됨"), subMenuItems: new List<MenuItemData>
|
|
{
|
|
new MenuItemData("file", "menu_file", subMenuItems: new List<MenuItemData>
|
|
{
|
|
new MenuItemData("file_new_file", "menu_file_new_file", new DebugLogCommand(" 새 파일 선택됨")),
|
|
// "파일 열기" 메뉴 아이템 생성 시 isEnabled: false로 설정하여 비활성화 상태로 초기화합니다.
|
|
// 부모 TopMenuController의 HandleMenuItemClicked에서 이 상태를 확인하여 클릭을 무시합니다.
|
|
new MenuItemData("file_open", "menu_file_open", new DebugLogCommand(" 파일 열기 선택됨"), isEnabled: false),
|
|
MenuItemData.CreateSeparator("file_sep_sample1"),
|
|
new MenuItemData("project_settings", "project_settings", new DebugLogCommand(" 프로젝트 설정 선택됨")), // 프로젝트별 메뉴 아이템
|
|
MenuItemData.CreateSeparator("file_sep_sample2"),
|
|
new MenuItemData("file_exit", "menu_file_exit", new QuitApplicationCommand())
|
|
}),
|
|
new MenuItemData("Playback", "Playback", new DebugLogCommand("Playback")),
|
|
new MenuItemData("modal", "모달", subMenuItems: new List<MenuItemData>
|
|
{
|
|
new MenuItemData("alert", "Alert", new ActionCommand(async () => {
|
|
await Alert.Show("알림알림알림알림알림알림알림알림알림알림알림알림알림알림알림알림알림알림알림알림알림알림", "이것은 간단한 알림 메시지입니다.");
|
|
await Alert.Show("경고", "데이터를 저장할 수 없습니다.", "알겠습니다");
|
|
await Alert.Show("error", "error_network_not", "button_retry");
|
|
})),
|
|
new MenuItemData("confirm", "Confirm", new ActionCommand(async () => {
|
|
bool result = await Confirm.Show("확인", "이것은 간단한 알림 메시지입니다.");
|
|
Debug.Log($"사용자가 확인 버튼을 눌렀나요? {result}");
|
|
result = await Confirm.Show("경고", "데이터를 저장할 수 없습니다.", "알겠습니다", "아니요");
|
|
Debug.Log($"사용자가 알림을 확인했나요? {result}");
|
|
result = await Confirm.Show("error", "error_network_not", "button_retry", "button_cancel");
|
|
Debug.Log($"사용자가 네트워크 오류 알림을 확인했나요? {result}");
|
|
}))
|
|
}),
|
|
new MenuItemData("Settings", "Settings", subMenuItems: new List<MenuItemData>
|
|
{
|
|
new MenuItemData("info", "info", new DebugLogCommand("info")),
|
|
})
|
|
}));
|
|
|
|
modalMenu.Initialize();
|
|
}
|
|
|
|
void Update()
|
|
{
|
|
// 이 게임 오브젝트가 마우스 오른쪽 버튼으로 클릭되면 메뉴를 표시합니다.
|
|
if (Input.GetMouseButtonDown(1))
|
|
{
|
|
Debug.Log("Right mouse button clicked.");
|
|
// Raycast 등으로 이 오브젝트가 클릭되었는지 확인하는 로직이 필요합니다.
|
|
// 여기서는 설명을 위해 바로 호출합니다.
|
|
ShowPlayerMenu(Input.mousePosition);
|
|
}
|
|
}
|
|
|
|
public void ShowPlayerMenu(Vector2 screenPosition)
|
|
{
|
|
// 3. 메뉴에 표시할 항목 리스트를 동적으로 생성합니다.
|
|
var menuItems = new List<ContextMenuItemData>
|
|
{
|
|
// ContextMenuItemData 생성자를 사용하여 각 메뉴 항목을 정의합니다.
|
|
// 생성자: (itemId, displayName, command, commandParameter)
|
|
new ContextMenuItemData("player_attack", "공격", new DebugLogCommand("플레이어가 '공격'을 선택했습니다."), "플레이어가 '공격'을 선택했습니다."),
|
|
new ContextMenuItemData("player_talk", "대화", new DebugLogCommand("플레이어가 '대화'를 선택했습니다."), "플레이어가 '대화'를 선택했습니다."),
|
|
new ContextMenuItemData(isSeparator: true), // 구분선 추가
|
|
new ContextMenuItemData("player_inspect", "조사", new DebugLogCommand("플레이어가 '조사'를 선택했습니다."), "플레이어가 '조사'를 선택했습니다.")
|
|
};
|
|
// 4. ContextMenuManager 싱글톤 인스턴스를 통해 메뉴를 표시합니다.
|
|
ContextMenuManager.Instance.ShowMenu(menuItems, screenPosition);
|
|
}
|
|
|
|
}
|