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