64 lines
2.6 KiB
C#
64 lines
2.6 KiB
C#
using UnityEngine;
|
|
using UVC.Core;
|
|
|
|
namespace Sample
|
|
{
|
|
/// <summary>
|
|
/// Type B 예시: MonoBehaviour 동적 생성 - 오디오 매니저
|
|
/// </summary>
|
|
/// <remarks>
|
|
/// <para><b>[ 타입 ]</b> Type B - MonoBehaviour 동적 생성 (Prefab 없이)</para>
|
|
/// <para><b>[ 라이프사이클 ]</b> App - 씬 전환 시에도 유지</para>
|
|
///
|
|
/// <para><b>[ 특징 ]</b></para>
|
|
/// <list type="bullet">
|
|
/// <item><description>프리팹 없이 런타임에 새 GameObject가 자동 생성됨</description></item>
|
|
/// <item><description>Injector가 new GameObject().AddComponent<T>()로 생성</description></item>
|
|
/// <item><description>App 라이프사이클이면 DontDestroyOnLoad 자동 적용</description></item>
|
|
/// <item><description>다른 서비스([Inject] ILogService)에 대한 의존성 주입 지원</description></item>
|
|
/// </list>
|
|
///
|
|
/// <para><b>[ 등록 방법 ]</b></para>
|
|
/// <code>Injector.Register<IAudioManager, InjectorSampleAudioManager>(ServiceLifetime.App);</code>
|
|
///
|
|
/// <para><b>[ 사용 방법 ]</b></para>
|
|
/// <code>
|
|
/// [Inject] private IAudioManager _audioManager;
|
|
/// _audioManager.PlayBGM("main_theme");
|
|
/// _audioManager.PlaySFX("button_click");
|
|
/// </code>
|
|
///
|
|
/// <para><b>[ Type C(Prefab)와의 차이점 ]</b></para>
|
|
/// <list type="bullet">
|
|
/// <item><description>Type B: 코드로만 구성, Inspector 설정 불가</description></item>
|
|
/// <item><description>Type C: 프리팹에 미리 설정된 AudioSource, AudioClip 등 활용 가능</description></item>
|
|
/// </list>
|
|
///
|
|
/// <para><b>[ 실제 구현 시 확장 예시 ]</b></para>
|
|
/// <code>
|
|
/// private AudioSource bgmSource;
|
|
/// private AudioSource sfxSource;
|
|
///
|
|
/// private void Awake()
|
|
/// {
|
|
/// bgmSource = gameObject.AddComponent<AudioSource>();
|
|
/// sfxSource = gameObject.AddComponent<AudioSource>();
|
|
/// bgmSource.loop = true;
|
|
/// }
|
|
/// </code>
|
|
/// </remarks>
|
|
public class InjectorSampleAudioManager : MonoBehaviour, IAudioManager
|
|
{
|
|
[Inject] private ILogService _logger;
|
|
|
|
/// <summary>효과음을 재생합니다.</summary>
|
|
public void PlaySFX(string clipName) => _logger?.Log($"Playing SFX: {clipName}");
|
|
|
|
/// <summary>배경음악을 재생합니다.</summary>
|
|
public void PlayBGM(string clipName) => _logger?.Log($"Playing BGM: {clipName}");
|
|
|
|
/// <summary>모든 오디오를 중지합니다.</summary>
|
|
public void StopAll() => _logger?.Log("Stopping all audio");
|
|
}
|
|
}
|