using System.Collections.Generic; using UnityEngine; using BaseGames.Core; using BaseGames.Core.Save; namespace BaseGames.World.Map { /// /// 地图自定义标记管理器(架构 15_MapShopModule §1.5)。 /// 实现 ISaveable,通过 SaveManager 持久化玩家地图标记。 /// MapPin/PinType 数据类定义在 SaveData.cs(BaseGames.Core.Save)中,避免循环依赖。 /// public class MapPinManager : MonoBehaviour, ISaveable { private List _pins = new(); public IReadOnlyList Pins => _pins; private void OnEnable() => ServiceLocator.GetOrDefault()?.Register(this); private void OnDisable() => ServiceLocator.GetOrDefault()?.Unregister(this); // ── 公共 API ────────────────────────────────────────────────────────── public void AddPin(MapPin pin) { if (pin != null) _pins.Add(pin); } public void RemovePin(MapPin pin) => _pins.Remove(pin); /// 便捷方法:用枚举类型创建并添加标记。 public MapPin CreatePin(string roomId, float normX, float normY, PinType type = PinType.Marker, string note = "") { var pin = new MapPin { RoomId = roomId, NormalizedPosX = normX, NormalizedPosY = normY, PinTypeInt = (int)type, Note = note, }; AddPin(pin); return pin; } // ── ISaveable ───────────────────────────────────────────────────────── public void OnSave(SaveData data) => data.Map.Pins = _pins; public void OnLoad(SaveData data) => _pins = data.Map.Pins ?? new List(); } }