Exemple #1
0
    // private List<Edge> allEdges;


    //TODO Remove this when publishing, change to pick a random map (and remove the prebuilt map from the scene in the editor)
    void Awake()
    {
        //GETS MESH WHEN GAME IS RUNNING
        if (Application.isPlaying)
        {
            meshManager = GetComponent <MapMeshManager>();
            meshManager.DestroyAllChildren();
            meshManager.DestroyWallMesh();
            GenerateMap();
        }
    }
    public override void OnInspectorGUI()
    {
        DrawDefaultInspector();

        MapMeshManager mapMesh = target as MapMeshManager;

        if (GUILayout.Button("DestroyMesh"))
        {
            mapMesh.DestroyAllChildren();
            mapMesh.DestroyWallMesh();
            mapMesh.DestroyColliders();
        }
    }
    public override void OnInspectorGUI()
    {
        DrawDefaultInspector();

        MapManager     map     = target as MapManager;
        MapMeshManager mapMesh = map.GetComponent <MapMeshManager> ();

        if (GUILayout.Button("Generate Map"))
        {
            mapMesh.DestroyAllChildren();
            mapMesh.DestroyWallMesh();
            map.GenerateMap();
        }
    }
Exemple #4
0
    //All other methods called from here
    public void GenerateMap()
    {
        //INITIALISATION
        if (meshManager == null)
        {
            //GETS MESH IF GAME NOT RUNNING (i.e. Awake() wasn't called)
            meshManager = GetComponent <MapMeshManager>();
        }
        mapData  = new int[gridWidth, gridHeight];
        mapFlags = new int[gridWidth, gridHeight];
        rooms    = new List <Room>();


        //GENERATE RANDOM PARAMETERS FOR SIDE ROOMS
        leftRoomHeight    = UnityEngine.Random.Range(0, 4) * ((int)UnityEngine.Random.Range(0, 2) * 2 - 1);
        rightRoomHeight   = UnityEngine.Random.Range(0, 4) * ((int)UnityEngine.Random.Range(0, 2) * 2 - 1);
        leftRoomDistance  = UnityEngine.Random.Range(2, 6);
        rightRoomDistance = UnityEngine.Random.Range(2, 6);

        //GENERATION

        //Random 0s (space) and 1s (walls) set according to fill percent
        GenerateNoise();

        //Noise transformed to areas of similar type and made not to be jagged
        Smooth(smoothIterations);

        //Central rooms set in map data, also added to rooms list and map flags set to 1
        GenerateMainRoom(true);

        /*Areas smaller than thresholds removed (i.e. tiny rooms and small floating walls),
         * then regions that are spaces are added to a list (minus the very central rooms,
         * then connected until every room is connected to one of the side rooms */
        ProcessRegions();

        //Smooths again incase passages are not smooth
        Smooth(smoothIterations);

        //Side central rooms connected to middle
        CreatePassage(rooms[0], rooms[1], centre, leftCentre, -1);
        CreatePassage(rooms[0], rooms[2], centre, rightCentre, -1);

        /*
         * //GETTING EDGES
         * mapFlags = new int[gridWidth, gridHeight];
         * allEdges = new List<Edge>();
         * finalRoom = new Room(GetRegions(0)[0], mapData, false, false);
         * foreach (Coord edge in finalRoom.edgeTiles) {
         *  allEdges.Add(new Edge(edge.tileX, edge.tileY));
         * }
         */

        //ADDS BORDERS
        int[,] borderedMapData = new int[gridWidth + borderSize * 2, gridHeight + borderSize * 2];
        for (int x = 0; x < borderedMapData.GetLength(0); x++)
        {
            for (int y = 0; y < borderedMapData.GetLength(1); y++)
            {
                if (x >= borderSize && x < gridWidth + borderSize && y >= borderSize && y < gridHeight + borderSize)
                {
                    borderedMapData[x, y] = mapData[x - borderSize, y - borderSize];
                }
                else
                {
                    borderedMapData[x, y] = 1;
                }
            }
        }

        //GENERATES MESH
        meshManager.GenerateMesh(borderedMapData, gridSize, gridWidth, gridHeight);
    }