Exemplo n.º 1
0
        private void OnCentralizeUsedTileSystem()
        {
            TileIndex min, max;

            GUIUtility.keyboardControl = 0;

            this.inputMaintainTilePositionsInWorldResize = true;

            // Bail if invalid range was encountered.
            if (!TileSystemUtility.FindTileBounds(this.target, out min, out max))
            {
                this.inputRowOffset    = 0;
                this.inputColumnOffset = 0;
                return;
            }

            ++max.row;
            ++max.column;

            int boundRows    = max.row - min.row;
            int boundColumns = max.column - min.column;

            this.inputRowOffset    = -(min.row - (this.inputNewRows - boundRows) / 2);
            this.inputColumnOffset = -(min.column - (this.inputNewColumns - boundColumns) / 2);
        }
Exemplo n.º 2
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();
        }