public void Load() { Scene scene = SceneManager.GetActiveScene(); foreach (GameObject item in _Objects) { //Chargement et affectation des couleurs et textures sauvegardés float _r = EncryptedPlayerPrefs.GetFloat(item.name + "R", -1f); float _g = EncryptedPlayerPrefs.GetFloat(item.name + "G", -1f); float _b = EncryptedPlayerPrefs.GetFloat(item.name + "B", -1f); float _a = EncryptedPlayerPrefs.GetFloat(item.name + "A", -1f); if (_r != -1) { Color _color = new Color(_r, _g, _b, _a); item.gameObject.GetComponent <Renderer>().material.SetColor("_Color", _color); } int _idTexture = EncryptedPlayerPrefs.GetInt(item.name + "Texture", -1); if (_idTexture != -1) { if (_idTexture != 11) { item.GetComponent <Renderer>().material.SetTexture("_MainTex", _SelectedTexture[_idTexture]); if (scene.name != "Gallerie") { item.GetComponent <Highlight>()._idTexture = _idTexture; } } } } }
IEnumerator Loading() { FinanceManager _totalMoney = _managers.GetComponent <FinanceManager>(); // Check if we have any data saved before if (EncryptedPlayerPrefs.GetFloat(_textSplit[0] + "TotalMoney", -1f) != -1f) { // Get the totalMoney stored value and assign it. double total = (double)EncryptedPlayerPrefs.GetFloat(_textSplit[0] + "TotalMoney", -1f); _totalMoney.totalMoney = total; moneyText.text = "" + total.ToString("F2"); // Get the Elevator Drop Off Amount stored value and assign it. Inventory _elevator_amount = _elevatorDropOff_Amount.GetComponent <Inventory>(); _elevator_amount.money = EncryptedPlayerPrefs.GetFloat(_textSplit[0] + "ElevatorDropOff_Amount", -1f); _elevator_amount._floatingText.text = "" + Mathf.Round(_elevator_amount.money).ToString(); // Get the Elevator Upgrade Amount stored value and assign it. UpgradeActorUI _elevatorUpgradeAmount = _elevatorUpgrade.GetComponent <UpgradeActorUI>(); _elevatorUpgradeAmount._price = EncryptedPlayerPrefs.GetFloat(_textSplit[0] + "ElevatorUpgradeAmount", -1f); Actor _elevatorSkillMultiplier = _elevator.GetComponent <Actor>(); // Get the Elevator Skill Multiplier stored value and assign it. _elevatorSkillMultiplier.SkillMultiplier = EncryptedPlayerPrefs.GetFloat(_textSplit[0] + "ElevatorSkillMultiplier", -1f); _elevatorUpgradeBtn_Text.text = "" + Mathf.Round(_elevatorUpgradeAmount._price).ToString(); _elevatorUpgradeAmount.LoadLastUpgrade(); // Get the WareHouse Amount stored value and assign it. UpgradeActorUI _wareHouseAmount = _warehouseUpgrade.GetComponent <UpgradeActorUI>(); _wareHouseAmount._price = EncryptedPlayerPrefs.GetFloat(_textSplit[0] + "WareHouseAmount", -1f); // Get the WareHouse Skill Multiplier stored value and assign it. Actor _wareHouseSkillMultiplier = _wareHouse.GetComponent <Actor>(); _wareHouseSkillMultiplier.SkillMultiplier = EncryptedPlayerPrefs.GetFloat(_textSplit[0] + "WareHouseSkillMultiplier", -1f); _warehouseUpgradeBtn_Text.text = "" + Mathf.Round(_wareHouseAmount._price).ToString(); _wareHouseAmount.LoadLastUpgrade(); // Get the total number of shafts saved value. int nb_shafts = EncryptedPlayerPrefs.GetInt(_textSplit[0] + "NumberOfShafts", -1); // Load all the saved shafts. for (int i = _managers.GetComponent <ShaftManager>().Shafts.Count; i < nb_shafts; i++) { _managers.GetComponent <ShaftManager>().LoadPreviousShafts(); } yield return(1); // Get the Upgrade Amout, Skill Multiplier & Drop Off Amount stored value // for every shaft and assign them. ShaftManager gett = _managers.GetComponent <ShaftManager>(); for (int i = 0; i < nb_shafts; i++) { float UpgradeAmount = +EncryptedPlayerPrefs.GetFloat(_textSplit[0] + "UpgradeAmount" + i, -1f); float SkillMultiplier = +EncryptedPlayerPrefs.GetFloat(_textSplit[0] + "SkillMultiplier" + i, -1f); float DropOff_Amount = +EncryptedPlayerPrefs.GetFloat(_textSplit[0] + "DropOff_Amount" + i, -1f); gett.Shafts[i].transform.GetChild(1).GetComponent <Actor>().SkillMultiplier = SkillMultiplier; gett.Shafts[i].transform.GetChild(3).GetChild(1).GetComponent <UpgradeActorUI>()._price = UpgradeAmount; gett.Shafts[i].transform.GetChild(3).GetChild(1).GetChild(1).GetChild(1).gameObject.GetComponent <TextMeshProUGUI>().text = "" + Mathf.Round(UpgradeAmount).ToString(); gett.Shafts[i].transform.GetChild(3).GetChild(1).GetComponent <UpgradeActorUI>().LoadLastUpgrade(); gett.Shafts[i].transform.GetChild(2).GetChild(1).GetComponent <Inventory>().money = DropOff_Amount; gett.Shafts[i].transform.GetChild(2).GetChild(1).GetComponent <Inventory>()._floatingText.text = "" + Mathf.Round(DropOff_Amount).ToString(); } // The game is loaded so, hide the menu & return to game. _popUp.SetActive(false); _menuBackground.SetActive(false); _map.SetActive(false); _menuBtn.GetComponent <Button>().interactable = true; _moneyAmount.SetActive(true); Time.timeScale = 1.0f; } // If no data was saved we show an alert message: There is no saved data to load else { _popUp.SetActive(true); _menuBackground.SetActive(false); _map.SetActive(false); } }
public float LoadGameFloat(string key) { return(EncryptedPlayerPrefs.GetFloat(key, -1)); }