private IPlantCell CreateCell(Vector3 center, Vector3 direction) { var geometry = CreateCellGeometry(center, direction); var vacuole = new Vacuole(); var cellWall = new CellWall(); return(cellCreator.CreateCell(PlantCellType.Parenchyma, geometry, vacuole, cellWall)); }
public IPlantCell CreateCell(PlantCellType type, Vector3 center, float radius, float height) { var geometry = CreateCellGeometry(center, radius, height); var vacuole = new Vacuole(); var wall = new CellWall(); return(cellFactory.CreateCell(type, geometry, vacuole, wall)); }
public void PrimMaze() { if (originX >= mapWidth || originY >= mapHeight) { Debug.LogError("初始位置不在迷宫内"); return; } CreateMap(); // 待判断是否需要打通的墙集合 List <CellWall> _walls = new List <CellWall> (); // 初始点 Cell currCell = cells[originX, originY]; currCell.SetVisited(); _walls.AddRange(currCell.GetNeighborWalls()); while (_walls.Count > 0) { // 随机选一面墙 CellWall randomWall = _walls[Random.Range(0, _walls.Count)]; if (randomWall.isBorder || randomWall.isDestroy) { _walls.Remove(randomWall); } List <Cell> neighborCells = randomWall.GetNeighborCells(); bool isAllCellVisited = true; foreach (Cell _cell in neighborCells) { if (!_cell.isVisited) { isAllCellVisited = false; break; } } // 如果这面墙分隔的两个单元格只有一个单元格被访问过 if (!isAllCellVisited) { // 那就从列表里移除这面墙,即把墙打通,让未访问的单元格成为迷宫的通路 randomWall.Destroy(); // 把这个格子的墙加入列表 foreach (Cell _cell in neighborCells) { if (_cell.isVisited) { continue; } _cell.SetVisited(); _walls.AddRange(_cell.GetNeighborWalls()); } // 去重 _walls = _walls.Distinct().ToList(); } // 移除当前墙 _walls.Remove(randomWall); } }
private void CreateWall(BaseCell cell, BaseCell otherCell, CompassDirection direction) { CellWall wall = Instantiate(ip.wallPrefab) as CellWall; wall.Initialize(cell, otherCell, direction); if (otherCell != null) { wall = Instantiate(ip.wallPrefab) as CellWall; wall.Initialize(otherCell, cell, direction.GetOpposite()); } }
public void CreateWallCols(ref CellWall[, ] arr, bool isColl) { for (int i = 0; i < arr.GetLength(0); i++) { for (int j = 0; j < arr.GetLength(1); j++) { bool isBorder; if (isColl) { isBorder = (i == mapWidth || i == 0); } else { isBorder = (j == mapHeight || j == 0); } arr[i, j] = new CellWall(i, j, wallPrefab, wallGroup, isColl, isBorder); } } }
public void Init() { // 获取单个单元格尺寸 Vector3 size = cellPrefab.GetComponent <Renderer> ().bounds.size; // 创建分组 mapGroup = GameObject.Find(mapGroupName); if (mapGroup == null) { mapGroup = new GameObject(mapGroupName); } cellGroup = GameObject.Find(cellsGroupName); if (cellGroup == null) { cellGroup = new GameObject(cellsGroupName); cellGroup.transform.parent = mapGroup.transform; } wallGroup = GameObject.Find(wallsGroupName); if (wallGroup == null) { wallGroup = new GameObject(wallsGroupName); wallGroup.transform.parent = mapGroup.transform; } // 声明cell和wall cells = new Cell[mapWidth, mapHeight]; wallCols = new CellWall[mapWidth + 1, mapHeight]; wallRows = new CellWall[mapWidth, mapHeight + 1]; CreateCells(); CreateWallCols(ref wallCols, true); CreateWallCols(ref wallRows, false); // 给cell建立邻居cell和wall关系 foreach (var item in cells) { item.InitNeighborCells(cells); item.InitNeighborWalls(wallRows, wallCols); } float mapOffsetWidth = (mapWidth - 1) * size.x * 0.5f; float mapOffsetHeight = (mapHeight - 1) * size.z * 0.5f; cellGroup.transform.localPosition = new Vector3(-mapOffsetWidth, 0, -mapOffsetHeight); wallGroup.transform.localPosition = new Vector3(-mapOffsetWidth, 0, -mapOffsetHeight); }
public Neighbors(CellWall north, CellWall east) { North = north; East = east; }