Пример #1
0
        /// <summary>
        /// Creates and return an event tile.
        /// </summary>
        /// <param name="tile">The base tile.</param>
        /// <param name="eventsMap">The event map where the tile sits in.</param>
        /// <param name="x">The x position inside the map (column of the map).</param>
        /// <param name="y">The y position inside the map (row of the map).</param>
        /// <returns>The created EventTile.</returns>
        public static EventTile CreateEvent(TileBase tile, Tilemap eventsMap, int x, int y)
        {
            var eventTile = new EventTile {
                Tile = tile
            };

            eventTile.Name = "Tile " + x + ":" + y;

            eventTile.SetPosition(eventsMap, x, y);

            return(eventTile);
        }
Пример #2
0
        /// <summary>
        /// Creates the Tiles list.
        /// </summary>
        /// <param name="editor">True if in editor mode.</param>
        public void CreateTilesList(bool editor = false)
        {
            Init(editor);

            var bounds  = eventsMap.cellBounds;
            var offsetX = bounds.x - lastMapBounds.x;
            var offsetY = bounds.y - lastMapBounds.y;

            lastMapBounds = bounds;
            var allTiles = eventsMap.GetTilesBlock(eventsMap.cellBounds);

            if (offsetX != 0 || offsetY != 0)
            {
                Tiles.All
                (
                    t =>
                {
                    t.SetPosition(eventsMap, t.X - offsetX, t.Y - offsetY);
                    return(true);
                }
                );
            }

            for (var x = 0; x < bounds.size.x; x++)
            {
                for (var y = 0; y < bounds.size.y; y++)
                {
                    var tile = allTiles[x + y * bounds.size.x];

                    if (tile != null && !Contains(x, y))
                    {
                        Tiles.Add(EventTile.CreateEvent(tile, eventsMap, x, y));
                        Tiles = Tiles.OrderBy(t => t.X).ThenBy(t => t.Y).ToList();
                    }
                }
            }
        }