private static int GetRotY(TiledLayerTile tile) { if (tile.IsFlippedDiag && tile.IsFlippedHorz) { return(90); } else if (tile.IsFlippedDiag && tile.IsFlippedVert) { return(-90); } else if (tile.IsFlippedVert && tile.IsFlippedHorz) { return(180); } return(0); }
public static void ExportTerrainAlpha() { CleanSOCache(); CleanGidTilesetCache(); System.DateTime beforDT = System.DateTime.Now; if (Directory.Exists(Application.dataPath + "/TileMap/TerrainAlpha/")) { Directory.Delete(Application.dataPath + "/TileMap/TerrainAlpha/", true); } Directory.CreateDirectory(Application.dataPath + "/TileMap/TerrainAlpha/"); //加载Map TiledMap map = LoadMap(m_MapName); var globalGridSizeX = map.width; var globalGridSizeZ = map.height; //计算map分块大小 int spiltMap_w = Mathf.CeilToInt(globalGridSizeX * 1f / m_MapSpiltSize_x); int spiltMap_h = Mathf.CeilToInt(globalGridSizeZ * 1f / m_MapSpiltSize_y); //创建地形obj配置 TerrainInfo terrainInfo = GetStriptableObject <TerrainInfo>("Assets/TileMap/TerrainInfo.asset"); terrainInfo.MapSize_W = globalGridSizeX; terrainInfo.MapSize_H = globalGridSizeZ; terrainInfo.SpiltMapSize_W = spiltMap_w; terrainInfo.SpiltMapSize_H = spiltMap_h; terrainInfo.SpiltMap_X = m_MapSpiltSize_x; terrainInfo.SpiltMap_Y = m_MapSpiltSize_y; terrainInfo.TerrainAlphaList = new bool[m_MapSpiltSize_x * m_MapSpiltSize_y]; //物件分块数据 Dictionary <string, TiledLayer> _layerDic = new Dictionary <string, TiledLayer>(); for (int i = 0; i < map.layers.Length; i++) { var layer = map.layers[i]; string layerName = layer.name; _layerDic.Add(layerName, layer); } var terrainAlphaTiles1 = _layerDic.ContainsKey(TerrainAlphaLayer1Name) ? _layerDic[TerrainAlphaLayer1Name].GetTiles() : null; var terrainAlphaTiles2 = _layerDic.ContainsKey(TerrainAlphaLayer2Name) ? _layerDic[TerrainAlphaLayer2Name].GetTiles() : null; var terrainAlphaTiles3 = _layerDic.ContainsKey(TerrainAlphaLayer3Name) ? _layerDic[TerrainAlphaLayer3Name].GetTiles() : null; int globalSize = globalGridSizeX * globalGridSizeZ; for (int i = 0; i < globalSize; i++) { // EditorUtility.DisplayProgressBar("ExportTerrainAlpha", i+"/"+(globalSize), i / (float)globalSize); TiledLayerTile _terrainAlphaTile = new TiledLayerTile(); int _terrainAlphaIndex = 0; // int _terainAlphaRY = 0; string _terrainAlphaName = ""; uint _level = 0; if (terrainAlphaTiles3 != null) { _terrainAlphaTile = terrainAlphaTiles3[i]; int index; string itemName = GetTilesetNameAndIndex(map, _terrainAlphaTile.Gid, out index); if (index == 1) { _terrainAlphaIndex = index; _terrainAlphaName = itemName; _level = 3; } } if (terrainAlphaTiles2 != null) { _terrainAlphaTile = terrainAlphaTiles2[i]; int index; string itemName = GetTilesetNameAndIndex(map, _terrainAlphaTile.Gid, out index); if (index == 1) { _terrainAlphaIndex = index; _terrainAlphaName = itemName; _level = 2; } } if (terrainAlphaTiles1 != null) { _terrainAlphaTile = terrainAlphaTiles1[i]; int index; string itemName = GetTilesetNameAndIndex(map, _terrainAlphaTile.Gid, out index); if (index == 1) { _terrainAlphaIndex = index; _terrainAlphaName = itemName; _level = 1; } } if (_terrainAlphaIndex == 1) { int X = _terrainAlphaTile.X; int Y = _terrainAlphaTile.Y; int itemIndex_x = X / spiltMap_w; int itemIndex_y = Y / spiltMap_h; terrainInfo.TerrainAlphaList[itemIndex_x * m_MapSpiltSize_x + itemIndex_y] = true; var _mapinfo = GetStriptableObject <AlphaTexInfo>(string.Format("Assets/TileMap/TerrainAlpha/TerrainAlpha_{0}_{1}.asset", itemIndex_x, itemIndex_y)); int _posIndex = Y * globalGridSizeX + X; AlphaTexInfo_S alphaTexInfo = new AlphaTexInfo_S(); alphaTexInfo.objName = _terrainAlphaName; alphaTexInfo.level = _level; _mapinfo.posIndex.Add(_posIndex); _mapinfo.terrainAlphaList.Add(alphaTexInfo); // UnityEditor.EditorUtility.SetDirty(_mapinfo); } } System.DateTime afterDT = System.DateTime.Now; System.TimeSpan ts = afterDT.Subtract(beforDT); Debug.Log(ts.TotalSeconds); EditorUtility.ClearProgressBar(); CleanSOCache(); CleanGidTilesetCache(); UnityEditor.AssetDatabase.SaveAssets(); }
public static void ExportObj() { CleanSOCache(); CleanGidTilesetCache(); System.DateTime beforDT = System.DateTime.Now; if (Directory.Exists(Application.dataPath + "/TileMap/ItemInfo/")) { Directory.Delete(Application.dataPath + "/TileMap/ItemInfo/", true); } Directory.CreateDirectory(Application.dataPath + "/TileMap/ItemInfo/"); //加载Map TiledMap map = LoadMap(m_MapName); var globalGridSizeX = map.width; var globalGridSizeZ = map.height; //计算map分块大小 int spiltMap_w = Mathf.CeilToInt(globalGridSizeX * 1f / m_MapSpiltSize_x); int spiltMap_h = Mathf.CeilToInt(globalGridSizeZ * 1f / m_MapSpiltSize_y); //创建地形obj配置 TerrainInfo terrainInfo = GetStriptableObject <TerrainInfo>("Assets/TileMap/TerrainInfo.asset"); terrainInfo.MapSize_W = globalGridSizeX; terrainInfo.MapSize_H = globalGridSizeZ; terrainInfo.SpiltMapSize_W = spiltMap_w; terrainInfo.SpiltMapSize_H = spiltMap_h; terrainInfo.SpiltMap_X = m_MapSpiltSize_x; terrainInfo.SpiltMap_Y = m_MapSpiltSize_y; terrainInfo.ItemInfoList = new bool[m_MapSpiltSize_x * m_MapSpiltSize_y]; //物件分块数据 Dictionary <string, TiledLayer> _layerDic = new Dictionary <string, TiledLayer>(); for (int i = 0; i < map.layers.Length; i++) { var layer = map.layers[i]; string layerName = layer.name; _layerDic.Add(layerName, layer); } var unRemoveTiles = _layerDic.ContainsKey(UnRemovableItemLayerName) ? _layerDic[UnRemovableItemLayerName].GetTiles() : null; var removableTiles = _layerDic.ContainsKey(RemovableItemLayerName) ? _layerDic[RemovableItemLayerName].GetTiles() : null; int globalSize = globalGridSizeX * globalGridSizeZ; for (int i = 0; i < globalSize; i++) { // EditorUtility.DisplayProgressBar("ExportObj", i+"/"+(globalSize), i / (float)globalSize); TiledLayerTile _unRemoveTile = new TiledLayerTile(); int _unRemoveID = 0; // int _unRemoveRY = 0; string _unRemoveName = ""; if (unRemoveTiles != null) { _unRemoveTile = unRemoveTiles[i]; // _unRemoveRY = GetRotY(_unRemoveTile); _unRemoveID = _unRemoveTile.Gid; _unRemoveName = GetTilesetNameAndIndex(map, _unRemoveTile.Gid, out _unRemoveID); } TiledLayerTile _removableTile = new TiledLayerTile(); int _removableID = 0; // int _removableRY = 0; string _removableName = ""; if (removableTiles != null) { _removableTile = removableTiles[i]; // _removableRY = GetRotY(_removableTile); _removableID = _removableTile.Gid; _removableName = GetTilesetNameAndIndex(map, _removableTile.Gid, out _removableID); } if (_unRemoveID == 1 || _removableID == 1) { int X = _unRemoveID != 0 ? _unRemoveTile.X : _removableTile.X; int Y = _unRemoveID != 0 ? _unRemoveTile.Y : _removableTile.Y; int itemIndex_x = X / spiltMap_w; int itemIndex_y = Y / spiltMap_h; terrainInfo.ItemInfoList[itemIndex_x * m_MapSpiltSize_x + itemIndex_y] = true; var _mapinfo = GetStriptableObject <ItemMapInfo>(string.Format("Assets/TileMap/ItemInfo/ItemInfo_{0}_{1}.asset", itemIndex_x, itemIndex_y)); int _posIndex = Y * globalGridSizeX + X; string itemName = _unRemoveID == 1 ? _unRemoveName : _removableName; // objInfo.itemRotY = _unRemoveID == 1 ? _unRemoveRY : _removableRY; _mapinfo.posIndex.Add(_posIndex); _mapinfo.itemNameList.Add(itemName); // UnityEditor.EditorUtility.SetDirty(_mapinfo); } } System.DateTime afterDT = System.DateTime.Now; System.TimeSpan ts = afterDT.Subtract(beforDT); Debug.Log(ts.TotalSeconds); EditorUtility.ClearProgressBar(); // UnityEditor.EditorUtility.SetDirty(terrainInfo); CleanSOCache(); CleanGidTilesetCache(); UnityEditor.AssetDatabase.SaveAssets(); }