Exemplo n.º 1
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="tile"></param>
        /// <param name="eventsMap"></param>
        /// <param name="x"></param>
        /// <param name="y"></param>
        /// <returns></returns>
        public static TileEvent CreateEvent(TileBase tile, Tilemap eventsMap, int x, int y)
        {
            var instance = new TileEvent {
                _tile = tile
            };

            instance._name = "Tile " + x + ":" + y;
            instance.SetPosition(eventsMap, x, y);

            return(instance);
        }
Exemplo n.º 2
0
        /// <summary>
        /// タイルリストを作成する
        /// </summary>
        /// <param name="isEditor"></param>
        public void CreateTilesList(bool isEditor = false)
        {
            Init(isEditor);

            var bounds  = _eventsMap.cellBounds;
            var offsetX = bounds.x - _lastMapBounds.x;
            var offsetY = bounds.y - _lastMapBounds.y;

            _lastMapBounds = bounds;

            // GetTilesBlock : 指定された範囲に存在するタイルを配列で返す
            var allTiles = _eventsMap.GetTilesBlock(_eventsMap.cellBounds);

            if (offsetX != 0 || offsetY != 0)
            {
                foreach (var elm in Tiles)
                {
                    elm.SetPosition(_eventsMap, elm.PosX - offsetX, elm.PosY - offsetY);
                }
            }

            bool isAdd = false;

            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))
                    {
                        continue;
                    }

                    Tiles.Add(TileEvent.CreateEvent(tile, _eventsMap, x, y));
                    isAdd = true;
                }
            }

            if (isAdd)
            {
                Tiles = Tiles.OrderBy(t => t.PosX).ThenBy(t => t.PosY).ToList();
            }
        }