feat: Implement Room Streaming System
- Add RoomStreamingManager to manage room loading and unloading based on player proximity. - Create StreamingBudgetConfigSO for memory and performance budgeting of the streaming system. - Introduce TransitionDirector to handle seamless and atmospheric fade transitions between rooms. - Develop WorldGraph to represent room connectivity and facilitate neighbor queries and distance calculations. - Implement RoomNode and RoomEdge classes to structure room data and connections.
This commit is contained in:
@@ -1,32 +1,57 @@
|
||||
#if GRAPH_DESIGNER
|
||||
#if GRAPH_DESIGNER
|
||||
using UnityEngine;
|
||||
using Opsive.BehaviorDesigner.Runtime.Tasks;
|
||||
using Opsive.BehaviorDesigner.Runtime.Tasks.Actions;
|
||||
using BaseGames.Enemies;
|
||||
using UnityEngine;
|
||||
using BaseGames.Enemies.Perception;
|
||||
|
||||
namespace BaseGames.Enemies.AI
|
||||
{
|
||||
/// <summary>
|
||||
/// BD Action:敌人巡逻行为。
|
||||
/// 持续令敌人向当前朝向移动,遇墙/边缘时自动转向。
|
||||
/// BD Action:来回踱步巡逻——持续向当前方向移动,遇墙或悬崖时自动翻转方向。
|
||||
///
|
||||
/// 若需要按预设路点顺序巡逻,请使用 <see cref="BD_PatrolWaypoints"/>(支持 Transform 引用和内联坐标)。
|
||||
///
|
||||
/// 转向检测优先级:
|
||||
/// <list type="number">
|
||||
/// <item>EnemySensorHub "wall_ahead" / "ledge" 槽(SensorToolkit,已配置时使用)</item>
|
||||
/// <item>Physics2D Raycast 兜底(Prefab 未配置 Sensor 时自动启用)</item>
|
||||
/// </list>
|
||||
/// </summary>
|
||||
[TaskName("Patrol (Pace)")]
|
||||
[TaskCategory("BaseGames/Enemy/Movement")]
|
||||
[TaskDescription("来回踱步巡逻:遇墙或悬崖自动翻转方向(SensorToolkit 优先)")]
|
||||
public class BD_Patrol : Action
|
||||
{
|
||||
[Tooltip("检测地面边缘的向下射线长度")]
|
||||
[Tooltip("(兜底)检测地面边缘的向下射线长度(m)")]
|
||||
public float edgeCheckLength = 1.2f;
|
||||
[Tooltip("检测障碍物的水平射线长度")]
|
||||
[Tooltip("(兜底)检测障碍物的水平射线长度(m)")]
|
||||
public float wallCheckLength = 0.4f;
|
||||
[Tooltip("地面/墙壁 LayerMask")]
|
||||
[Tooltip("(兜底)边缘检测射线起点相对角色的前向偏移(m)")]
|
||||
public float edgeCheckFwdOffset = 0.3f;
|
||||
[Tooltip("(兜底)边缘检测射线起点相对角色的向下偏移(m)")]
|
||||
public float edgeCheckDownOffset = 0.1f;
|
||||
[Tooltip("(兜底)地面/墙壁 LayerMask")]
|
||||
public LayerMask groundLayer;
|
||||
|
||||
private EnemyBase _enemy;
|
||||
private float _dir = 1f;
|
||||
private EnemyBase _enemy;
|
||||
private EnemySensorHub _hub;
|
||||
private float _dir = 1f;
|
||||
|
||||
public override void OnStart()
|
||||
// 缓存:SensorHub 中对应槽位是否已配置(Awake 时查询一次,避免每帧 Dictionary 查找)
|
||||
private bool _hasWallSensor;
|
||||
private bool _hasEdgeSensor;
|
||||
|
||||
public override void OnAwake()
|
||||
{
|
||||
_enemy = GetComponent<EnemyBase>();
|
||||
_enemy = GetComponent<EnemyBase>();
|
||||
_hub = GetComponent<EnemySensorHub>();
|
||||
_hasWallSensor = _hub != null && _hub.Get(SensorSlotNames.WallAhead) != null;
|
||||
_hasEdgeSensor = _hub != null && _hub.Get(SensorSlotNames.Ledge) != null;
|
||||
}
|
||||
|
||||
public override void OnStart() => _enemy?.SetAiPhase(AiPhase.Patrol);
|
||||
|
||||
public override TaskStatus OnUpdate()
|
||||
{
|
||||
if (_enemy == null) return TaskStatus.Failure;
|
||||
@@ -38,27 +63,33 @@ namespace BaseGames.Enemies.AI
|
||||
return TaskStatus.Running;
|
||||
}
|
||||
|
||||
public override void OnEnd()
|
||||
{
|
||||
_enemy?.StopMovement();
|
||||
}
|
||||
public override void OnEnd() => _enemy?.StopMovement();
|
||||
|
||||
private bool ShouldFlip()
|
||||
{
|
||||
Transform t = _enemy.transform;
|
||||
Vector2 pos = t.position;
|
||||
if (_hub != null)
|
||||
{
|
||||
// 有传感器配置:用传感器结果,完全跳过 Raycast
|
||||
if (_hasWallSensor || _hasEdgeSensor)
|
||||
{
|
||||
bool wallHit = _hasWallSensor && _hub.HasAnyDetection(SensorSlotNames.WallAhead);
|
||||
bool edgeHit = _hasEdgeSensor && _hub.HasAnyDetection(SensorSlotNames.Ledge);
|
||||
return wallHit || edgeHit;
|
||||
}
|
||||
}
|
||||
|
||||
// 前方边缘检测:在脚前方向下射线,若无地面则转向
|
||||
Vector2 edgeOrigin = pos + Vector2.right * (_dir * 0.3f) + Vector2.down * 0.1f;
|
||||
// Raycast 兜底:仅在未配置 Sensor 时执行
|
||||
Transform t = _enemy.transform;
|
||||
Vector2 pos = t.position;
|
||||
|
||||
Vector2 edgeOrigin = pos + Vector2.right * (_dir * edgeCheckFwdOffset) + Vector2.down * edgeCheckDownOffset;
|
||||
bool hasGround = Physics2D.Raycast(edgeOrigin, Vector2.down, edgeCheckLength, groundLayer);
|
||||
if (!hasGround) return true;
|
||||
|
||||
// 前方障碍检测:水平射线,若撞墙则转向
|
||||
bool hitWall = Physics2D.Raycast(pos, Vector2.right * _dir, wallCheckLength, groundLayer);
|
||||
if (hitWall) return true;
|
||||
|
||||
return false;
|
||||
return hitWall;
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
Reference in New Issue
Block a user