修复 GameStateBattle -> GameStateShop/LevelUp 时的敌人异常残留问题
用一个 _isStopped 布尔门替代 id 追踪: - OnReset 开头置 _isStopped = true - OnInit 置 _isStopped = false - OnShowEntitySuccess:只要 _isStopped 为真且是 Enemy 组,立即 HideEntity - SpawnEnemyAsync await 恢复后也补一道 _isStopped 检查(若 await 拿到了 enemy 且已停战,直接 hide 不注册)——双保险 为什么这样对:停战窗口(Shop/LevelUp)期间本就不该有任何敌人,所以"停战期间出生的敌人一律 hide"在语义上完全正确,且不受 await 同步抽空、id 复用、加载时序任何影响。
This commit is contained in:
@@ -1,6 +1,5 @@
|
||||
using System.Collections.Generic;
|
||||
using SepCore.Entity;
|
||||
using UnityEngine;
|
||||
|
||||
namespace SepCore.EnemyManager
|
||||
{
|
||||
@@ -24,12 +23,8 @@ namespace SepCore.EnemyManager
|
||||
|
||||
public void Remove(int entityId)
|
||||
{
|
||||
if (!_enemyById.ContainsKey(entityId))
|
||||
{
|
||||
Debug.LogWarning($"EnemyRegistry: Attempt to remove non-existent entity id={entityId}");
|
||||
return;
|
||||
}
|
||||
|
||||
// 移除是幂等的。ClearEnemies 会同步清空 registry,而 HideEntity 的完成回调
|
||||
// 是异步的,晚几帧才到达,此时该 id 早已不在集合中,属正常情况,静默忽略即可。
|
||||
_enemyById.Remove(entityId);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user