Files
zeling_v2/Assets/_Game/Scripts/World/Map/MapPin.cs

53 lines
2.1 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
using System.Collections.Generic;
using UnityEngine;
using BaseGames.Core;
using BaseGames.Core.Save;
namespace BaseGames.World.Map
{
/// <summary>
/// 地图自定义标记管理器(架构 15_MapShopModule §1.5)。
/// 实现 ISaveable通过 SaveManager 持久化玩家地图标记。
/// MapPin/PinType 数据类定义在 SaveData.csBaseGames.Core.Save避免循环依赖。
/// </summary>
public class MapPinManager : MonoBehaviour, ISaveable
{
private List<MapPin> _pins = new();
public IReadOnlyList<MapPin> Pins => _pins;
private void OnEnable() => ServiceLocator.GetOrDefault<ISaveableRegistry>()?.Register(this);
private void OnDisable() => ServiceLocator.GetOrDefault<ISaveableRegistry>()?.Unregister(this);
// ── 公共 API ──────────────────────────────────────────────────────────
public void AddPin(MapPin pin)
{
if (pin != null) _pins.Add(pin);
}
public void RemovePin(MapPin pin) => _pins.Remove(pin);
/// <summary>便捷方法:用枚举类型创建并添加标记。</summary>
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<MapPin>();
}
}