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:
@@ -0,0 +1,87 @@
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
namespace BaseGames.Enemies.StatusEffects
|
||||
{
|
||||
/// <summary>
|
||||
/// 状态效果管理器。
|
||||
/// 挂载在 EnemyBase 同 GameObject,负责激活效果的 Tick、叠加规则与移除。
|
||||
///
|
||||
/// 设计原则:
|
||||
/// - 同类型效果只保留一个(新效果重置计时)。
|
||||
/// - 每帧在 EnemyBase.Update 中由 Tick 驱动。
|
||||
/// - 敌人死亡时由 EnemyBase.Die 调用 Clear。
|
||||
/// </summary>
|
||||
[DisallowMultipleComponent]
|
||||
public sealed class EnemyStatusEffectManager : MonoBehaviour
|
||||
{
|
||||
private EnemyBase _enemy;
|
||||
|
||||
// 用 List 而非 Dictionary 避免 GC(通常同时激活效果 < 4 个)
|
||||
private readonly List<IStatusEffect> _active = new List<IStatusEffect>(4);
|
||||
|
||||
private void Awake() => _enemy = GetComponent<EnemyBase>();
|
||||
|
||||
// ── 外部 API ──────────────────────────────────────────────────────
|
||||
|
||||
/// <summary>施加效果。同类型效果已存在时先移除旧的再挂新的(刷新)。</summary>
|
||||
public void Apply(IStatusEffect effect)
|
||||
{
|
||||
if (effect == null) return;
|
||||
Remove(effect.Type); // 移除同类旧效果(刷新逻辑)
|
||||
_active.Add(effect);
|
||||
effect.OnApplied(_enemy);
|
||||
}
|
||||
|
||||
/// <summary>移除指定类型效果(若存在)。</summary>
|
||||
public void Remove(StatusEffectType type)
|
||||
{
|
||||
for (int i = _active.Count - 1; i >= 0; i--)
|
||||
{
|
||||
if (_active[i].Type == type)
|
||||
{
|
||||
_active[i].OnRemoved(_enemy);
|
||||
_active.RemoveAt(i);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>查询指定类型效果是否激活。</summary>
|
||||
public bool HasEffect(StatusEffectType type)
|
||||
{
|
||||
for (int i = 0; i < _active.Count; i++)
|
||||
if (_active[i].Type == type) return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
/// <summary>激活效果的只读视图(调试叠加层 / 存档用,非热路径)。</summary>
|
||||
public System.Collections.Generic.IReadOnlyList<IStatusEffect> ActiveEffects => _active;
|
||||
|
||||
/// <summary>移除全部效果(死亡 / 重生时调用)。</summary>
|
||||
public void Clear()
|
||||
{
|
||||
for (int i = _active.Count - 1; i >= 0; i--)
|
||||
_active[i].OnRemoved(_enemy);
|
||||
_active.Clear();
|
||||
}
|
||||
|
||||
// ── 每帧驱动 ─────────────────────────────────────────────────────
|
||||
|
||||
private void Update()
|
||||
{
|
||||
if (_active.Count == 0) return;
|
||||
float dt = Time.deltaTime;
|
||||
for (int i = _active.Count - 1; i >= 0; i--)
|
||||
{
|
||||
var fx = _active[i];
|
||||
fx.Tick(_enemy, dt);
|
||||
if (fx.IsFinished)
|
||||
{
|
||||
fx.OnRemoved(_enemy);
|
||||
_active.RemoveAt(i);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user