started adding enemy factory
This commit is contained in:
50
Assets/Darkmatter/Code/Domain/Factory/EnemyFactory.cs
Normal file
50
Assets/Darkmatter/Code/Domain/Factory/EnemyFactory.cs
Normal file
@@ -0,0 +1,50 @@
|
||||
using Darkmatter.Core;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using VContainer;
|
||||
|
||||
namespace Darkmatter.Domain
|
||||
{
|
||||
public class EnemyFactory : IEnemyFactory
|
||||
{
|
||||
private readonly List<Transform> patrolPoints;
|
||||
private readonly Transform playerTransform;
|
||||
private readonly GameObject fatZombiePrefab;
|
||||
private readonly GameObject slimZombiePrefab;
|
||||
private readonly IObjectResolver objectResolver;
|
||||
public EnemyFactory(Transform playerTransform, List<Transform> patrolPoints, GameObject fatZombiePrefab, GameObject slimZombiePrefab)
|
||||
{
|
||||
this.playerTransform = playerTransform;
|
||||
this.patrolPoints = patrolPoints;
|
||||
this.fatZombiePrefab = fatZombiePrefab;
|
||||
this.slimZombiePrefab = slimZombiePrefab;
|
||||
}
|
||||
public IEnemyPawn GetEnemy(ZombieType type)
|
||||
{
|
||||
GameObject enemyObj = null;
|
||||
|
||||
switch (type)
|
||||
{
|
||||
case ZombieType.Fat:
|
||||
enemyObj = GameObject.Instantiate(fatZombiePrefab, GetSpawnPos(), Quaternion.identity);
|
||||
break;
|
||||
|
||||
case ZombieType.slim:
|
||||
enemyObj = GameObject.Instantiate(slimZombiePrefab, GetSpawnPos(), Quaternion.identity);
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
objectResolver.Inject(enemyObj);
|
||||
IEnemyPawn enemyPawn = enemyObj.GetComponent<IEnemyPawn>();
|
||||
|
||||
return enemyPawn;
|
||||
}
|
||||
|
||||
private Vector3 GetSpawnPos()
|
||||
{
|
||||
return patrolPoints[Random.Range(0, patrolPoints.Count)].position;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user