예제 #1
0
    public GameObject CreateMap(MapSettings settings, MeshSettings meshSettings, Transform parent = null)
    {
        GameObject map = new GameObject("Tile Map");

        //GameObject gameObject = GameObject.CreatePrimitive(PrimitiveType.Plane);
        //Mesh mesh = gameObject.GetComponent<MeshFilter>().sharedMesh;
        //GameObject.Destroy(gameObject);

        MeshFilter filter = map.AddComponent <MeshFilter>();

        //filter.sharedMesh = mesh;
        filter.sharedMesh = DiscreteMeshGenerator.GenerateGridMesh(settings, meshSettings);

        Renderer renderer = map.AddComponent <MeshRenderer>();

        renderer.sharedMaterial = new Material(Shader.Find("Unlit/Texture"))
        {
            mainTexture = GenerateMapTexture(settings)
        };
        //renderer.transform.localScale = new Vector3(settings.width, 1.0f, settings.height) / settings.cellScale;

        return(map);
    }
예제 #2
0
    public void DrawMapInEditor()
    {
        if (tileMapSettings.createOuterWalls)
        {
            if (tileMapSettings.isVoxelMap)
            {
                ///
                /// Room Adder
                //DrawMesh(DiscreteVoxelMeshGenerator.GenerateGridMesh(OuterWallsGenerator.CreateOuterWalls(MazeGenerator.ConvertToEmptyGrid(Sidewinder.CreateMaze(RandomRoomPlacementMazeAdder.AddRoomsToMaze(MazeGenerator.GenerateMazeGrid(mazeSettings), roomAdder), sidewinder))), tileMapSettings));
                //DrawMesh(DiscreteVoxelMeshGenerator.GenerateGridMesh(OuterWallsGenerator.CreateOuterWalls(MazeGenerator.ConvertToEmptyGrid(MazeGenerator.GenerateMazeGrid(mazeSettings))), tileMapSettings));
                ///
                /// Fractal
                //DrawMesh(DiscreteVoxelMeshGenerator.GenerateGridMesh(OuterWallsGenerator.CreateOuterWalls(MazeGenerator.ConvertToEmptyGrid(RecursiveDivision.CreateMaze(MazeGenerator.GenerateMazeGrid(mazeSettings)))), tileMapSettings));
                ///
                /// Eller
                //DrawMesh(DiscreteVoxelMeshGenerator.GenerateGridMesh(OuterWallsGenerator.CreateOuterWalls(MazeGenerator.ConvertToEmptyGrid(Eller.CreateMaze(MazeGenerator.GenerateMazeGrid(mazeSettings)))), tileMapSettings));
                ///
                /// Growing Tree
                //DrawMesh(DiscreteVoxelMeshGenerator.GenerateGridMesh(OuterWallsGenerator.CreateOuterWalls(MazeGenerator.ConvertToEmptyGrid(GrowingTree.CreateMaze(MazeGenerator.GenerateMazeGrid(mazeSettings)))), tileMapSettings));
                //DrawMesh(DiscreteVoxelMeshGenerator.GenerateGridMesh(OuterWallsGenerator.CreateOuterWalls(MazeGenerator.ConvertToEmptyGrid(GrowingTree.CreateMaze(MazeGenerator.GenerateMazeGrid(mazeSettings), null, x => x[x.Count-1]))), tileMapSettings));
                //DrawMesh(DiscreteVoxelMeshGenerator.GenerateGridMesh(OuterWallsGenerator.CreateOuterWalls(MazeGenerator.ConvertToEmptyGrid(GrowingTree.CreateMaze(MazeGenerator.GenerateMazeGrid(mazeSettings), null, x => Random.value < 0.5f ? x[x.Count-1] : x[Random.Range(0, x.Count)]))), tileMapSettings));
                ///
                /// Prim Weighted Cells
                //DrawMesh(DiscreteVoxelMeshGenerator.GenerateGridMesh(OuterWallsGenerator.CreateOuterWalls(MazeGenerator.ConvertToEmptyGrid(PrimWeightedCells.CreateMaze(MazeGenerator.GenerateMazeGrid(mazeSettings)))), tileMapSettings));
                ///
                /// Prim Same Weight
                //DrawMesh(DiscreteVoxelMeshGenerator.GenerateGridMesh(OuterWallsGenerator.CreateOuterWalls(MazeGenerator.ConvertToEmptyGrid(PrimSameWeight.CreateMaze(MazeGenerator.GenerateMazeGrid(mazeSettings)))), tileMapSettings));
                ///
                /// Kruskal
                //DrawMesh(DiscreteVoxelMeshGenerator.GenerateGridMesh(OuterWallsGenerator.CreateOuterWalls(MazeGenerator.ConvertToEmptyGrid(RandomizedKruskal.CreateMaze(MazeGenerator.GenerateMazeGrid(mazeSettings)))), tileMapSettings));
                ///
                /// Recursive Backtracker
                //DrawMesh(DiscreteVoxelMeshGenerator.GenerateGridMesh(OuterWallsGenerator.CreateOuterWalls(MazeGenerator.ConvertToEmptyGrid(RecursiveBacktracker.CreateMaze(MazeGenerator.GenerateMazeGrid(mazeSettings)))), tileMapSettings));
                ///
                /// Hunt and Kill
                //DrawMesh(DiscreteVoxelMeshGenerator.GenerateGridMesh(OuterWallsGenerator.CreateOuterWalls(MazeGenerator.ConvertToEmptyGrid(HuntAndKill.CreateMaze(MazeGenerator.GenerateMazeGrid(mazeSettings)))), tileMapSettings));
                ///
                /// Wilson
                //DrawMesh(DiscreteVoxelMeshGenerator.GenerateGridMesh(OuterWallsGenerator.CreateOuterWalls(MazeGenerator.ConvertToEmptyGrid(Wilson.CreateMaze(MazeGenerator.GenerateMazeGrid(mazeSettings)))), tileMapSettings));
                ///
                /// Aldous-Broder
                //DrawMesh(DiscreteVoxelMeshGenerator.GenerateGridMesh(OuterWallsGenerator.CreateOuterWalls(MazeGenerator.ConvertToEmptyGrid(AldousBroder.CreateMaze(MazeGenerator.GenerateMazeGrid(mazeSettings)))), tileMapSettings));
                ///
                /// Sidewinder
                //DrawMesh(DiscreteVoxelMeshGenerator.GenerateGridMesh(OuterWallsGenerator.CreateOuterWalls(MazeGenerator.ConvertToEmptyGrid(Sidewinder.CreateMaze(MazeGenerator.GenerateMazeGrid(mazeSettings), sidewinder))), tileMapSettings));
                ///
                /// Binary Tree
                //DrawMesh(DiscreteVoxelMeshGenerator.GenerateGridMesh(OuterWallsGenerator.CreateOuterWalls(MazeGenerator.ConvertToEmptyGrid(BinaryTree.CreateMaze(MazeGenerator.GenerateMazeGrid(mazeSettings), btree))), tileMapSettings));
                /// With Distances
                //DistanceMazeGrid mazeGrid = (DistanceMazeGrid)BinaryTree.CreateMaze(MazeGenerator.GenerateMazeGrid(mazeSettings), btree);
                //DrawMesh(DiscreteVoxelMeshGenerator.GenerateGridMesh(OuterWallsGenerator.CreateOuterWalls(MazeGenerator.ConvertToEmptyGrid(BinaryTree.CreateMaze(MazeGenerator.GenerateMazeGrid(mazeSettings), btree))), tileMapSettings));
                //mazeGrid.distances = mazeGrid.values[0, 0].FindDistanceForAllReachableLinkedCells();
                //Debug.Log(mazeGrid.ToString());
                ///
                /// MAZES
                /// ///
                ///
                /// Settling
                //SettlingRooms.PreprocessMap(tileMapSettings, settling);
                //DrawMesh(DiscreteVoxelMeshGenerator.GenerateGridMesh(OuterWallsGenerator.CreateOuterWalls(SettlingRooms.ProcessMap(GridGenerator.GenerateEmptyGrid(tileMapSettings), settling)), tileMapSettings));
                ///
                /// From prefab
                //GridMapFromPrefabs.PreprocessMap(tileMapSettings, mapFromPrefab);
                //DrawMesh(DiscreteVoxelMeshGenerator.GenerateGridMesh(OuterWallsGenerator.CreateOuterWalls(GridMapFromPrefabs.ProcessMap(GridGenerator.GenerateEmptyGrid(tileMapSettings), mapFromPrefab)), tileMapSettings));
                ///
                /// Corridor
                //RandomRoomWithCorridor.PreprocessMap(tileMapSettings, corridor);
                //DrawMesh(DiscreteVoxelMeshGenerator.GenerateGridMesh(OuterWallsGenerator.CreateOuterWalls(RandomRoomWithCorridor.ProcessMap(GridGenerator.GenerateEmptyGrid(tileMapSettings), corridor)), tileMapSettings));
                ///
                /// BSP
                //BinarySpacePartitioning.PreprocessMap(tileMapSettings, bsp);
                //DrawMesh(DiscreteVoxelMeshGenerator.GenerateGridMesh(OuterWallsGenerator.CreateOuterWalls(BinarySpacePartitioning.ProcessMap(GridGenerator.GenerateEmptyGrid(tileMapSettings), bsp)), tileMapSettings));
                ///
                /// Random Room Placement
                //RandomRoomPlacement.PreprocessMap(tileMapSettings, roomPlacement);
                //DrawMesh(DiscreteVoxelMeshGenerator.GenerateGridMesh(OuterWallsGenerator.CreateOuterWalls(RandomRoomPlacement.ProcessMap(GridGenerator.GenerateEmptyGrid(tileMapSettings), roomPlacement)), tileMapSettings));
                ///
                /// Diffusion Limited Aggregation
                //DiffusionLimitedAggregation.PreprocessMap(tileMapSettings, difLimAgr);
                //DrawMesh(DiscreteVoxelMeshGenerator.GenerateGridMesh(OuterWallsGenerator.CreateOuterWalls(DiffusionLimitedAggregation.ProcessMap(GridGenerator.GenerateEmptyGrid(tileMapSettings), difLimAgr)), tileMapSettings));
                ///
                /// Random Worms
                //RandomWorms.PreprocessMap(tileMapSettings, randomWorms);
                //DrawMesh(DiscreteVoxelMeshGenerator.GenerateGridMesh(OuterWallsGenerator.CreateOuterWalls(RandomWorms.ProcessMap(GridGenerator.GenerateEmptyGrid(tileMapSettings), randomWorms)), tileMapSettings));
                ///
                /// Random Walkers
                //DrawMesh(DiscreteVoxelMeshGenerator.GenerateGridMesh(OuterWallsGenerator.CreateOuterWalls(RandomWalkers.ProcessMap(GridGenerator.GenerateEmptyGrid(tileMapSettings), randomWalkers)), tileMapSettings));
                ///
                /// GameOfLife
                //DrawMesh(DiscreteVoxelMeshGenerator.GenerateGridMesh(OuterWallsGenerator.CreateOuterWalls(GameOfLifeCave.ProcessMap(GridGenerator.GenerateEmptyGrid(tileMapSettings), gameOfLife)), tileMapSettings));
                ///
                /// RandomRoomGrid
                //RandomRoomSizeGrid.PreprocessMap(tileMapSettings, randomRoomGrid);
                //DrawMesh(DiscreteVoxelMeshGenerator.GenerateGridMesh(OuterWallsGenerator.CreateOuterWalls(RandomRoomSizeGrid.ProcessMap(GridGenerator.GenerateEmptyGrid(tileMapSettings), randomRoomGrid)), tileMapSettings));
                ///
                /// RoomGrid
                //FixedRoomSizeGrid.PreprocessMap(tileMapSettings, roomGrid);
                //DrawMesh(DiscreteVoxelMeshGenerator.GenerateGridMesh(OuterWallsGenerator.CreateOuterWalls(FixedRoomSizeGrid.ProcessMap(GridGenerator.GenerateEmptyGrid(tileMapSettings), roomGrid)), tileMapSettings));
                /// RoomGrid + GameOfLife
                //DrawMesh(DiscreteVoxelMeshGenerator.GenerateGridMesh(OuterWallsGenerator.CreateOuterWalls(FixedRoomSizeGrid.ProcessMap(GridGenerator.GenerateEmptyGrid(tileMapSettings), roomGrid, gameOfLife)), tileMapSettings));
                ///
                ///FisherYates
                //DrawMesh(DiscreteVoxelMeshGenerator.GenerateGridMesh(OuterWallsGenerator.CreateOuterWalls(FisherYatesShuffle.ProcessMap(GridGenerator.GenerateEmptyGrid(tileMapSettings), fisherYates)), tileMapSettings));
                ///
                /// Without Processing
                //DrawMesh(DiscreteVoxelMeshGenerator.GenerateGridMesh(OuterWallsGenerator.CreateOuterWalls(GridGenerator.GenerateEmptyGrid(tileMapSettings)), tileMapSettings));

                /// PointyHex test
                //DrawMesh(DiscretePointyHexMeshGenerator.GenerateGridMesh(OuterWallsGenerator.CreateOuterWalls(GridGenerator.GenerateEmptyGrid(tileMapSettings)), tileMapSettings));
                //DrawMesh(ContiguousPointyHexMeshGenerator.GenerateGridMesh(OuterWallsGenerator.CreateOuterWalls(GridGenerator.GenerateEmptyGrid(tileMapSettings)), tileMapSettings));

                //DrawMesh(DiscreteSolidPointyHexMeshGenerator.GenerateGridMesh(OuterWallsGenerator.CreateOuterWalls(GridGenerator.GenerateEmptyGrid(tileMapSettings)), tileMapSettings));
                //DrawMesh(DiscreteSolidPointyHexMeshGenerator.GenerateGridMesh(OuterWallsGenerator.CreateOuterWalls(FisherYatesShuffle.ProcessMap(GridGenerator.GenerateEmptyGrid(tileMapSettings), fisherYates)), tileMapSettings));
                //DrawMesh(DiscreteSolidPointyHexMeshGenerator.GenerateGridMesh(OuterWallsGenerator.CreateOuterWalls(GameOfLifeCave.ProcessMap(GridGenerator.GenerateEmptyGrid(tileMapSettings), gameOfLife)), tileMapSettings));

                /// Height maps
                //DrawMesh(DiscreteSolidPointyHexMeshGenerator.GenerateTerrainMesh(GridGenerator.GenerateEmptyGrid(tileMapSettings).FillWholeGrid(CellType.Wall), tileMapSettings, HeightMapGenerator.GenerateHeightMap(heightMapSettings, new Vector2(0.0f, 0.0f), tileMapSettings.mapWidth, tileMapSettings.mapHeight)));
                //DrawMesh(DiscreteVoxelMeshGenerator.GenerateTerrainMesh(GridGenerator.GenerateEmptyGrid(tileMapSettings), tileMapSettings, HeightMapGenerator.GenerateHeightMap(heightMapSettings, new Vector2(0.0f, 0.0f), tileMapSettings.mapWidth, tileMapSettings.mapHeight)));

                /// Layers Height
                //DrawMesh(DiscreteSolidPointyHexMeshGenerator.GenerateTerrainMesh(GridGenerator.GenerateEmptyGrid(tileMapSettings), tileMapSettings, HeightMapGenerator.GenerateHeightMap(heightMapSettings, new Vector2(0.0f, 0.0f), tileMapSettings.mapWidth, tileMapSettings.mapHeight), heightLayersSettings));
                //DrawMesh(DiscreteVoxelMeshGenerator.GenerateTerrainMesh(GridGenerator.GenerateEmptyGrid(tileMapSettings), tileMapSettings, HeightMapGenerator.GenerateHeightMap(heightMapSettings, new Vector2(0.0f, 0.0f), tileMapSettings.mapWidth, tileMapSettings.mapHeight), heightLayersSettings));

                //DrawMesh(DiscreteTerrainGenerator.GenerateDiscreteTerrainMesh(discreteTerrainSettings));

                //DrawMesh(ContiguousTerrainGenerator.GenerateContiguousTerrainMesh(contiguousTerrainSettings));

                HeightMap heightMap = ContiguousTerrainGenerator.GenerateContiguousTerrainHeightMap(contiguousTerrainSettings);
                textureData.ApplyToMaterial(terrainMaterial);
                textureData.UpdateMeshHeight(terrainMaterial, heightMap.minValue, heightMap.maxValue);
                DrawMesh(ContiguousTerrainGenerator.GenerateContiguousTerrainFromHM(heightMap, contiguousTerrainSettings));

                ///
                ///IO Tests
                ///
                /// Texture2D
                //ExportMap.ExportGraphic(OuterWallsGenerator.CreateOuterWalls(FixedRoomSizeGrid.ProcessMap(GridGenerator.GenerateEmptyGrid(tileMapSettings), roomGrid)));
                //DrawMesh(DiscreteVoxelMeshGenerator.GenerateGridMesh(ExportMap.ImportGraphic("f", "u", "c"), tileMapSettings));
                /// TXT
                //ExportMap.ExportText(OuterWallsGenerator.CreateOuterWalls(FixedRoomSizeGrid.ProcessMap(GridGenerator.GenerateEmptyGrid(tileMapSettings), roomGrid)));
                //DrawMesh(DiscreteVoxelMeshGenerator.GenerateGridMesh(ExportMap.ImportText("f", "u", "c"), tileMapSettings));
                /// Binary
                /// BUG: FAILED TO WRITE\READ ARRAY => Need to make custom loader
                //ExportMap.SaveDataBinary(OuterWallsGenerator.CreateOuterWalls(FixedRoomSizeGrid.ProcessMap(GridGenerator.GenerateEmptyGrid(tileMapSettings), roomGrid)));
                //DrawMesh(DiscreteVoxelMeshGenerator.GenerateGridMesh(ExportMap.LoadDataBinary(), tileMapSettings));
                /// JSON
                //ExportMap.ExportJSON(OuterWallsGenerator.CreateOuterWalls(FixedRoomSizeGrid.ProcessMap(GridGenerator.GenerateEmptyGrid(tileMapSettings), roomGrid)));
                //DrawMesh(DiscreteVoxelMeshGenerator.GenerateGridMesh(ExportMap.ImportJSON("f","u","c"), tileMapSettings));
            }
            else
            {
                if (tileMapSettings.isDiscrete)
                {
                    DrawMesh(DiscreteMeshGenerator.GenerateGridMesh(OuterWallsGenerator.CreateOuterWalls(GridGenerator.GenerateEmptyGrid(tileMapSettings)), tileMapSettings));
                }
                else
                {
                    DrawMesh(ContiguousMeshGenerator.GenerateGridMesh(OuterWallsGenerator.CreateOuterWalls(GridGenerator.GenerateEmptyGrid(tileMapSettings)), tileMapSettings));
                }
            }
        }
        else
        {
            if (tileMapSettings.isVoxelMap)
            {
                ///RoomGrid
                FixedRoomSizeGrid.PreprocessMap(tileMapSettings, roomGrid);
                DrawMesh(DiscreteVoxelMeshGenerator.GenerateGridMesh(FixedRoomSizeGrid.ProcessMap(GridGenerator.GenerateEmptyGrid(tileMapSettings), roomGrid), tileMapSettings));
                ///FisherYates
                //DrawMesh(DiscreteVoxelMeshGenerator.GenerateGridMesh(FisherYatesShuffle.ProcessMap(GridGenerator.GenerateEmptyGrid(tileMapSettings), fisherYates), tileMapSettings));
                ///Without Processing
                //DrawMesh(DiscreteVoxelMeshGenerator.GenerateGridMesh(GridGenerator.GenerateEmptyGrid(tileMapSettings), tileMapSettings));
            }
            else
            {
                if (tileMapSettings.isDiscrete)
                {
                    DrawMesh(DiscreteMeshGenerator.GenerateGridMesh(GridGenerator.GenerateEmptyGrid(tileMapSettings), tileMapSettings));
                }
                else
                {
                    DrawMesh(ContiguousMeshGenerator.GenerateGridMesh(GridGenerator.GenerateEmptyGrid(tileMapSettings), tileMapSettings));
                }
            }
        }
    }