Files
XRLib/Assets/Scripts/Factory/Playback/PlaybackCommand.cs
2025-12-12 18:58:44 +09:00

92 lines
3.1 KiB
C#

#nullable enable
using UnityEngine;
using UVC.Data;
using UVC.Factory.Cameras;
using UVC.Factory.Component;
using UVC.Factory.Modal;
using UVC.Factory.Playback.UI;
using UVC.UI.Commands;
using UVC.UI.Loading;
using UVC.UI.Modal;
namespace UVC.Factory.Playback
{
/// <summary>
/// 재생(Playback) 명령을 실행하는 클래스입니다.
///
/// <para>
/// 이 명령은 팩토리 카메라를 비활성화하고, 재생 목록 모달을 띄운 뒤,
/// 사용자가 재생 항목을 선택하면 재생을 시작합니다.
/// 사용자가 취소하면 재생을 종료합니다.
/// </para>
///
/// <example>
/// <code>
/// // ICommand 인터페이스를 구현하므로 다음과 같이 사용할 수 있습니다.
/// ICommand playbackCommand = new PlaybackCommand();
/// playbackCommand.Execute();
/// </code>
/// </example>
/// </summary>
public class PlaybackCommand : ICommand
{
/// <summary>
/// 재생 명령을 실행합니다.
///
/// <para>
/// 1. 카메라를 비활성화합니다.<br/>
/// 2. 재생 목록 모달을 띄웁니다.<br/>
/// 3. 사용자가 항목을 선택하면 재생을 시작합니다.<br/>
/// 4. 사용자가 취소하면 재생을 종료합니다.<br/>
/// </para>
///
/// <example>
/// <code>
/// // 명령 실행 예시
/// var command = new PlaybackCommand();
/// command.Execute();
/// </code>
/// </example>
/// </summary>
/// <param name="parameter">사용하지 않음</param>
public async void Execute(object? parameter = null)
{
// 1. 카메라 비활성화
FactoryCameraController.Instance.Enable = false;
// 2. 재생 목록 모달 생성 및 표시
var modalContent = new ModalContent(UIPlaybackListModal.PrefabPath)
{
Title = "Playback List",
ConfirmButtonText = "Play",
ShowCancelButton = false
};
// 3. 사용자가 항목을 선택할 때까지 대기
UIPlaybackListItemData? result = await UVC.UI.Modal.Modal.Open<UIPlaybackListItemData>(modalContent);
Debug.Log($"PlaybackCommand result==null:{result==null}");
if (result != null)
{
// 4. 항목 선택 시: 로딩 표시, 재생 시작
UILoading.Show();
UIPlaybackListItemData data = result;
Debug.Log($"PlaybackCommand data:{data}");
DataRepository.Instance.MqttReceiver.Stop();
await PlaybackService.Instance.StartAsync(data);
FactoryCameraController.Instance.Enable = true;
UILoading.Hide();
}
else
{
// 5. 취소 시: 재생 종료
UILoading.Show();
PlaybackService.Instance.Exit();
FactoryCameraController.Instance.Enable = true;
UILoading.Hide();
}
}
}
}