Пример #1
0
    /// <summary>
    /// Clears a previous dungeon and removes all tiles and objects.
    /// </summary>
    /// <returns></returns>
    public IEnumerator ClearPreviousDungeon()
    {
        timer = new DungeonTimer(false);
        timer.Start();

        yield return(DestroyPreviousGameObjects());

        yield return(ClearPreviousTiles());

        dungeon = DungeonDict.Instance.dungeon = null;
    }
Пример #2
0
    /// <summary>
    /// Creates the dungeon in an async way.
    /// </summary>
    /// <param name="seed">The random seed for the dungeon.</param>
    /// <param name="levelNumber">The current level number.</param>
    /// <param name="config">The config to load and use during generation.</param>
    /// <param name="tileset">The tileset to use for the tilemap generation.</param>
    public IEnumerator CreateDungeon(int seed, int levelNumber, DungeonConfig config, Tileset tileset, Dungeon dungeonToLoad = null)
    {
        timer = new DungeonTimer();
        timer.Start();

        yield return(DestroyPreviousGameObjects());

        dungeon = dungeonToLoad;
        if (dungeon == null)
        {
            Debug.Log("Creating dungeon with seed: " + seed);
            // Load all room types
            List <Fast2DArray <int> > roomLayouts = new List <Fast2DArray <int> >();
            List <List <TiledImporter.PrefabLocations> > roomGameObjects = new List <List <TiledImporter.PrefabLocations> >();
            List <RoomType> roomTypes = new List <RoomType>();
            yield return(LoadRoomTypes(roomLayouts, roomGameObjects, roomTypes));

            //seed = -1304249244;
            seed    = "I wanna go home".GetHashCode();
            dungeon = new Dungeon(roomLayouts.ToArray(), roomGameObjects.ToArray(), roomTypes.ToArray(), seed, config);
        }
        DungeonDict.Instance.dungeon = dungeon;

        AdjustMask();

        yield return(ClearPreviousTiles());

        yield return(SetTiles(tileset));

        yield return(SetBorderTiles(tileset));

        yield return(roomCreator.CreateRooms(dungeon, levelNumber, config, timer));

        MiniMapManager.Instance.OnNewLevelGenerated();

        SetLoadStatus(1.0f);

        position = transform.position;

        if (Player.LocalPlayer) // check to allow for debugging if a localplayer is not scene
        {
            Player.LocalPlayer.StateCommunicator.LevelSetLoaded(true);
        }
    }