/// <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) }; }
/// <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; }