44 lines
1.4 KiB
C#
44 lines
1.4 KiB
C#
#if GRAPH_DESIGNER
|
||
using UnityEngine;
|
||
using Opsive.BehaviorDesigner.Runtime.Tasks;
|
||
using Opsive.BehaviorDesigner.Runtime.Tasks.Actions;
|
||
using BaseGames.Core;
|
||
using BaseGames.Core.Pool;
|
||
using BaseGames.Enemies;
|
||
|
||
namespace BaseGames.Enemies.AI
|
||
{
|
||
/// <summary>
|
||
/// BD Action:Boss 专用召唤小兵。
|
||
/// 通过 GlobalObjectPool 在 Boss 周围生成 MinionPrefabKey 对应的敌人。
|
||
/// </summary>
|
||
public class BD_SummonMinions : Action
|
||
{
|
||
[SerializeField] private string m_MinionPrefabKey = "";
|
||
[SerializeField] private int m_Count = 2;
|
||
[SerializeField] private float m_SpawnRadius = 3f;
|
||
|
||
public override TaskStatus OnUpdate()
|
||
{
|
||
if (string.IsNullOrEmpty(m_MinionPrefabKey)) return TaskStatus.Failure;
|
||
|
||
var pool = ServiceLocator.GetOrDefault<IObjectPoolService>();
|
||
if (pool == null) return TaskStatus.Failure;
|
||
|
||
for (int i = 0; i < m_Count; i++)
|
||
{
|
||
var angle = Random.Range(0f, 360f) * Mathf.Deg2Rad;
|
||
var offset = new Vector2(Mathf.Cos(angle), 0f) * m_SpawnRadius;
|
||
var spawnPos = new Vector3(
|
||
transform.position.x + offset.x,
|
||
transform.position.y + offset.y,
|
||
0f);
|
||
pool.Spawn(m_MinionPrefabKey, spawnPos, Quaternion.identity);
|
||
}
|
||
|
||
return TaskStatus.Success;
|
||
}
|
||
}
|
||
}
|
||
#endif
|