从 EnemyManager 中拆分刷怪位置策略接口
This commit is contained in:
+3
-10
@@ -8,7 +8,6 @@ using SepCore.AsyncTask;
|
||||
using SepCore.CustomUtility;
|
||||
using UnityEngine;
|
||||
using UnityGameFramework.Runtime;
|
||||
using Random = UnityEngine.Random;
|
||||
|
||||
namespace SepCore.EnemyManager
|
||||
{
|
||||
@@ -47,6 +46,7 @@ namespace SepCore.EnemyManager
|
||||
private float _spawnRateScale = 1f;
|
||||
|
||||
private Transform _player;
|
||||
private ISpawnPositionStrategy _spawnPositionStrategy;
|
||||
|
||||
public float SpawnRateScale => _spawnRateScale;
|
||||
public float BattleDuration => _duration;
|
||||
@@ -76,6 +76,7 @@ namespace SepCore.EnemyManager
|
||||
public void OnInit(DRLevel level, Player player)
|
||||
{
|
||||
_player = player != null ? player.CachedTransform : null;
|
||||
_spawnPositionStrategy = new RandomCircleSpawnStrategy(_spawnDistanceFromPlayer);
|
||||
|
||||
_baseSpawnEnemyIntervals = (float[])level.Intervals.Clone();
|
||||
_spawnEnemyIntervals = (float[])_baseSpawnEnemyIntervals.Clone();
|
||||
@@ -136,7 +137,7 @@ namespace SepCore.EnemyManager
|
||||
if (_currentEnemyCount >= _spawnEnemyMaxCount) return;
|
||||
int entityPoolId = _currentSpawnEnemyId % _spawnEnemyMaxCount;
|
||||
var enemyData = EntityDataFactory.Create(entityPoolId, enemyType, _currentLevel);
|
||||
enemyData.Position = GetRandomPosition();
|
||||
enemyData.Position = _spawnPositionStrategy.GetSpawnPosition(_player);
|
||||
_currentSpawnEnemyId++;
|
||||
|
||||
EnemyBase enemy = await _entity.ShowEnemyAsync(enemyData);
|
||||
@@ -148,14 +149,6 @@ namespace SepCore.EnemyManager
|
||||
RegisterEnemy(enemy);
|
||||
}
|
||||
|
||||
private Vector3 GetRandomPosition()
|
||||
{
|
||||
float x = Random.Range(-1f, 1f);
|
||||
float z = Random.Range(-1f, 1f);
|
||||
Vector3 dir = new Vector3(x, 0, z).normalized;
|
||||
return _player.position + dir * _spawnDistanceFromPlayer;
|
||||
}
|
||||
|
||||
public void ClearEnemies()
|
||||
{
|
||||
foreach (var enemy in _enemies)
|
||||
|
||||
Reference in New Issue
Block a user