/// <summary> /// 生成小地图 /// </summary> private void GenerateMap() { Vector3Int min, max, size; if (!CheckTileMapsValid(out min, out max, out size)) { return; } if (!Directory.Exists(miniMapGenerateDirPath)) { Directory.CreateDirectory(miniMapGenerateDirPath); } var mapTexture = new Texture2D(size.x, size.y, TextureFormat.ARGB32, false); mapTexture.filterMode = FilterMode.Point; foreach (var info in tileMapInfos) { if (!info.enable) { continue; } // 对于每一个TileMap都要把他们绘制到地图上 var tileMapSize = info.tileMap.size; var tileMapMin = info.tileMap.cellBounds.min; for (var i = 0; i < tileMapSize.x; i++) { for (var j = 0; j < tileMapSize.y; j++) { var pos = new Vector3Int(tileMapMin.x + i, tileMapMin.y + j, 0); var tile = info.tileMap.GetTile(pos); if (tile != null) { mapTexture.SetPixel(info.offset.x + i, info.offset.y + j, info.color); } } } } #region 自定义背景颜色 for (var i = 0; i < size.x; i++) { for (var j = 0; j < size.y; j++) { var color = mapTexture.GetPixel(i, j); if (color.EqualsTo(defaultColor)) { mapTexture.SetPixel(i, j, emptyColor); } } } #endregion #region 持久化保存 mapTexture.Apply(); var filePath = $"Assets/{miniMapGenerateDirPath.GetAfterSubstring($"{Application.dataPath}/")}/Map_{sceneName}.asset"; AssetDatabase.CreateAsset(mapTexture, filePath); AssetDatabase.Refresh(); #endregion ProjectWindowUtil.ShowCreatedAsset(mapTexture); ResourceMgr.GenerateResourcesConst("HighFive", "Const", "Auto"); }