摄像机区域的架构改动
This commit is contained in:
52
Assets/_Game/Scripts/World/Map/MapPin.cs
Normal file
52
Assets/_Game/Scripts/World/Map/MapPin.cs
Normal file
@@ -0,0 +1,52 @@
|
||||
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.cs(BaseGames.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>();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user