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