public void AddXP(int exp) { user.totalXP += exp; int tempLVL = Mathf.FloorToInt(expInc * Mathf.Sqrt(user.totalXP)); // LEVEL UP if (tempLVL > user.lvl) { // set new user level user.lvl = tempLVL; // unlock level specific rewards LevelRewards.UnlockLevelRewards(); // label manipulation lvlLabel.text = "[Level " + user.lvl + "]"; // show level up banner LevelUpBanner.instance.ShowBanner(); } float expNext = (inverseCalcFactor * (user.lvl + 1) * (user.lvl + 1)); float expLast = (inverseCalcFactor * user.lvl * user.lvl); float diff = expNext - user.totalXP; // progressbar manipulation lvlProgressBar.maxValue = expNext; lvlProgressBar.minValue = expLast; lvlProgressBar.value = (expNext - diff); }
// restores all savestate data and replaces instance vars accordingly public void LoadPrefs() { if (PlayerPrefs.HasKey("firststart")) { intro.SetActive(false); user = new User(PlayerPrefs.GetString("user_gender"), PlayerPrefs.GetInt("user_age"), PlayerPrefs.GetInt("user_height"), PlayerPrefs.GetInt("user_weight"), PlayerPrefs.GetInt("user_lvl"), PlayerPrefs.GetInt("user_totalXP")); AddXP(0); //add 0 XP to restore progressbar position lvlLabel.text = "[Level " + user.lvl + "]"; //deserialize json-string into workoutHistory-dict and restore it var dWorkoutHistory = JsonConvert.DeserializeObject <Dictionary <DateTime, List <WorkoutSession> > >(PlayerPrefs.GetString("workoutHistory")); workoutHistory = dWorkoutHistory; Color mainColor = PlayerPrefsX.GetColor("mainColor"); Color bgColor = PlayerPrefsX.GetColor("bgColor"); GameObject.FindGameObjectWithTag("Camera").GetComponent <Camera>().backgroundColor = bgColor; GameObject[] bgos = GameObject.FindGameObjectsWithTag("BGColor"); foreach (GameObject go in bgos) { go.GetComponent <UnityEngine.UI.Image>().color = bgColor; } GameObject[] gos = GameObject.FindGameObjectsWithTag("Header"); foreach (GameObject go in gos) { go.GetComponent <UnityEngine.UI.Image>().color = mainColor; } mainCol = mainColor; bgCol = bgColor; NotificationTimer.h = PlayerPrefs.GetInt("notification_h"); NotificationTimer.m = PlayerPrefs.GetInt("notification_m"); NotificationTimer.SetupLocalNotificationsOnReboot(NotificationTimer.h, NotificationTimer.m, 7); //unlock all currently unlocked rewards again LevelRewards.UnlockLevelRewards(); } else { intro.SetActive(true); } }