Files
zeling_v2/Assets/_Game/Scripts/World/Map/MapPinConfigSO.cs
Joywayer f74d7f1877 Add independent review reports for Minimap system (Rounds 8, 9, and 26)
- Round 8 report highlights improvements in architecture, editor usability, and data robustness, with a total score of 80/100.
- Round 9 report focuses on editor extension capabilities, identifying issues with room data indexing and layout editing, resulting in a score of 76/100.
- Round 26 report evaluates the system against commercial standards, noting new issues and confirming previous fixes, with a score of 95.8/100.
2026-05-25 23:15:12 +08:00

54 lines
1.8 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.Save;
namespace BaseGames.World.Map
{
/// <summary>
/// 集中管理标记类型PinType与对应 Sprite 的映射配置。
/// 替代原先分散在 MapPanel 和 MinimapHUD 中各自维护的 PinSpriteEntry 数组,
/// 两个 UI 组件共享同一资产引用,保证标记外观统一且便于策划修改。
/// <para>内部使用 <see cref="Dictionary{TKey,TValue}"/> 惰性缓存GetSprite 为 O(1) 查找。</para>
/// </summary>
[CreateAssetMenu(menuName = "BaseGames/World/Map/PinConfig")]
public class MapPinConfigSO : ScriptableObject
{
[SerializeField] private PinSpriteEntry[] _entries;
private Dictionary<PinType, Sprite> _cache;
/// <summary>
/// 根据 PinType 返回对应 SpriteO(1) 哈希查找)。
/// 首次调用时惰性构建内部字典entries 中无匹配项时返回 null。
/// </summary>
public Sprite GetSprite(PinType type)
{
EnsureCache();
return _cache.TryGetValue(type, out var s) ? s : null;
}
private void EnsureCache()
{
if (_cache != null) return;
_cache = new Dictionary<PinType, Sprite>();
if (_entries == null) return;
foreach (var e in _entries)
_cache[e.PinType] = e.Sprite;
}
private void OnValidate()
{
// 编辑器修改配置后立即重建缓存,确保 Play Mode 前数据已就绪
_cache = null;
}
}
/// <summary>标记类型与显示精灵的映射表项。</summary>
[System.Serializable]
public class PinSpriteEntry
{
public PinType PinType;
public Sprite Sprite;
}
}