using System.Collections; using System.Collections.Generic; using System.Linq; using UnityEngine; namespace Ether { public class GridMapMananger : SingletonAutoMono { private const string mapDataPath = "Config/MapDta"; [Header("地图信息")] public List mapDataList = new List(); //场景名字+坐标和对应的瓦片信息 private Dictionary tileDetailsDict = new Dictionary(); public override void Init() { mapDataList = Resources.LoadAll(mapDataPath).ToList(); foreach (var mapData in mapDataList) { InitTileDetailsDict(mapData); } } /// /// 根据地图信息生成字典 /// /// 地图信息 private void InitTileDetailsDict(MapData_SO mapData) { foreach (TileProperty tileProperty in mapData.tileProperties) { TileDetails tileDetails = new TileDetails { gridX = tileProperty.tileCoordinate.x, gridY = tileProperty.tileCoordinate.y }; //字典的Key string key = tileDetails.gridX + "x" + tileDetails.gridY + "y" + mapData.sceneName; if (GetTileDetails(key) != null) { tileDetails = GetTileDetails(key); } switch (tileProperty.gridType) { case GridType.Obstacle: tileDetails.isObstacle = tileProperty.boolTypeValue; break; } if (GetTileDetails(key) != null) tileDetailsDict[key] = tileDetails; else tileDetailsDict.Add(key, tileDetails); } } /// /// 根据key返回瓦片信息 /// /// x+y+地图名字 /// private TileDetails GetTileDetails(string key) { if (tileDetailsDict.ContainsKey(key)) { return tileDetailsDict[key]; } return null; } } }