private void CheckPieces(List <EditorLevelPiece> pieces, List <GridVO> grids) { while (grids.Count > 0) { GridVO grid = grids[0]; grids.RemoveAt(0); EditorLevelPiece piece = new EditorLevelPiece(); pieces.Add(piece); piece.grids.Add(new EditorLevelPieceGrid(grid.x.value, grid.y.value, grid.color.value)); bool find = true; while (find) { find = false; for (int i = 0; i < piece.grids.Count; i++) { GridVO nextGrid = GetGridNextTo(piece.grids[i].x, piece.grids[i].y, piece.grids[i].color, grids); if (nextGrid != null) { grids.Remove(nextGrid); piece.grids.Add(new EditorLevelPieceGrid(nextGrid.x.value, nextGrid.y.value, nextGrid.color.value)); find = true; } } } } }
private void SetPiece(EditorLevelPiece piece) { List <GridVO> grids = EditorVO.Instance.piecesGrids; int minx = piece.grids[0].x; int maxy = piece.grids[0].y; for (int i = 1; i < piece.grids.Count; i++) { if (piece.grids[i].x < minx) { minx = piece.grids[i].x; } if (piece.grids[i].y > maxy) { maxy = piece.grids[i].y; } } int offx = minx % 2 == 0 ? -minx : -minx + 1; int offy = -maxy; for (int y = 0; y > -10; y--) { for (int x = 0; x < 22; x++, x++) { bool find = true; for (int i = 0; i < piece.grids.Count; i++) { GridVO grid = EditorVO.Instance.GetGridPiece((int)piece.grids[i].x + offx + x, (int)piece.grids[i].y + offy + y); if (grid == null || grid.color.value != 0) { find = false; break; } else { //获取周围的格子 List <Point2D> nextCoords = HaxgonCoord <Point2D> .GetCoordsNextTo(Point2D.Create((int)piece.grids[i].x + offx + x, (int)piece.grids[i].y + offy + y)); for (int n = 0; n < nextCoords.Count; n++) { GridVO nextGrid = EditorVO.Instance.GetGridPiece((int)nextCoords[n].x, (int)nextCoords[n].y); if (nextGrid != null && nextGrid.color.value != 0 && nextGrid.color.value != grid.color.value) { find = false; break; } } } } if (find) { for (int i = 0; i < piece.grids.Count; i++) { EditorVO.Instance.GetGridPiece((int)piece.grids[i].x + offx + x, (int)piece.grids[i].y + offy + y).color.value = piece.grids[i].color; } return; } } } }
public EditorVO() { Dropdown.OptionData op = new Dropdown.OptionData(); op.text = "无"; op.image = ResourceManager.CreateSprite("image/grid/gridBg"); colors.Add(op); for (int i = 0; i < 12; i++) { op = new Dropdown.OptionData(); op.text = "颜色" + (i + 1); op.image = ResourceManager.CreateSprite("image/grid/" + (i + 1)); colors.Add(op); } color.value = 1; //生成格子 for (int x = 0; x < 11; x++) { for (int y = 0; y > -7; y--) { GridVO grid = new GridVO(); grid.x = new Int(x); grid.y = new Int(y); grid.color = new Int(); grids.Add(grid); } } //生成干扰格子 for (int x = 0; x < 11; x++) { for (int y = 0; y > -7; y--) { GridVO grid = new GridVO(); grid.x = new Int(x); grid.y = new Int(y); grid.color = new Int(); otherGrids1.Add(grid); } } //生成片的格子 for (int x = 0; x < 22; x++) { for (int y = 0; y > -10; y--) { GridVO grid = new GridVO(); grid.x = new Int(x); grid.y = new Int(y); grid.color = new Int(); piecesGrids.Add(grid); } } }
// Update is called once per frame void Update() { EditorMainThread.Instance.Update(); CheckThread.Instance.Update(); if (Input.GetAxis("Fire1") > 0 && lastClick == 0) { Vector3 pos = Input.mousePosition; pos.x = (pos.x / GameVO.Instance.PixelWidth - 0.5f) * GameVO.Instance.Width; pos.y = (pos.y / GameVO.Instance.PixelHeight - 0.5f) * GameVO.Instance.Height; Point2D p = HaxgonCoord <Point2D> .PositionToCoord(Point2D.Create(pos.x - offx, pos.y - offy), 0.4f); GridVO grid = EditorVO.Instance.GetGrid((int)p.x, (int)p.y); if (grid != null) { grid.color.value = EditorVO.Instance.color.value; } p = HaxgonCoord <Point2D> .PositionToCoord(Point2D.Create(pos.x - offx1, pos.y - offy1), 0.4f); grid = EditorVO.Instance.GetGrid1((int)p.x, (int)p.y); if (grid != null) { grid.color.value = EditorVO.Instance.color.value; } new CreateLevelCommand(); DrawPieces(); } lastClick = Input.GetAxis("Fire1"); int max = 0; for (int i = 0; i < LevelConfig.Configs.Count; i++) { if (LevelConfig.Configs[i].id > max) { max = LevelConfig.Configs[i].id; } } maxLevelTxt.text = "最大关卡:" + max; }