Пример #1
0
        public void RefreshMaze()
        {
            //Preprocess
            var generator = new EllerGenerator();

            _Maze      = generator.Generate(_MazeCellsX, _MazeCellsY);
            _GraphMaze = new MazeGraph(_Maze, true);
            //Process
            var mazeGO = GenerateW4MazeMesh(
                _Maze,
                _Height,
                _WallThikness,
                _Material);
            //PostProcess
            var lightsGO = _LightPlacer.SetUpLights(_Maze, _Height);

            lightsGO.transform.SetParent(mazeGO.transform);
        }
Пример #2
0
        public GameObject GenerateW4MazeMesh(
            W4Maze maze,
            float mazeHeight,
            float wallThikness,
            Material material)
        {
            var mazeGO    = new GameObject();
            var mazeWidth = maze.ColumnCount;
            var mazeDepth = maze.RowCount;
            var floor     = CreateFloor(
                mazeWidth,
                mazeDepth,
                material);
            var wallsGO = CreateWalls(
                new MazeGraph(maze, true),
                mazeHeight,
                wallThikness,
                Mathf.Max(mazeDepth, mazeWidth),
                material);

            floor.transform.position += new Vector3(
                mazeWidth / 2f,
                0,
                mazeDepth / 2f);
            if (_IsGenerateRoof)
            {
                var roof = Instantiate(floor);
                roof.transform.position += Vector3.up * mazeHeight;
                roof.transform.up        = -Vector3.up;
#if UNITY_EDITOR
                roof.transform.SetParent(mazeGO.transform);
                roof.name = "roof" + mazeWidth.ToString() + "x"
                            + mazeDepth.ToString();
#endif
            }
#if UNITY_EDITOR
            floor.transform.SetParent(mazeGO.transform);
            wallsGO.transform.SetParent(mazeGO.transform);
            mazeGO.name  = "Maze";
            wallsGO.name = "Walls";
#endif
            return(mazeGO);
        }
Пример #3
0
        public MazeGraph(W4Maze maze, bool isSimplify)
        {
            _Cells     = new List <MazeGraphCell>(maze.RowCount * maze.ColumnCount);
            _PathEdges = new List <Edge>();
            _WallEdges = new List <Edge>();
            for (int i = 0; i < _Cells.Capacity; i++)
            {
                _Cells.Add(new MazeGraphCell());
            }
            for (int j = 0; j < maze.RowCount; j++)
            {
                for (int i = 0; i < maze.ColumnCount; i++)
                {
                    var cell  = maze.GetCell(i, j);
                    int index = i + j * maze.ColumnCount;

                    MazeGraphCellFromW4Cell(
                        _Cells[index],
                        cell,
                        i,
                        j,
                        maze.ColumnCount
                        );

                    _Cells[index].Position = new Vector2(
                        i + 0.5f,
                        j + 0.5f);
                    _Cells[index].CanBeSimplifiied
                        = (!cell.BotWall && !cell.TopWall &&
                           cell.RightWall && cell.LeftWall) ||
                          (cell.BotWall && cell.TopWall &&
                           !cell.RightWall && !cell.LeftWall);

                    if (cell.BotWall)
                    {
                        var edge = new Edge();
                        edge.Begin = new Vector2(
                            _Cells[index].Position.x - 0.5f,
                            _Cells[index].Position.y - 0.5f);
                        edge.End = new Vector2(
                            _Cells[index].Position.x + 0.5f,
                            _Cells[index].Position.y - 0.5f);
                        if (_WallEdges.TrueForAll(x => x != edge))
                        {
                            _WallEdges.Add(edge);
                        }
                    }
                    if (cell.TopWall)
                    {
                        var edge = new Edge();
                        edge.Begin = new Vector2(
                            _Cells[index].Position.x - 0.5f,
                            _Cells[index].Position.y + 0.5f);
                        edge.End = new Vector2(
                            _Cells[index].Position.x + 0.5f,
                            _Cells[index].Position.y + 0.5f);
                        if (_WallEdges.TrueForAll(x => x != edge))
                        {
                            _WallEdges.Add(edge);
                        }
                    }
                    if (cell.LeftWall)
                    {
                        var edge = new Edge();
                        edge.Begin = new Vector2(
                            _Cells[index].Position.x - 0.5f,
                            _Cells[index].Position.y - 0.5f);
                        edge.End = new Vector2(
                            _Cells[index].Position.x - 0.5f,
                            _Cells[index].Position.y + 0.5f);
                        if (_WallEdges.TrueForAll(x => x != edge))
                        {
                            _WallEdges.Add(edge);
                        }
                    }
                    if (cell.RightWall)
                    {
                        var edge = new Edge();
                        edge.Begin = new Vector2(
                            _Cells[index].Position.x + 0.5f,
                            _Cells[index].Position.y + 0.5f);
                        edge.End = new Vector2(
                            _Cells[index].Position.x + 0.5f,
                            _Cells[index].Position.y - 0.5f);
                        if (_WallEdges.TrueForAll(x => x != edge))
                        {
                            _WallEdges.Add(edge);
                        }
                    }
                }
            }
            if (isSimplify)
            {
                for (int i = 0; i < _Cells.Count; i++)
                {
                    if (_Cells[i].CanBeSimplifiied)
                    {
                        SimplifyCell(_Cells[i]);
                        i--;
                    }
                }
            }
            CalculatePathEdges();
            ProcessWallEdges();
        }
Пример #4
0
 public MazeCoords(W4Maze maze)
 {
     for (int i = 0; i < maze.ColumnCount; i++)
     {
     }
 }