多轮审查和修复
This commit is contained in:
39
Assets/Scripts/Enemies/AI/BD_SpawnProjectile.cs
Normal file
39
Assets/Scripts/Enemies/AI/BD_SpawnProjectile.cs
Normal file
@@ -0,0 +1,39 @@
|
||||
#if GRAPH_DESIGNER
|
||||
using UnityEngine;
|
||||
using Opsive.BehaviorDesigner.Runtime.Tasks;
|
||||
using Opsive.BehaviorDesigner.Runtime.Tasks.Actions;
|
||||
using BaseGames.Core;
|
||||
using BaseGames.Core.Pool;
|
||||
|
||||
namespace BaseGames.Enemies.AI
|
||||
{
|
||||
/// <summary>
|
||||
/// BD Action:在敌人当前位置生成弹射物。
|
||||
/// ProjectileKey 为 Addressable 键,通过 GlobalObjectPool 实例化。
|
||||
/// </summary>
|
||||
public class BD_SpawnProjectile : Action
|
||||
{
|
||||
[SerializeField] private Vector2 m_Direction = Vector2.right;
|
||||
[SerializeField] private string m_ProjectileKey = "";
|
||||
[SerializeField] private float m_Speed = 8f;
|
||||
|
||||
public override TaskStatus OnUpdate()
|
||||
{
|
||||
if (string.IsNullOrEmpty(m_ProjectileKey)) return TaskStatus.Failure;
|
||||
|
||||
var pool = ServiceLocator.GetOrDefault<IObjectPoolService>();
|
||||
if (pool == null) return TaskStatus.Failure;
|
||||
|
||||
var go = pool.Spawn(m_ProjectileKey, transform.position, Quaternion.identity);
|
||||
if (go != null)
|
||||
{
|
||||
var rb = go.GetComponent<Rigidbody2D>();
|
||||
if (rb != null)
|
||||
rb.velocity = m_Direction.normalized * m_Speed;
|
||||
}
|
||||
|
||||
return TaskStatus.Success;
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
Reference in New Issue
Block a user