从 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)
|
||||
|
||||
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 302bed92b8cc83341aa3762deb8b56be
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
+9
@@ -0,0 +1,9 @@
|
||||
using UnityEngine;
|
||||
|
||||
namespace SepCore.EnemyManager
|
||||
{
|
||||
public interface ISpawnPositionStrategy
|
||||
{
|
||||
Vector3 GetSpawnPosition(Transform player);
|
||||
}
|
||||
}
|
||||
+11
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 71ed05cb0cc806b43a28fc4492963dd2
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
+23
@@ -0,0 +1,23 @@
|
||||
using UnityEngine;
|
||||
using Random = UnityEngine.Random;
|
||||
|
||||
namespace SepCore.EnemyManager
|
||||
{
|
||||
public class RandomCircleSpawnStrategy : ISpawnPositionStrategy
|
||||
{
|
||||
private readonly float _spawnDistance;
|
||||
|
||||
public RandomCircleSpawnStrategy(float spawnDistance)
|
||||
{
|
||||
_spawnDistance = spawnDistance;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
+11
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 12331e41ea431384aa2d6a60da5f4c13
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in New Issue
Block a user