Beispiel #1
0
    public void LoadKingdom()
    {
        if (File.Exists(Application.persistentDataPath + "/kingdom.save"))
        {
            BinaryFormatter bf   = new BinaryFormatter();
            FileStream      file = File.Open(Application.persistentDataPath + "/kingdom.save", FileMode.Open);
            KingdomData     data = (KingdomData)bf.Deserialize(file);
            file.Close();

            name = data.name;
            gold = data.gold;

            elapsedTime = data.elapsedTime;


            //load the inventory lists
            weapons = data.weapons;
            armor   = data.armor;

            //load the heroes
            heroes = data.heroes;

            highestLevelRegionActive = data.highestLevelRegionActive;

            //load the data for each of the buildings
            Building blacksmith = GameObject.Find("Blacksmith").GetComponent <Building>();
            blacksmith.level            = data.blacksmithLevel;
            blacksmith.upgradeCost      = data.bsUpgradeCost;
            blacksmith.levelAsText.text = "Level: " + blacksmith.level;
        }
        else
        {
            Debug.Log("No save found");
        }
    }
Beispiel #2
0
    //TODO look into creating multiple save files
    public void SaveKingdom()
    {
        KingdomData data = CreateKingdomDataObject();

        BinaryFormatter bf   = new BinaryFormatter();
        FileStream      file = File.Create(Application.persistentDataPath + "/kingdom.save");

        bf.Serialize(file, data);
        file.Close();
    }
Beispiel #3
0
    public KingdomData CreateKingdomDataObject()
    {
        //TODO Tailor is not yet saved (am unsure if this building will remain)


        KingdomData data = new KingdomData();

        data.name            = name;
        data.gold            = gold;
        data.blacksmithLevel = blacksmith.level;
        data.bsUpgradeCost   = blacksmith.upgradeCost;


        data.weapons = weapons;
        data.armor   = armor;
        data.heroes  = heroes;

        data.highestLevelRegionActive = highestLevelRegionActive;

        data.elapsedTime = elapsedTime;

        return(data);
    }