/// <summary> /// Load map serialized data into a map /// </summary> /// <param name="_autoTileMap"></param> public void LoadToMap( AutoTileMap _autoTileMap ) { _autoTileMap.Initialize(); _autoTileMap.ClearMap(); for( int iLayer = 0; iLayer < TileData.Count; ++iLayer ) { int iTileRepetition = 1; int iTileIdx = 0; foreach( int iType in TileData[iLayer].Tiles ) { //see compression notes in CreateFromTilemap if( iType < -1 ) { iTileRepetition = -iType; } else { for( ;iTileRepetition > 0; --iTileRepetition, ++iTileIdx ) { int tile_x = iTileIdx % TileMapWidth; int tile_y = iTileIdx / TileMapWidth; if( iType >= 0 ) { _autoTileMap.SetAutoTile( tile_x, tile_y, iType, iLayer, false); } } iTileRepetition = 1; } } } _autoTileMap.RefreshAllTiles(); _autoTileMap.RefreshMinimapTexture(); }
public void DoAction( AutoTileMap _autoTileMap ) { int tileMinX = _autoTileMap.MapTileWidth-1; int tileMinY = _autoTileMap.MapTileHeight-1; int tileMaxX = 0; int tileMaxY = 0; for( int i = 0; i < aTileData.Count; ++i ) { TileData tileData = aTileData[i]; // save prev tile type for undo action tileData.Tile_type_prev = _autoTileMap.GetAutoTile( tileData.Tile_x, tileData.Tile_y, tileData.Tile_layer ).Idx; _autoTileMap.SetAutoTile( tileData.Tile_x, tileData.Tile_y, tileData.Tile_type, tileData.Tile_layer ); tileMinX = Mathf.Min( tileMinX, tileData.Tile_x ); tileMinY = Mathf.Min( tileMinY, tileData.Tile_y ); tileMaxX = Mathf.Max( tileMaxX, tileData.Tile_x ); tileMaxY = Mathf.Max( tileMaxY, tileData.Tile_y ); } if (_autoTileMap.BrushGizmo.IsRefreshMinimapEnabled) { _autoTileMap.RefreshMinimapTexture(tileMinX, tileMinY, (tileMaxX - tileMinX) + 1, (tileMaxY - tileMinY) + 1); } _autoTileMap.UpdateChunks(); }
/// <summary> /// Load map serialized data into a map /// </summary> /// <param name="_autoTileMap"></param> public IEnumerator LoadToMap(AutoTileMap _autoTileMap) { _autoTileMap.Initialize(); _autoTileMap.ClearMap(); if( !Metadata.IsVersionAboveOrEqual("1.2.4") ) { _applyFixVersionBelow124(_autoTileMap); } int totalMapTiles = TileMapWidth * TileMapHeight; for( int iLayer = 0; iLayer < TileData.Count; ++iLayer ) { TileLayer tileData = TileData[iLayer]; _autoTileMap.MapLayers.Add( new AutoTileMap.MapLayer() { Name = tileData.Name, Visible = tileData.Visible, LayerType = tileData.LayerType, SortingOrder = tileData.SortingOrder, SortingLayer = tileData.SortingLayer, Depth = tileData.Depth, TileLayerIdx = iLayer, }); _autoTileMap.TileLayers.Add( new AutoTile[TileMapWidth * TileMapHeight] ); int iTileRepetition = 1; int iTileIdx = 0; for (int i = 0; i < tileData.Tiles.Count; ++i ) { int iType = tileData.Tiles[i]; //see compression notes in CreateFromTilemap if (iType < -1) { iTileRepetition = -iType; } else { //+++fix: FogOfWar tiles could be < -1, and this is not good for compress system, excepting ids >= -1 if (tileData.LayerType == eLayerType.FogOfWar) { iType = (iType << 1); //restore value so the lost bit was the less significant of last byte } //--- if (iTileRepetition > totalMapTiles) { Debug.LogError("Error uncompressing layer " + tileData.Name + ". The repetition of a tile was higher than map tiles " + iTileRepetition + " > " + totalMapTiles); iTileRepetition = 0; } for (; iTileRepetition > 0; --iTileRepetition, ++iTileIdx) { if (iTileIdx % 10000 == 0) { //float loadingPercent = ((float)(iTileIdx + iLayer * TileMapWidth * TileMapHeight)) / (TileMapWidth * TileMapHeight * TileData.Count); //Debug.Log(" Loading " + (int)(loadingPercent * 100) + "%"); yield return null; } int tile_x = iTileIdx % TileMapWidth; int tile_y = iTileIdx / TileMapWidth; if (iType >= 0 || tileData.LayerType == eLayerType.FogOfWar) { _autoTileMap.SetAutoTile(tile_x, tile_y, iType, iLayer, false); } } iTileRepetition = 1; } } } _autoTileMap.RefreshAllTiles(); _autoTileMap.UpdateChunkLayersData(); _autoTileMap.RefreshMinimapTexture(); }