Files
XRLib/Assets/Scripts/Simulator/SimulatorSceneMain.cs
2026-02-26 17:09:39 +09:00

160 lines
6.3 KiB
C#

using Best.HTTP.JSON;
using Cysharp.Threading.Tasks;
using Simulator.Config;
using Simulator.Data;
using Simulator.UI;
using System;
using System.Collections.Generic;
using UnityEngine;
using UVC.Core;
using UVC.Data;
using UVC.Network;
using UVC.UI.Commands;
using UVC.UI.Menu;
using UVC.UI.Tooltip;
using UVC.UI.Window.PropertyWindow;
namespace Simulator
{
[DefaultExecutionOrder(90)]
public class SimulatorSceneMain : SingletonScene<SimulatorSceneMain>
{
[SerializeField]
private TopMenuController GNB;
public Action Initialized;
public event Action<LogicDetailData> onRequestDataReceived;
[SerializeField]
private PropertyWindow propertyWindow;
private SimulatorAppMain _appMain;
/// <summary>
/// 초기 화 메서드입니다.
/// Awake 메서드에서 호출되며, MonoBehaviour가 생성될 때 한 번만 실행됩니다.
/// </summary>
protected override void Init()
{
if (!TooltipManager.Instance.IsInitialized) TooltipManager.Instance.Initialize();
_appMain = SimulatorAppMain.Instance;
_appMain.Initialized += OnAppInitialized;
}
private void OnAppInitialized()
{
OnAppInitializedAsync().Forget();
}
private async UniTaskVoid OnAppInitializedAsync()
{
await requestDataAsync();
SetupGNB();
//SetupPropertyWindow();
if (Initialized != null)
{
Initialized.Invoke();
}
}
private async UniTask requestDataAsync()
{
Debug.Log("requestDataAsync");
// WebReceiver의 파라미터 수신 대기
var webReceiver = FindAnyObjectByType<WebReceiver>();
if (webReceiver == null)
{
Debug.LogError("WebReceiver not found in scene.");
return;
}
var tcs = new UniTaskCompletionSource();
void handler() { tcs.TrySetResult(); }
webReceiver.onWebParameterReceived += handler;
await tcs.Task;
webReceiver.onWebParameterReceived -= handler;
// SceneMain이 직접 데이터 로딩 수행
await ComponentsManager.Instance.Request(SimulationConfig.projectId.ToString());
Debug.Log(SimulationConfig.projectId);
}
private void SetupGNB()
{
if (GNB == null)
{
GNB = FindAnyObjectByType<TopMenuController>(FindObjectsInactive.Include);
}
if (GNB == null)
{
Debug.LogError("SideMenuController is not assigned in SceneMain.");
return;
}
GNB.AddMenuItem(new MenuItemData("menu", "menu", new DebugLogCommand("[SampleProject] 프로젝트 설정 선택됨"), subMenuItems: new List<MenuItemData>
{
new MenuItemData("simulation", "시뮬레이션", subMenuItems: new List<MenuItemData>
{
new MenuItemData("simulation_create", "시뮬레이션 생성", new DebugLogCommand("시뮬레이션 생성")),
new MenuItemData("simulation_open", "시뮬레이션 열기", new SimulationListOpenCommand()),
new MenuItemData("simulation_save", "시뮬레이션 저장", new DebugLogCommand("시뮬레이션 저장")),
new MenuItemData("simulation_save_as", "시뮬레이션 복제", new DebugLogCommand("시뮬레이션 복제")),
new MenuItemData("simulation_delete", "시뮬레이션 삭제", new DebugLogCommand("시뮬레이션 삭제")),
new MenuItemData("simulation_history", "시뮬레이션 이력", new DebugLogCommand("시뮬레이션 이력"))
}),
new MenuItemData("scenario", "시나리오", subMenuItems: new List<MenuItemData>
{
new MenuItemData("scenario_create", "시나리오 생성", new DebugLogCommand("시나리오 생성")),
new MenuItemData("scenario_run", "시나리오 실행", new DebugLogCommand("시나리오 실행")),
new MenuItemData("scenario_save_as", "시나리오 복제", new DebugLogCommand("시나리오 복제")),
new MenuItemData("scenario_delete", "시나리오 삭제", new DebugLogCommand("시나리오 삭제")),
new MenuItemData("scenario_history", "시나리오 이력", new DebugLogCommand("시나리오 이력"))
}),
new MenuItemData("whatif", "WHAT-IF 분석", subMenuItems: new List<MenuItemData>
{
new MenuItemData("whatif_create", "WHAT-IF 생성", new DebugLogCommand("WHAT-IF 생성")),
new MenuItemData("whatif_run", "WHAT-IF 실행", new DebugLogCommand("WHAT-IF 실행")),
new MenuItemData("whatif_save_as", "WHAT-IF 복제", new DebugLogCommand("WHAT-IF 복제")),
new MenuItemData("whatif_delete", "WHAT-IF 삭제", new DebugLogCommand("WHAT-IF 삭제")),
new MenuItemData("whatif_history", "WHAT-IF 이력", new DebugLogCommand("WHAT-IF 이력"))
}),
new MenuItemData("visible", "보기", subMenuItems: new List<MenuItemData>
{
new MenuItemData("explorer_window", "탐색창", new ActionCommand(()=> Debug.Log("탐색창"))),
new MenuItemData("property_window", "속성창", new ActionCommand(()=> {
if(propertyWindow.IsVisible) propertyWindow.Hide();
else propertyWindow.Show();
})),
}),
new MenuItemData("help", "도움말", subMenuItems: new List<MenuItemData>
{
new MenuItemData("guide", "가이드", new ActionCommand(()=> Debug.Log("가이드"))),
}),
}));
GNB.Initialize();
}
private void OnDestroy()
{
if (_appMain != null)
{
_appMain.Initialized -= OnAppInitialized;
}
}
enum SampleEnum
{
Option1,
Option2,
Option3
}
}
}