Files
XRLib/Assets/Sample/Injector/InjectorSampleUIManager.cs

96 lines
3.8 KiB
C#
Raw Normal View History

2025-12-15 20:17:38 +09:00
using UnityEngine;
using UVC.Core;
namespace Sample
{
/// <summary>
/// Type C 예시: Prefab 기반 MonoBehaviour - UI 매니저
/// </summary>
/// <remarks>
/// <para><b>[ 타입 ]</b> Type C - Prefab 기반 MonoBehaviour</para>
/// <para><b>[ 라이프사이클 ]</b> App - 씬 전환 시에도 유지</para>
///
/// <para><b>[ 특징 ]</b></para>
/// <list type="bullet">
/// <item><description>프리팹에 미리 설정된 UI 요소들이 Instantiate 시 유지됨</description></item>
/// <item><description>Inspector에서 Canvas, Panel, Button 등 시각적으로 구성 가능</description></item>
/// <item><description>디자이너와 협업 시 유용 (코드 수정 없이 UI 변경 가능)</description></item>
/// <item><description>다른 서비스([Inject] ILogService)에 대한 의존성 주입 지원</description></item>
/// </list>
///
/// <para><b>[ 프리팹 생성 방법 ]</b></para>
/// <list type="number">
/// <item><description>Hierarchy에서 Canvas 생성</description></item>
/// <item><description>Canvas 하위에 Popup Panel, Loading Panel 등 UI 요소 배치</description></item>
/// <item><description>Canvas에 InjectorSampleUIManager 컴포넌트 추가</description></item>
/// <item><description>Inspector에서 popupPanel, loadingPanel 필드에 해당 GameObject 연결</description></item>
/// <item><description>Project 폴더로 드래그하여 프리팹화</description></item>
/// </list>
///
/// <para><b>[ 등록 방법 ]</b></para>
/// <code>
/// // InjectorSampleAppContext에서
/// [SerializeField] private InjectorSampleUIManager uiManagerPrefab;
///
/// protected override void RegisterServices()
/// {
/// Injector.RegisterPrefab&lt;IUIManager&gt;(uiManagerPrefab.gameObject, ServiceLifetime.App);
/// }
/// </code>
///
/// <para><b>[ 사용 방법 ]</b></para>
/// <code>
/// [Inject] private IUIManager _uiManager;
/// _uiManager.ShowPopup("알림", "저장되었습니다.");
/// _uiManager.ShowLoading();
/// </code>
///
/// <para><b>[ Type B(동적 생성)와의 차이점 ]</b></para>
/// <list type="bullet">
/// <item><description>Type B: 빈 GameObject에 컴포넌트만 추가, Inspector 설정 불가</description></item>
/// <item><description>Type C: 프리팹의 모든 설정(자식 오브젝트, 컴포넌트 값 등) 유지</description></item>
/// </list>
/// </remarks>
public class InjectorSampleUIManager : MonoBehaviour, IUIManager
{
[Header("UI References")]
[SerializeField]
[Tooltip("팝업 패널 GameObject - 프리팹에서 연결")]
private GameObject popupPanel;
[SerializeField]
[Tooltip("로딩 패널 GameObject - 프리팹에서 연결")]
private GameObject loadingPanel;
[Inject] private ILogService _logger;
/// <summary>팝업을 표시합니다.</summary>
public void ShowPopup(string title, string message)
{
_logger?.Log($"Show Popup: {title} - {message}");
if (popupPanel != null) popupPanel.SetActive(true);
}
/// <summary>팝업을 숨깁니다.</summary>
public void HidePopup()
{
_logger?.Log("Hide Popup");
if (popupPanel != null) popupPanel.SetActive(false);
}
/// <summary>로딩 UI를 표시합니다.</summary>
public void ShowLoading()
{
_logger?.Log("Show Loading");
if (loadingPanel != null) loadingPanel.SetActive(true);
}
/// <summary>로딩 UI를 숨깁니다.</summary>
public void HideLoading()
{
_logger?.Log("Hide Loading");
if (loadingPanel != null) loadingPanel.SetActive(false);
}
}
}