重构清理敌人类
This commit is contained in:
+9
-3
@@ -22,7 +22,6 @@ namespace SepCore.EnemyManager
|
||||
public IReadOnlyCollection<EntityBase> Enemies => _enemyRegistry.Enemies;
|
||||
|
||||
private int _spawnEnemyMaxCount;
|
||||
private int _spawnDistanceFromPlayer;
|
||||
|
||||
private int _currentSpawnEnemyId;
|
||||
private int _currentLevel;
|
||||
@@ -73,11 +72,18 @@ namespace SepCore.EnemyManager
|
||||
return;
|
||||
}
|
||||
|
||||
if (!_entity.HasEntityGroup(EnemyGroupName))
|
||||
{
|
||||
Log.Error("Entity group '{0}' does not exist.", EnemyGroupName);
|
||||
return;
|
||||
}
|
||||
|
||||
_isStopped = false;
|
||||
_spawnEnemyMaxCount = GameEntry.Luban.Global.SpawnEnemyMaxCount;
|
||||
_spawnDistanceFromPlayer = GameEntry.Luban.Global.SpawnDistanceFromPlayer / 1000;
|
||||
float minDistance = GameEntry.Luban.Global.EnemySpawnDistanceMin / 1000f;
|
||||
float maxDistance = GameEntry.Luban.Global.EnemySpawnDistanceMax / 1000f;
|
||||
_player = player.CachedTransform;
|
||||
_spawnPositionStrategy = new RandomCircleSpawnStrategy(_spawnDistanceFromPlayer);
|
||||
_spawnPositionStrategy = new RandomCircleSpawnStrategy(minDistance, maxDistance);
|
||||
|
||||
_baseDuration = level.Duration;
|
||||
_duration = _baseDuration;
|
||||
|
||||
@@ -8,7 +8,7 @@ namespace SepCore.EnemyManager
|
||||
{
|
||||
public class EnemySpawnScheduler
|
||||
{
|
||||
private const float MinSpawnRateScale = 0.1f;
|
||||
private static float MinSpawnRateScale => GameEntry.Luban.Global.MinSpawnRateScale / 1000f;
|
||||
|
||||
private float _elapsedTime;
|
||||
private float[] _baseIntervals;
|
||||
|
||||
+8
-5
@@ -5,19 +5,22 @@ namespace SepCore.EnemyManager
|
||||
{
|
||||
public class RandomCircleSpawnStrategy : ISpawnPositionStrategy
|
||||
{
|
||||
private readonly float _spawnDistance;
|
||||
private readonly float _minDistance;
|
||||
private readonly float _maxDistance;
|
||||
|
||||
public RandomCircleSpawnStrategy(float spawnDistance)
|
||||
public RandomCircleSpawnStrategy(float minDistance, float maxDistance)
|
||||
{
|
||||
_spawnDistance = spawnDistance;
|
||||
_minDistance = minDistance;
|
||||
_maxDistance = maxDistance;
|
||||
}
|
||||
|
||||
public Vector3 GetSpawnPosition(Transform player)
|
||||
{
|
||||
float x = Random.Range(-1f, 1f);
|
||||
float z = Random.Range(-1f, 1f);
|
||||
Vector3 dir = new Vector3(x, 0, z).normalized;
|
||||
return player.position + dir * _spawnDistance;
|
||||
Vector3 dir = new Vector3(x, 0f, z).normalized;
|
||||
float distance = Random.Range(_minDistance, _maxDistance);
|
||||
return player.position + dir * distance;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user