示例#1
0
        private void OnResizeTileSystem()
        {
            var tileSystem = this.target as TileSystem;

            bool eraseOutOfBounds = false;

            // Display suitable warning message to user if resized tile
            // system will cause out-of-bound tiles to be erased.
            if (TileSystemUtility.WillHaveOutOfBoundTiles(tileSystem, this.inputNewRows, this.inputNewColumns, this.inputRowOffset, this.inputColumnOffset))
            {
                if (!EditorUtility.DisplayDialog(
                        TileLang.ParticularText("Action", "Rebuild Tile System"),
                        TileLang.Text("Upon modifying tile system some tiles will become out-of-bounds and will be erased.\n\nWould you like to proceed?"),
                        TileLang.ParticularText("Action", "Yes"),
                        TileLang.ParticularText("Action", "No")
                        ))
                {
                    return;
                }

                eraseOutOfBounds = true;
            }

            Undo.RegisterFullObjectHierarchyUndo(tileSystem.gameObject, TileLang.ParticularText("Action", "Rebuild Tile System"));

            bool maintainFlag = (this.inputNewRows != tileSystem.RowCount || this.inputNewColumns != tileSystem.ColumnCount)
                ? this.inputMaintainTilePositionsInWorldResize
                : this.inputMaintainTilePositionsInWorldOffset;

            var resizer = new TileSystemResizer();

            resizer.Resize(tileSystem, this.inputNewRows, this.inputNewColumns, this.inputRowOffset, this.inputColumnOffset, this.inputNewChunkWidth, this.inputNewChunkHeight, maintainFlag, eraseOutOfBounds);

            // Refresh "Modify Grid" parameters from new state of tile system.
            this.RefreshModifyGridParamsFromTileSystem();

            SceneView.RepaintAll();
        }
        /// <summary>
        /// Adjust the number of rows, columns and/or chunk size of a tile system.
        /// </summary>
        /// <remarks>
        /// <para>This is achieved by reconstructing the data structure of the specified
        /// tile system whilst maintaining game objects that are attached to tiles where
        /// possible. Procedural chunk meshes are automatically updated to conform to the
        /// updated data structure.</para>
        /// <para>This function may take a while to complete and should not be used unless
        /// absolutely necessary.</para>
        /// </remarks>
        /// <param name="system">Tile system.</param>
        /// <param name="newRows">New number of rows.</param>
        /// <param name="newColumns">New number of columns.</param>
        /// <param name="rowOffset">Number of rows of tiles to offset by.</param>
        /// <param name="columnOffset">Number of columns of tiles to offset by.</param>
        /// <param name="chunkWidth">New chunk width.</param>
        /// <param name="chunkHeight">New chunk height.</param>
        /// <param name="maintainTilePositionsInWorld">Indicates if tile positions should
        /// be maintained in world space.</param>
        /// <seealso cref="WillHaveOutOfBoundTiles"/>
        public static void Resize(TileSystem system, int newRows, int newColumns, int rowOffset, int columnOffset, int chunkWidth, int chunkHeight, bool maintainTilePositionsInWorld)
        {
            TileSystemResizer resizer = new TileSystemResizer();

            resizer.Resize(system, newRows, newColumns, rowOffset, columnOffset, chunkWidth, chunkHeight, maintainTilePositionsInWorld, true);
        }