コード例 #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();
                }
            }
        }
    }
コード例 #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);
    }