73 lines
2.8 KiB
C#
73 lines
2.8 KiB
C#
using System;
|
||
using System.Collections.Generic;
|
||
using System.Linq;
|
||
using UnityEngine;
|
||
|
||
namespace BaseGames.World.Map
|
||
{
|
||
/// <summary>
|
||
/// 单个房间的地图数据 SO(架构 15_MapShopModule §1.1)。
|
||
/// 资产路径: Assets/ScriptableObjects/Map/Room_{RoomId}.asset
|
||
/// </summary>
|
||
[CreateAssetMenu(menuName = "BaseGames/World/Map/RoomData")]
|
||
public class MapRoomDataSO : ScriptableObject
|
||
{
|
||
[Header("基础信息")]
|
||
public string RoomId; // 与场景名一致,如 "Room_Forest_01"
|
||
public string RegionId; // 所属区域,如 "Forest"
|
||
public string DisplayName; // 可选,地图 Tooltip
|
||
|
||
[Header("地图布局(格子坐标,单位:格)")]
|
||
public Vector2Int GridPosition; // 左下角坐标
|
||
public Vector2Int GridSize; // 宽×高(格)
|
||
|
||
[Header("房间轮廓纹理")]
|
||
public Texture2D RoomOutlineTex; // 用于地图 UI 显示房间形状(可空,回退到矩形格子)
|
||
|
||
[Header("出口信息")]
|
||
public RoomExitData[] Exits; // 该房间所有出口定义
|
||
|
||
[Header("特殊标记")]
|
||
public bool IsBossRoom;
|
||
public bool IsSavePoint;
|
||
public bool IsShop;
|
||
public Sprite MapIconOverride; // null = 按 isXxx 自动选择图标
|
||
}
|
||
|
||
[Serializable]
|
||
public struct RoomExitData
|
||
{
|
||
public string TargetRoomId; // 连接的目标房间 ID
|
||
public Vector2Int ExitGridPos; // 出口在格子地图上的位置
|
||
public ExitDirection Direction; // 出口方向
|
||
}
|
||
|
||
public enum ExitDirection { Up, Down, Left, Right }
|
||
|
||
// ─── 全局地图数据库 ──────────────────────────────────────────────────────────
|
||
|
||
/// <summary>
|
||
/// 全局地图数据库 SO(编辑器配置一次;架构 15_MapShopModule §1.1)。
|
||
/// 资产路径: Assets/ScriptableObjects/Map/MapDatabase.asset
|
||
/// </summary>
|
||
[CreateAssetMenu(menuName = "BaseGames/World/Map/MapDatabase")]
|
||
public class MapDatabaseSO : ScriptableObject
|
||
{
|
||
public MapRoomDataSO[] AllRooms;
|
||
|
||
private Dictionary<string, MapRoomDataSO> _index;
|
||
|
||
/// <summary>运行时快速查找(首次调用时建立索引)。</summary>
|
||
public MapRoomDataSO GetRoom(string roomId)
|
||
{
|
||
if (_index == null)
|
||
_index = AllRooms.Where(r => r != null)
|
||
.ToDictionary(r => r.RoomId);
|
||
_index.TryGetValue(roomId, out var r);
|
||
return r;
|
||
}
|
||
|
||
private void OnDisable() => _index = null; // SO 卸载时清理缓存
|
||
}
|
||
}
|