地图系统
This commit is contained in:
@@ -31,6 +31,7 @@ namespace BaseGames.World.Map
|
||||
private HashSet<string> _exploredRooms = new();
|
||||
private HashSet<string> _mappedRooms = new();
|
||||
private string _currentRegionId;
|
||||
private bool _locatorEnabled; // 定位能力(指南针);控制地图玩家点是否显示,存档持久化
|
||||
private int _totalRoomCount = -1; // -1 = 未缓存;OnLoad 后重置
|
||||
private Dictionary<string, MapRoomDataSO[]> _regionCache; // R11-N6 GetRoomsByRegion 结果缓存
|
||||
private bool _isDuplicate; // Awake 检测到重复实例时置位,OnEnable/OnDisable 提前 return
|
||||
@@ -60,9 +61,10 @@ namespace BaseGames.World.Map
|
||||
|
||||
public void OnSave(SaveData data)
|
||||
{
|
||||
data.Map.ExploredRooms = new HashSet<string>(_exploredRooms);
|
||||
data.Map.MappedRooms = new HashSet<string>(_mappedRooms);
|
||||
data.Map.LastRegionId = _currentRegionId;
|
||||
data.Map.ExploredRooms = new HashSet<string>(_exploredRooms);
|
||||
data.Map.MappedRooms = new HashSet<string>(_mappedRooms);
|
||||
data.Map.LastRegionId = _currentRegionId;
|
||||
data.Map.LocatorUnlocked = _locatorEnabled;
|
||||
}
|
||||
|
||||
public void OnLoad(SaveData data)
|
||||
@@ -70,10 +72,13 @@ namespace BaseGames.World.Map
|
||||
_exploredRooms = data.Map.ExploredRooms != null ? new HashSet<string>(data.Map.ExploredRooms) : new HashSet<string>();
|
||||
_mappedRooms = data.Map.MappedRooms != null ? new HashSet<string>(data.Map.MappedRooms) : new HashSet<string>();
|
||||
_currentRegionId = data.Map.LastRegionId; // 恢复区域 ID,避免读档后首次进房误触发 EVT_RegionChanged
|
||||
_locatorEnabled = data.Map.LocatorUnlocked;
|
||||
_totalRoomCount = -1; // 强制下次调用 GetExplorationProgress 时重新计数
|
||||
|
||||
// 读档后广播:UI 仅需轻量刷新(不重建结构);订阅 OnExplorationChanged 的 UI 会 RefreshAllCells
|
||||
OnExplorationChanged?.Invoke();
|
||||
// 定位状态可能随存档变化,通知 UI 显示/隐藏玩家位置点
|
||||
OnLocatorChanged?.Invoke();
|
||||
}
|
||||
|
||||
// ── 事件驱动房间发现 ──────────────────────────────────────────────────
|
||||
@@ -136,6 +141,23 @@ namespace BaseGames.World.Map
|
||||
public bool IsExplored(string roomId) => _exploredRooms.Contains(roomId);
|
||||
public bool IsMapped(string roomId) => _mappedRooms.Contains(roomId);
|
||||
public string CurrentRegionId => _currentRegionId;
|
||||
|
||||
// ── 定位门控(指南针)─────────────────────────────────────────────────
|
||||
|
||||
/// <inheritdoc/>
|
||||
public bool IsLocatorEnabled => _locatorEnabled;
|
||||
|
||||
/// <inheritdoc/>
|
||||
public event Action OnLocatorChanged;
|
||||
|
||||
/// <inheritdoc/>
|
||||
public void SetLocatorEnabled(bool enabled)
|
||||
{
|
||||
if (_locatorEnabled == enabled) return; // 幂等:状态未变化不广播
|
||||
_locatorEnabled = enabled;
|
||||
OnLocatorChanged?.Invoke();
|
||||
}
|
||||
|
||||
public MapDatabaseSO Database => _database;
|
||||
public int ExploredRoomCount => _exploredRooms.Count;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user