예제 #1
0
    private IEnumerator LoadSave()
    {
        //Debug.Log("Seed:" + PlayerPrefs.GetInt("Seed"));

        myWorldGeneration.myUseSeed = true;
        GameInstance.GetInstance().SetSeed(PlayerPrefs.GetInt("Seed"));

        myWorldGeneration.GenerateWorld();

        //Debug.Log("PlayerRoomX:" + PlayerPrefs.GetInt("PlayerRoomX"));
        //Debug.Log("PlayerRoomY:" + PlayerPrefs.GetInt("PlayerRoomY"));
        //Debug.Log("PlayerBiomeX:" + PlayerPrefs.GetInt("PlayerBiomeX"));
        //Debug.Log("PlayerBiomeY:" + PlayerPrefs.GetInt("PlayerBiomeY"));

        while (!myWorldGeneration.myGenerationFinished)
        {
            yield return(null);
        }

        myWorldGeneration.ActivateBiome(PlayerPrefs.GetInt("PlayerBiomeX"), PlayerPrefs.GetInt("PlayerBiomeY"));
        Room theRoom = myWorldGeneration.ActivateRoom(PlayerPrefs.GetInt("PlayerRoomX"), PlayerPrefs.GetInt("PlayerRoomY"));

        myWorldGeneration.PlacePlayerInRoom(theRoom);

        myWorldGeneration.PlacePlayerAt(PlayerPrefs.GetFloat("PlayerX"), PlayerPrefs.GetFloat("PlayerY"));

        MapUI mapUI = FindObjectOfType <MapUI>();

        int roomVisited = PlayerPrefs.GetInt("RoomsVisited");

        for (int i = 0; i < roomVisited; ++i)
        {
            Biome biome = myWorldGeneration.GetBiome(PlayerPrefs.GetInt("Visited" + i + "BiomeX"), PlayerPrefs.GetInt("Visited" + i + "BiomeY"));

            mapUI.SetRoomVisited(PlayerPrefs.GetInt("Visited" + i + "RoomX"), PlayerPrefs.GetInt("Visited" + i + "RoomY"), biome);
        }

        myWorldGeneration.GetPlayerMovement().GetComponent <PlayerData>().SetSoulsCollected(PlayerPrefs.GetInt("PlayerSouls"));

        /*
         * PlayerPrefs.SetInt("ResourceNum", resourceToSave.Count);
         *
         * for (int i = 0; i < resourceToSave.Count; ++i)
         * {
         *  PlayerPrefs.SetInt("Resource" + i + "Life", resourceToSave[i].GetCurrentLife());
         *  PlayerPrefs.SetFloat("Resource" + i + "Time", resourceToSave[i].GetCurrentTimeToRefill());
         *  PlayerPrefs.SetInt("Resource" + i + "X", resourceToSave[i].GetTile().myTileData.myX);
         *  PlayerPrefs.SetInt("Resource" + i + "Y", resourceToSave[i].GetTile().myTileData.myY);
         *  PlayerPrefs.SetInt("Resource" + i + "BiomeX", resourceToSave[i].GetTile().myParentRoom.GetBiome().myX);
         *  PlayerPrefs.SetInt("Resource" + i + "BiomeY", resourceToSave[i].GetTile().myParentRoom.GetBiome().myY);
         * }
         */
    }
예제 #2
0
    public void SaveWorld()
    {
        PlayerPrefs.SetInt("Seed", myWorldGeneration.GetSeed());

        Biome[] biomes = myWorldGeneration.GetBiomes();

        List <ResourceUsable> resourceToSave = new List <ResourceUsable>();

        for (int i = 0; i < biomes.Length; ++i)
        {
            List <ResourceUsable> newResouces = biomes[i].GetResourceUsablesToSave();
            for (int j = 0; j < newResouces.Count; ++j)
            {
                resourceToSave.Add(newResouces[j]);
            }
        }

        PlayerPrefs.SetInt("PlayerRoomX", myWorldGeneration.GetPlayerMovement().GetCurrentRoom().myRoomData.myX);
        PlayerPrefs.SetInt("PlayerRoomY", myWorldGeneration.GetPlayerMovement().GetCurrentRoom().myRoomData.myY);
        PlayerPrefs.SetInt("PlayerBiomeX", myWorldGeneration.GetPlayerMovement().GetCurrentRoom().GetBiome().myX);
        PlayerPrefs.SetInt("PlayerBiomeY", myWorldGeneration.GetPlayerMovement().GetCurrentRoom().GetBiome().myY);
        PlayerPrefs.SetFloat("PlayerX", myWorldGeneration.GetPlayerMovement().transform.position.x);
        PlayerPrefs.SetFloat("PlayerY", myWorldGeneration.GetPlayerMovement().transform.position.y);
        PlayerPrefs.SetInt("PlayerSouls", myWorldGeneration.GetPlayerMovement().GetComponent <PlayerData>().GetSoulsCollected());

        PlayerPrefs.SetInt("ResourceNum", resourceToSave.Count);

        for (int i = 0; i < resourceToSave.Count; ++i)
        {
            PlayerPrefs.SetInt("Resource" + i + "Life", resourceToSave[i].GetCurrentLife());
            PlayerPrefs.SetFloat("Resource" + i + "Time", resourceToSave[i].GetCurrentTimeToRefill());
            PlayerPrefs.SetInt("Resource" + i + "X", resourceToSave[i].GetTile().myTileData.myX);
            PlayerPrefs.SetInt("Resource" + i + "Y", resourceToSave[i].GetTile().myTileData.myY);
            PlayerPrefs.SetInt("Resource" + i + "BiomeX", resourceToSave[i].GetTile().myParentRoom.GetBiome().myX);
            PlayerPrefs.SetInt("Resource" + i + "BiomeY", resourceToSave[i].GetTile().myParentRoom.GetBiome().myY);
        }

        MapUI mapUI = FindObjectOfType <MapUI>();

        List <Room> rooms = mapUI.GetVisitedRooms();

        PlayerPrefs.SetInt("RoomsVisited", rooms.Count);

        for (int i = 0; i < rooms.Count; ++i)
        {
            PlayerPrefs.SetInt("Visited" + i + "BiomeX", rooms[i].GetBiome().myX);
            PlayerPrefs.SetInt("Visited" + i + "BiomeY", rooms[i].GetBiome().myY);
            PlayerPrefs.SetInt("Visited" + i + "RoomX", rooms[i].myRoomData.myX);
            PlayerPrefs.SetInt("Visited" + i + "RoomY", rooms[i].myRoomData.myY);
        }

        PlayerPrefs.Save();
    }