/// <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();
		}
Ejemplo n.º 2
0
        /// <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();
        }