using UnityEngine; using UVC.Core; namespace Sample { /// /// Scene 레벨 서비스 등록 컨텍스트 - 현재 씬에서만 유지되는 서비스를 등록합니다. /// /// /// [ 역할 ] /// InjectorSceneContext를 상속받아 Scene 라이프사이클 서비스를 등록합니다. /// 씬 전환 시 자동으로 정리되며, 새 씬에서는 해당 씬의 SceneContext가 서비스를 등록합니다. /// /// [ 설정 방법 ] /// /// 각 씬에 빈 GameObject 생성 → 이름: "SceneContext" /// 이 컴포넌트(InjectorSampleSceneContext) 추가 /// Inspector에서 Scene UI Prefab 연결 (선택) /// /// /// [ 등록되는 서비스 ] /// /// Type AISceneConfig → SceneConfig (순수 C#, Scene 라이프사이클) /// Type BIEnemySpawner → InjectorSampleEnemySpawner (MonoBehaviour 동적 생성) /// Type CISceneUI → InjectorSampleSceneUI (Prefab 기반) /// Type DInjectorSampleLevelManager (MonoBehaviour SingletonScene) /// /// /// [ 실행 순서 ] /// DefaultExecutionOrder(-900)으로 AppContext 다음에 실행됩니다. /// /// [ App vs Scene 라이프사이클 ] /// /// App: 게임 전체에서 공유 (설정, 네트워크, 오디오 등) /// Scene: 현재 씬에서만 유효 (레벨 매니저, 적 스포너 등) /// /// public class InjectorSampleSceneContext : InjectorSceneContext { [Header("Scene Prefabs")] [SerializeField] [Tooltip("Scene용 UI 프리팹 - InjectorSampleSceneUI 프리팹을 연결하세요 (선택)")] private InjectorSampleSceneUI sceneUIPrefab; /// /// Scene 라이프사이클 서비스들을 등록합니다. /// 씬 로드 시 자동 호출되며, 씬 전환 시 자동으로 정리됩니다. /// protected override void RegisterSceneServices() { base.RegisterSceneServices(); // ========== Type A: Scene 라이프사이클 순수 C# 클래스 ========== // 씬 전환 시 자동으로 해제되는 일반 클래스 Injector.Register(ServiceLifetime.Scene); // ========== Type B: Scene 라이프사이클 MonoBehaviour ========== // 씬 전환 시 GameObject와 함께 자동 파괴 Injector.Register(ServiceLifetime.Scene); // ========== Type C: Scene 라이프사이클 Prefab ========== // 프리팹 기반 UI, 씬 전환 시 자동 파괴 if (sceneUIPrefab != null) Injector.RegisterPrefab(sceneUIPrefab.gameObject, ServiceLifetime.Scene); // ========== Type D: Scene 단위 Singleton 연동 ========== // SingletonScene를 상속받은 클래스, 씬 전환 시 자동 파괴 Injector.RegisterSingleton(); Debug.Log("[InjectorSampleSceneContext] All Scene services registered"); } } }