Beispiel #1
0
        /// <summary>
        /// 绘制范围网格
        /// </summary>
        public override void OnMouseDowning()
        {
            cornerEnd = map.mouseCellPos;
            var leftBottom = new Vector2Int();
            var rightTop   = new Vector2Int();

            EX_Vector2Int.TwoCorner(ref leftBottom, ref rightTop, cornerBegin, cornerEnd);
            var _leftBottom = map.GridToWorld(leftBottom) - map.cellSize / 2;
            var _rightTop   = map.GridToWorld(rightTop) + map.cellSize / 2;
            var _center     = (_leftBottom + _rightTop) / 2;
            var _size       = _rightTop - _leftBottom;

            Handles.color = wireframeColor;
            Handles.DrawWireCube(_center, _size);
        }
Beispiel #2
0
        /// <summary>
        /// 鼠标抬起,若无取消,则执行矩形操作
        /// </summary>
        public override void OnMouseUp()
        {
            if (cancel)
            {
                cancel = false;
                HideOrShowLastCoverTiles(false);
                return;
            }

            var cellPositions = EX_Vector2Int.Range(cornerBegin, cornerEnd);

            for (int y = 0; y < cellPositions.Length; y++)
            {
                for (int x = 0; x < cellPositions[y].Length; x++)
                {
                    RectOperation(cellPositions[y][x]);
                }
            }
        }
Beispiel #3
0
        /// <summary>
        /// 鼠标网格位置发生变化时触发
        /// 触发频率比OnMouseDowning更低
        /// 对性能敏感的操作可放置于此
        /// </summary>
        public override void OnMouseCellPosChange()
        {
            OnMouseDowning();
            // 释放上一帧隐藏的Tile
            HideOrShowLastCoverTiles(false);

            // 暂时隐藏当前Rect覆盖位置地图中的的Tile
            var cellPositions = EX_Vector2Int.Range(cornerBegin, cornerEnd);

            lastCoverTiles = new E_PrefabTile[cellPositions.Length][];
            for (int y = 0; y < cellPositions.Length; y++)
            {
                lastCoverTiles[y] = new E_PrefabTile[cellPositions[y].Length];
                for (int x = 0; x < cellPositions[y].Length; x++)
                {
                    lastCoverTiles[y][x] = map.GetTileByCellPos(cellPositions[y][x]);
                }
            }

            HideOrShowLastCoverTiles(true);
        }
        /// <summary>
        /// 鼠标网格位置发生变化时更新
        /// </summary>
        public override void OnMouseCellPosChange()
        {
            base.OnMouseCellPosChange();
            // 获取两个角落
            var leftBottom = new Vector2Int();
            var rightTop   = new Vector2Int();

            EX_Vector2Int.TwoCorner(ref leftBottom, ref rightTop, cornerBegin, cornerEnd);
            var gridSize = rightTop - leftBottom + Vector2Int.one;
            // 生成新数组
            var tileArray2D = new E_PrefabTile[gridSize.y][];
            // 旧的参数
            var oldArray  = window.tempTileArray2D;
            var oldSize   = new Vector2Int(oldArray[0].Length, oldArray.Length);
            var oldOffset = window.tempTileArray2DOffset;
            var oldUseful = new bool[oldSize.y][];

            // 初始化利用表(不被利用的tile将被destroy)
            for (int y = 0; y < oldSize.y; y++)
            {
                oldUseful[y] = new bool[oldSize.x];
                for (int x = 0; x < oldSize.x; x++)
                {
                    oldUseful[y][x] = false;
                }
            }

            // 生成新的
            for (int y = 0; y < gridSize.y; y++)
            {
                tileArray2D[y] = new E_PrefabTile[gridSize.x];
                for (int x = 0; x < gridSize.x; x++)
                {
                    var gridPos    = new Vector2Int(x, y) + leftBottom;
                    var arrayIndex = gridPos - oldOffset;
                    // 利用重叠部分
                    if (arrayIndex.x >= 0 && arrayIndex.x < oldSize.x && arrayIndex.y >= 0 && arrayIndex.y < oldSize.y)
                    {
                        var oldTile = oldArray[arrayIndex.y][arrayIndex.x];
                        tileArray2D[y][x] = oldTile;
                        oldTile.SetCellPos(gridPos);
                        oldUseful[arrayIndex.y][arrayIndex.x] = true;
                    }
                    // 生成未有部分
                    else
                    {
                        tileArray2D[y][x] = E_PrefabTile.Create(window.currentTile);
                        tileArray2D[y][x].SetMap(window.currentMap)
                        .SetCellPos(gridPos);
                    }
                }
            }

            // 删除未利用的
            for (int y = 0; y < oldSize.y; y++)
            {
                for (int x = 0; x < oldSize.x; x++)
                {
                    if (!oldUseful[y][x])
                    {
                        oldArray[y][x].DestroySelfImmediate();
                    }
                }
            }

            // 更新参数
            window.tempTileArray2D       = tileArray2D;
            window.tempTileArray2DOffset = leftBottom;
        }