238 lines
11 KiB
C#
238 lines
11 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.Factory;
|
|
using UVC.Factory.Alarm;
|
|
using UVC.Factory.Component;
|
|
using UVC.Factory.Modal;
|
|
using UVC.Factory.Modal.Settings;
|
|
using UVC.Factory.Playback;
|
|
using UVC.Log;
|
|
using UVC.UI.Commands;
|
|
using UVC.UI.Loading;
|
|
using UVC.UI.Menu;
|
|
using UVC.UI.Modal;
|
|
using UVC.UI.Tooltip;
|
|
|
|
namespace SampleProject
|
|
{
|
|
[DefaultExecutionOrder(90)]
|
|
public class SceneMain : SingletonScene<SceneMain>
|
|
{
|
|
[SerializeField]
|
|
private TopMenuController topMenu;
|
|
|
|
[SerializeField]
|
|
private TopMenuController sideMenu;
|
|
|
|
public Action Initialized;
|
|
|
|
/// <summary>
|
|
/// 초기 화 메서드입니다.
|
|
/// Awake 메서드에서 호출되며, MonoBehaviour가 생성될 때 한 번만 실행됩니다.
|
|
/// </summary>
|
|
protected override void Init()
|
|
{
|
|
if (!TooltipManager.Instance.IsInitialized) TooltipManager.Instance.Initialize();
|
|
AppMain.Instance.Initialized += OnAppInitialized;
|
|
}
|
|
|
|
private async void OnAppInitialized()
|
|
{
|
|
|
|
// AGVManager 생성 시 이벤트 처리
|
|
AGVManager.Instance.OnCreated += OnAGVCreated;
|
|
|
|
PlaybackService.Instance.OnStartPlayback += OnStartPlayback;
|
|
PlaybackService.Instance.OnExitPlayback += OnExitPlayback;
|
|
PlaybackService.Instance.OnChangedTime += OnChangedTimePlayback;
|
|
|
|
await requestDataAsync();
|
|
|
|
SetupTopMenu();
|
|
SetupSideMenu();
|
|
|
|
if (Initialized != null)
|
|
{
|
|
Initialized.Invoke();
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
/// AGV 관리자가 생성될 때 발생하는 이벤트를 처리합니다.
|
|
/// </summary>
|
|
/// <remarks>이 메서드는 AGV 관리자 생성과 관련된 필요한 초기화 또는 설정 작업을 수행하기 위한 것입니다.
|
|
/// 내부적으로 호출되며 외부 코드에서 직접 사용하도록 의도된 것이 아닙니다.
|
|
///</remarks>
|
|
internal void OnAGVCreated()
|
|
{
|
|
AlarmManager.Instance.Run();
|
|
UILoading.Hide();
|
|
FactoryCameraController.Instance.Enable = true;
|
|
}
|
|
|
|
private async UniTask requestDataAsync()
|
|
{
|
|
|
|
Debug.Log("requestDataAsync");
|
|
|
|
UILoading.Show();
|
|
|
|
//Debug.Log("Requesting BaseInfo data...");
|
|
//var httpFetcher = DataRepository.Instance.HttpFetcher;
|
|
//var splitRequest = new HttpRequestConfig(URLList.Get("baseinfo"))
|
|
// .SetSplitResponseByKey(true) // 응답을 키별로 분할
|
|
// .AddSplitConfig("AGV", DataMapperValidator.Get("AGV")) // "AGV" 키에 대한 매퍼, Validator 설정
|
|
// .AddSplitConfig("ALARM", DataMapperValidator.Get("ALARM")); // "ALARM" 키에 대한 매퍼, Validator 설정
|
|
//httpFetcher.Add("baseInfo", splitRequest);
|
|
//await httpFetcher.Excute("baseInfo");
|
|
//Debug.Log("BaseInfo data request completed.");
|
|
//UILoading.Hide();
|
|
|
|
//MqttReceiver 시작
|
|
DataRepository.Instance.MqttReceiver.Start();
|
|
if (AGVManager.Instance.Created)
|
|
{
|
|
|
|
await UniTask.Delay(1000);
|
|
UILoading.Hide();
|
|
}
|
|
}
|
|
|
|
|
|
private void OnStartPlayback()
|
|
{
|
|
FactoryObjectSelectionManager.Instance.DeselectAll();
|
|
InfoWindow.Instance.Hide();
|
|
}
|
|
|
|
|
|
private async void OnExitPlayback()
|
|
{
|
|
FactoryObjectSelectionManager.Instance.DeselectAll();
|
|
InfoWindow.Instance.Hide();
|
|
await requestDataAsync();
|
|
}
|
|
|
|
private void OnChangedTimePlayback()
|
|
{
|
|
}
|
|
|
|
|
|
private void SetupTopMenu()
|
|
{
|
|
if (topMenu == null)
|
|
{
|
|
Debug.LogError("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("[SampleProject] 새 파일 선택됨")))
|
|
}),
|
|
new MenuItemData("file_open", "menu_file_open",
|
|
new ActionCommand<string>((path) => Debug.Log($"[SampleProject] 파일 열기 선택됨: {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 PlaybackCommand()));
|
|
// 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()}"))),
|
|
new MenuItemData("agv", "Pool", new ActionCommand(() => Debug.Log($"Pool stats: {AGVManager.Instance.Pool.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 SettingOpenCommand()));
|
|
|
|
topMenu.Initialize();
|
|
}
|
|
|
|
|
|
private void SetupSideMenu()
|
|
{
|
|
if (sideMenu == null)
|
|
{
|
|
Debug.LogError("SideMenuController is not assigned in SceneMain.");
|
|
return;
|
|
}
|
|
|
|
sideMenu.AddMenuItem(new MenuItemData("menu", "menu", new DebugLogCommand("[SampleProject] 프로젝트 설정 선택됨"), subMenuItems: new List<MenuItemData>
|
|
{
|
|
new MenuItemData("file", "menu_file", subMenuItems: new List<MenuItemData>
|
|
{
|
|
new MenuItemData("file_new_file", "menu_file_new_file", new DebugLogCommand("[SampleProject] 새 파일 선택됨")),
|
|
// "파일 열기" 메뉴 아이템 생성 시 isEnabled: false로 설정하여 비활성화 상태로 초기화합니다.
|
|
// 부모 TopMenuController의 HandleMenuItemClicked에서 이 상태를 확인하여 클릭을 무시합니다.
|
|
new MenuItemData("file_open", "menu_file_open", new DebugLogCommand("[SampleProject] 파일 열기 선택됨"), isEnabled: false),
|
|
MenuItemData.CreateSeparator("file_sep_sample1"),
|
|
new MenuItemData("project_settings", "project_settings", new DebugLogCommand("[SampleProject] 프로젝트 설정 선택됨")), // 프로젝트별 메뉴 아이템
|
|
MenuItemData.CreateSeparator("file_sep_sample2"),
|
|
new MenuItemData("file_exit", "menu_file_exit", new QuitApplicationCommand())
|
|
}),
|
|
new MenuItemData("Playback", "Playback", new PlaybackCommand()),
|
|
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("확인", "이것은 간단한 알림 메시지입니다.");
|
|
ULog.Debug($"사용자가 확인 버튼을 눌렀나요? {result}");
|
|
result = await Confirm.Show("경고", "데이터를 저장할 수 없습니다.", "알겠습니다", "아니요");
|
|
ULog.Debug($"사용자가 알림을 확인했나요? {result}");
|
|
result = await Confirm.Show("error", "error_network_not", "button_retry", "button_cancel");
|
|
ULog.Debug($"사용자가 네트워크 오류 알림을 확인했나요? {result}");
|
|
}))
|
|
}),
|
|
new MenuItemData("Settings", "Settings", subMenuItems: new List<MenuItemData>
|
|
{
|
|
new MenuItemData("info", "info", new DisplayDataOrderCommand()),
|
|
})
|
|
}));
|
|
|
|
sideMenu.Initialize();
|
|
}
|
|
|
|
}
|
|
}
|