- 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
87 lines
3.3 KiB
C#
87 lines
3.3 KiB
C#
// 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.cs(BaseGames.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++; // 加载存档后通知消费方重绘
|
||
}
|
||
}
|
||
}
|