47 lines
1.3 KiB
C#
47 lines
1.3 KiB
C#
using UnityEngine;
|
|
using UVC.Core;
|
|
|
|
namespace Sample
|
|
{
|
|
/// <summary>
|
|
/// 동적 생성 오브젝트 스포너 예시
|
|
/// Instantiate 후 수동으로 Inject 호출하는 방법을 보여줍니다.
|
|
/// </summary>
|
|
public class InjectorSampleEnemySpawnerExample : MonoBehaviour
|
|
{
|
|
[Header("Spawn Settings")]
|
|
[SerializeField] private InjectorSampleEnemy enemyPrefab;
|
|
[SerializeField] private Transform spawnPoint;
|
|
|
|
[Inject] private ILogService _logger;
|
|
|
|
public void SpawnEnemy()
|
|
{
|
|
SpawnEnemy(spawnPoint != null ? spawnPoint.position : transform.position);
|
|
}
|
|
|
|
public void SpawnEnemy(Vector3 position)
|
|
{
|
|
if (enemyPrefab == null)
|
|
{
|
|
_logger?.LogError("Enemy prefab is not assigned!");
|
|
return;
|
|
}
|
|
|
|
// 프리팹 인스턴스화
|
|
var enemy = Instantiate(enemyPrefab, position, Quaternion.identity);
|
|
|
|
// 생성된 오브젝트에 의존성 주입
|
|
InjectorAppContext.Instance?.InjectInto(enemy.gameObject);
|
|
|
|
_logger?.Log($"Enemy spawned at {position}");
|
|
}
|
|
|
|
[ContextMenu("Spawn Enemy At Position")]
|
|
private void SpawnEnemyAtPosition()
|
|
{
|
|
SpawnEnemy();
|
|
}
|
|
}
|
|
}
|