private int FilteringByScoreType(BestScoreType scoreType, int oriScore, ref DateTime recordedTime) { switch (scoreType) { case BestScoreType.Daily: if (recordedTime.Date < DateTime.Now.Date) { recordedTime = DateTime.Now; return(0); } return(oriScore); case BestScoreType.Weekly: if (DateTime.Now.AlreadyPastWeek(recordedTime)) { recordedTime = DateTime.Now; return(0); } return(oriScore); case BestScoreType.AllTime: return(oriScore); default: throw new ArgumentOutOfRangeException(nameof(scoreType), scoreType, null); } }
private void SaveToPrefs(BestScoreType scoreType, BestScoreInfo scoreInfo) { PlayerPrefs.SetInt(GetPrefsPath(scoreType) + "_SCORE", scoreInfo.score); PlayerPrefs.SetString(GetPrefsPath(scoreType) + "_DATE", scoreInfo.recordedTime.ToString(CultureInfo.InvariantCulture)); PlayerPrefs.Save(); }
private BestScoreInfo GetScoreInfoInPrefs(BestScoreType scoreType, bool filtering = true) { var curScore = PlayerPrefs.GetInt(GetPrefsPath(scoreType) + "_SCORE", 0); var curRecordDate = DateTime.Parse(PlayerPrefs.GetString(GetPrefsPath(scoreType) + "_DATE", DateTime.Now.ToString(CultureInfo.InvariantCulture))); if (filtering) { curScore = FilteringByScoreType(scoreType, curScore, ref curRecordDate); } return(new BestScoreInfo { recordedTime = curRecordDate, score = curScore, }); }
public BestScoreInfo GetBestScoreInfo(BestScoreType scoreType) { return(_bestScoreDictionary[scoreType]); }
private string GetPrefsPath(BestScoreType scoreType) => PlayerPrefs_PREFIX + scoreType;