从 EnemyManager 中拆分刷怪位置策略接口
This commit is contained in:
parent
43f81c8926
commit
b6a13b18fc
|
|
@ -8,7 +8,6 @@ using SepCore.AsyncTask;
|
||||||
using SepCore.CustomUtility;
|
using SepCore.CustomUtility;
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
using UnityGameFramework.Runtime;
|
using UnityGameFramework.Runtime;
|
||||||
using Random = UnityEngine.Random;
|
|
||||||
|
|
||||||
namespace SepCore.EnemyManager
|
namespace SepCore.EnemyManager
|
||||||
{
|
{
|
||||||
|
|
@ -47,6 +46,7 @@ namespace SepCore.EnemyManager
|
||||||
private float _spawnRateScale = 1f;
|
private float _spawnRateScale = 1f;
|
||||||
|
|
||||||
private Transform _player;
|
private Transform _player;
|
||||||
|
private ISpawnPositionStrategy _spawnPositionStrategy;
|
||||||
|
|
||||||
public float SpawnRateScale => _spawnRateScale;
|
public float SpawnRateScale => _spawnRateScale;
|
||||||
public float BattleDuration => _duration;
|
public float BattleDuration => _duration;
|
||||||
|
|
@ -76,6 +76,7 @@ namespace SepCore.EnemyManager
|
||||||
public void OnInit(DRLevel level, Player player)
|
public void OnInit(DRLevel level, Player player)
|
||||||
{
|
{
|
||||||
_player = player != null ? player.CachedTransform : null;
|
_player = player != null ? player.CachedTransform : null;
|
||||||
|
_spawnPositionStrategy = new RandomCircleSpawnStrategy(_spawnDistanceFromPlayer);
|
||||||
|
|
||||||
_baseSpawnEnemyIntervals = (float[])level.Intervals.Clone();
|
_baseSpawnEnemyIntervals = (float[])level.Intervals.Clone();
|
||||||
_spawnEnemyIntervals = (float[])_baseSpawnEnemyIntervals.Clone();
|
_spawnEnemyIntervals = (float[])_baseSpawnEnemyIntervals.Clone();
|
||||||
|
|
@ -136,7 +137,7 @@ namespace SepCore.EnemyManager
|
||||||
if (_currentEnemyCount >= _spawnEnemyMaxCount) return;
|
if (_currentEnemyCount >= _spawnEnemyMaxCount) return;
|
||||||
int entityPoolId = _currentSpawnEnemyId % _spawnEnemyMaxCount;
|
int entityPoolId = _currentSpawnEnemyId % _spawnEnemyMaxCount;
|
||||||
var enemyData = EntityDataFactory.Create(entityPoolId, enemyType, _currentLevel);
|
var enemyData = EntityDataFactory.Create(entityPoolId, enemyType, _currentLevel);
|
||||||
enemyData.Position = GetRandomPosition();
|
enemyData.Position = _spawnPositionStrategy.GetSpawnPosition(_player);
|
||||||
_currentSpawnEnemyId++;
|
_currentSpawnEnemyId++;
|
||||||
|
|
||||||
EnemyBase enemy = await _entity.ShowEnemyAsync(enemyData);
|
EnemyBase enemy = await _entity.ShowEnemyAsync(enemyData);
|
||||||
|
|
@ -148,14 +149,6 @@ namespace SepCore.EnemyManager
|
||||||
RegisterEnemy(enemy);
|
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()
|
public void ClearEnemies()
|
||||||
{
|
{
|
||||||
foreach (var enemy in _enemies)
|
foreach (var enemy in _enemies)
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,8 @@
|
||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 302bed92b8cc83341aa3762deb8b56be
|
||||||
|
folderAsset: yes
|
||||||
|
DefaultImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
|
|
@ -0,0 +1,9 @@
|
||||||
|
using UnityEngine;
|
||||||
|
|
||||||
|
namespace SepCore.EnemyManager
|
||||||
|
{
|
||||||
|
public interface ISpawnPositionStrategy
|
||||||
|
{
|
||||||
|
Vector3 GetSpawnPosition(Transform player);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,11 @@
|
||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 71ed05cb0cc806b43a28fc4492963dd2
|
||||||
|
MonoImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
serializedVersion: 2
|
||||||
|
defaultReferences: []
|
||||||
|
executionOrder: 0
|
||||||
|
icon: {instanceID: 0}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
|
|
@ -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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,11 @@
|
||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 12331e41ea431384aa2d6a60da5f4c13
|
||||||
|
MonoImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
serializedVersion: 2
|
||||||
|
defaultReferences: []
|
||||||
|
executionOrder: 0
|
||||||
|
icon: {instanceID: 0}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
Loading…
Reference in New Issue