private void Start() { if (!instance) { instance = true; } else { Destroy(gameObject); } DontDestroyOnLoad(gameObject); playerScore = 0; //print(Application.persistentDataPath); if (SaveFiles.JsonFileExistsAtPersPath("PlayerScore"))//if there is a player score file already { playerScoreManager = SaveFiles.LoadObjectFromJSONFile <PlayerScoreManagerFile>("PlayerScore"); topPlayerScore = playerScoreManager.TopPlayerScore;//load the top score from it } else { playerScoreManager.TopPlayerScore = 0; topPlayerScore = 0; SaveFiles.SaveObjectAsJSONAtPersDataPath(playerScoreManager, "PlayerScore");//make a new player score file } scoreTxt.text = playerScoreManager.TopPlayerScore.ToString();//show it on the screen }
public void SetBallSprite(Ball ball) { choosedBall = ball;//set the coosed ball which the player choosed it if (ball.IsAdNeeded) { ShowLockedPanel(ball);//show this ball is locked because of not enough score print("AdNeeded"); } else if (!ball.IsAdNeeded && ball.BallScoreOpen == 0) { unlockedBallsFile.BallsLockStates[ball.BallName] = true; //unlock the ball SaveFiles.SaveObjectAsJSONAtPersDataPath(unlockedBallsFile, SaveFilesName.UnlockedBalls); //save the new ball lock state RemoveUsedBallPanel(); //remove the UsedBallPanel from the other balls ball.UsedBallPanel.SetActive(true); //active the UsedBallPanel of this ball SaveFiles.SetStringPlayerPref("BallName", ball.BallName.ToString()); print("BallChoosed"); } else { if (topScore >= ball.BallScoreOpen) //if he has enough score then use this ball { RemoveUsedBallPanel(); //remove the UsedBallPanel from the other balls ball.UsedBallPanel.SetActive(true); //active the UsedBallPanel of this ball SaveFiles.SetStringPlayerPref("BallName", ball.BallName.ToString()); print("BallChoosed"); } else { ShowLockedPanel(ball);//show this ball is locked because of not enough score print("BallLocked"); } } }
public void SavePlayerScore() { if (playerScore > playerScoreManager.TopPlayerScore)//if the new score is bigger the the top score { playerScoreManager.TopPlayerScore = playerScore; topPlayerScore = playerScoreManager.TopPlayerScore;//make it the top score } SaveFiles.SaveObjectAsJSONAtPersDataPath(playerScoreManager, "PlayerScore");//save new score }
private void Start() { if (SaveFiles.JsonFileExistsAtPersPath(SaveFilesName.UnlockedBalls))//if there is a player score file already { unlockedBalls = SaveFiles.LoadObjectFromJSONFile <UnlockedBallsFile>(SaveFilesName.UnlockedBalls); UnLockBall(unlockedBalls); } else { SaveFiles.SaveObjectAsJSONAtPersDataPath(unlockedBalls, SaveFilesName.UnlockedBalls);//make a new player score file } }
public static float GetTopScore() { PlayerScoreManagerFile playerScoreManager = new PlayerScoreManagerFile(); if (SaveFiles.JsonFileExistsAtPersPath("PlayerScore"))//if there is a player score file already { playerScoreManager = SaveFiles.LoadObjectFromJSONFile <PlayerScoreManagerFile>("PlayerScore"); return(playerScoreManager.TopPlayerScore);//load the top score from it } else { playerScoreManager.TopPlayerScore = 0; SaveFiles.SaveObjectAsJSONAtPersDataPath(playerScoreManager, "PlayerScore");//make a new player score file return(0); } }