/// <summary>
 /// 鼠标按下
 /// </summary>
 public override void OnMouseDown()
 {
     // 设置cornerBegin
     base.OnMouseDown();
     // 初始化临时存储数组
     window.tempTileArray2D       = new E_PrefabTile[1][];
     window.tempTileArray2DOffset = map.mouseCellPos;
     window.tempTileArray2D[0]    = new[]
     {
         E_PrefabTile.Create(window.currentTile).SetMap(map).SetCellPos(map.mouseCellPos)
     };
 }
Esempio n. 2
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);
        }
Esempio n. 3
0
 public override void Update()
 {
     base.Update();
     // 更新笔头位置
     if (pencilHead != null)
     {
         pencilHead.SetCellPos(map.mouseCellPos);
     }
     // 隐藏笔头位置的地图元素
     if (!window.isMouseDowning)
     {
         if (lastCoverTile != null)
         {
             lastCoverTile.TempShow();
         }
         lastCoverTile = map.GetTileByCellPos(map.mouseCellPos);
         if (lastCoverTile != null)
         {
             lastCoverTile.TempHide();
         }
     }
 }
Esempio n. 4
0
 /// <summary>
 /// 重新生成笔头
 /// </summary>
 private void ReGeneratePencilHead()
 {
     DestroyPencilHead();
     pencilHead = E_PrefabTile.Create(window.currentTile)?.SetMap(map).SetCellPos(map.mouseCellPos);
 }
        /// <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;
        }