Exemplo n.º 1
0
    //loads for cloud profiles
    public void LoadCloudProfile(SaveData newLoadData)
    {
        Debug.Log("LoadSaveDataCloud");
        currentScoreData = newLoadData.scoreData;

        for (int i = 0; i < buildings.childCount; i++)
        {
            RatBuildings ratBuilding = buildings.GetChild(i).GetComponent <RatBuildings>();
            if (ratBuilding != null)
            {
                int index = newLoadData.buildingsPurchased.FindIndex(x => x.buildingName == ratBuilding.buildingName);
                ratBuilding.LoadSaveData(newLoadData.buildingsPurchased[index]);
            }
        }
        gameData.total_cheese = newLoadData.currentCheese;
        gameData.username     = newLoadData.username;

        for (int i = buyableUpgrades.childCount - 1; i >= 0; i--)
        {
            Upgrade upgradeInstance = buyableUpgrades.GetChild(i).GetComponent <Upgrade>();

            if (upgradeInstance != null)
            {
                int index = newLoadData.upgradesPurchased.FindIndex(x => x == upgradeInstance.upgradeName);


                if (index != -1)
                {
                    upgradeInstance.PurchaseWithoutCost();
                }
            }
        }
    }
Exemplo n.º 2
0
    //used for guest profile loading
    public bool LoadSaveDataGeneric(string path)
    {
        Debug.Log("LoadSaveDataGeneric");
        if (!File.Exists(path))
        {
            Debug.Log("FILE DOES NOT EXIST.");
            return(false);
        }
        else
        {
            Debug.Log("Reading data.");
            string readText = File.ReadAllText(path);

            SaveData newLoadData = JsonUtility.FromJson <SaveData>(readText);
            currentScoreData = newLoadData.scoreData;

            for (int i = 0; i < buildings.childCount; i++)
            {
                RatBuildings ratBuilding = buildings.GetChild(i).GetComponent <RatBuildings>();
                if (ratBuilding != null)
                {
                    int index = newLoadData.buildingsPurchased.FindIndex(x => x.buildingName == ratBuilding.buildingName);
                    ratBuilding.LoadSaveData(newLoadData.buildingsPurchased[index]);
                }
            }
            gameData.total_cheese = newLoadData.currentCheese;
            gameData.username     = newLoadData.username;

            for (int i = buyableUpgrades.childCount - 1; i >= 0; i--)
            {
                Upgrade upgradeInstance = buyableUpgrades.GetChild(i).GetComponent <Upgrade>();

                if (upgradeInstance != null)
                {
                    int index = newLoadData.upgradesPurchased.FindIndex(x => x == upgradeInstance.upgradeName);


                    if (index != -1)
                    {
                        upgradeInstance.PurchaseWithoutCost();
                    }
                }
            }
        }
        SceneToSceneData.isLoading = false;
        SceneToSceneData.loadPath  = "";
        return(true);
    }
Exemplo n.º 3
0
    //transforms all the current scene data into a saveable format
    SaveData GetSaveData()
    {
        SaveData newSave = new SaveData();

        newSave.scoreData     = currentScoreData;
        newSave.currentCheese = gameData.total_cheese;

        foreach (Transform child in purchasedUpgrades)
        {
            newSave.upgradesPurchased.Add(child.GetComponent <Upgrade>().upgradeName);
        }


        foreach (Transform child in buildings)
        {
            RatBuildings ratBuilding = child.GetComponent <RatBuildings>();
            if (ratBuilding != null)
            {
                newSave.AddBuildingData(ratBuilding.GetBuildingData());
            }
        }
        return(newSave);
    }