Files
zeling_v2/Assets/_Game/Scripts/World/Map/MapPin.cs
Joywayer 5cb6c2a19d Add final evaluation report for Minimap system after all fixes and improvements
- Summarized the evolution of scores across five review rounds
- Detailed the status of each evaluation dimension post-fixes
- Highlighted remaining issues and recommended future work for further enhancements
- Compared current system against industry benchmarks
2026-05-25 14:25:19 +08:00

87 lines
3.3 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.
// NOTE: 此文件包含 MapPinManager 类,但文件名为 MapPin.cs历史遗留Unity .meta 绑定限制不可安全重命名)。
// 如需搜索,请搜索 "MapPinManager" 类名,而非文件名。
using System.Collections.Generic;
using UnityEngine;
using BaseGames.Core;
using BaseGames.Core.Save;
namespace BaseGames.World.Map
{
/// <summary>标记类型与显示精灵的映射表项(从 MapPanel 移入,与数据同文件管理)。</summary>
[System.Serializable]
public class PinSpriteEntry
{
public PinType PinType;
public Sprite Sprite;
}
/// <summary>
/// 地图自定义标记管理器(架构 15_MapShopModule §1.5)。
/// 实现 <see cref="ISaveable"/> 和 <see cref="IPinService"/>,通过 ServiceLocator 对外暴露。
/// <para>
/// <see cref="PinsVersion"/> 每次 Pin 集合变化时自增外部消费方MapPanel
/// 可通过版本号判断是否需要重绘,避免无效 Instantiate。
/// </para>
/// MapPin/PinType 数据类定义在 SaveData.csBaseGames.Core.Save避免循环依赖。
/// </summary>
public class MapPinManager : MonoBehaviour, ISaveable, IPinService
{
private List<MapPin> _pins = new();
public IReadOnlyList<MapPin> Pins => _pins;
/// <summary>每次 Pin 集合发生变化时自增;外部消费方通过此版本号实现脏检查。</summary>
public int PinsVersion { get; private set; }
private void OnEnable()
{
ServiceLocator.GetOrDefault<ISaveableRegistry>()?.Register(this);
ServiceLocator.Register<IPinService>(this);
}
private void OnDisable()
{
ServiceLocator.GetOrDefault<ISaveableRegistry>()?.Unregister(this);
ServiceLocator.Unregister<IPinService>(this);
}
// ── 公共 API ──────────────────────────────────────────────────────────
public void AddPin(MapPin pin)
{
if (pin != null) { _pins.Add(pin); PinsVersion++; }
}
public void RemovePin(MapPin pin)
{
if (_pins.Remove(pin)) PinsVersion++;
}
/// <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>();
PinsVersion++; // 加载存档后通知消费方重绘
}
}
}