Exemplo n.º 1
0
        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);
            }
        }
Exemplo n.º 2
0
        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();
        }
Exemplo n.º 3
0
        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,
            });
        }
Exemplo n.º 4
0
 public BestScoreInfo GetBestScoreInfo(BestScoreType scoreType)
 {
     return(_bestScoreDictionary[scoreType]);
 }
Exemplo n.º 5
0
 private string GetPrefsPath(BestScoreType scoreType) => PlayerPrefs_PREFIX + scoreType;