public void ReportProgress(string id, double progress, Action <bool> callback)
        {
            //Debug.Log("ReportProgress");
            if (!this.VerifyUser())
            {
                return;
            }
            foreach (Achievement current in _achievements)
            {
                if (current.id == id && current.percentCompleted <= progress)
                {
                    if (progress >= 100.0)
                    {
                        current.SetCompleted(true);
                    }
                    current.SetHidden(false);
                    current.SetLastReportedDate(DateTime.Now);
                    current.percentCompleted = progress;
                    if (callback != null)
                    {
                        callback(true);
                    }
#if !UNITY_WEBPLAYER
                    PlayerPrefsSerializer.Save("achieve_" + id, current);
#endif
                    return;
                }
            }
            foreach (AchievementDescription current2 in _achievementDescriptions)
            {
                if (current2.id == id)
                {
                    bool        completed = progress >= 100.0;
                    Achievement item      = new Achievement(id, progress, completed, false, DateTime.Now);
                    _achievements.Add(item);
                    if (callback != null)
                    {
                        callback(true);
                    }
                    //Debug.Log(item);
#if !UNITY_WEBPLAYER
                    PlayerPrefsSerializer.Save("achieve_" + id, item);
#endif
                    return;
                }
            }
            Debug.LogError("Achievement ID not found");
            if (callback != null)
            {
                callback(false);
            }
        }
Beispiel #2
0
 public void SaveGame()
 {
     // save maze
     PlayerPrefsSerializer.Save("MazeData", mazeData);
     // save player position
     PlayerPrefs.SetFloat("PlayerX", player.transform.position.x);
     PlayerPrefs.SetFloat("PlayerY", player.transform.position.y);
     PlayerPrefs.SetFloat("PlayerZ", player.transform.position.z);
     // save enemy position
     PlayerPrefs.SetFloat("EnemyX", enemy.transform.position.x);
     PlayerPrefs.SetFloat("EnemyY", enemy.transform.position.y);
     PlayerPrefs.SetFloat("EnemyZ", enemy.transform.position.z);
     // save score
     PlayerPrefs.SetInt("Score", score.GetScore());
 }
        public void ReportScore(long score, string board, Action <bool> callback)
        {
            //Debug.Log("ReportScore");
            if (!this.VerifyUser())
            {
                return;
            }
            foreach (Leaderboard current in _leaderboards)
            {
                if (current.id == board)
                {
                    List <Score> scoreList = new List <Score> ((Score[])current.scores)
                    {
                        new Score(board, score, this.localUser.id, DateTime.Now, score + " points", 0)
                    };

                    scoreList.Sort((Score s1, Score s2) => s2.value.CompareTo(s1.value));
                    for (int i = 0; i < scoreList.Count; i++)
                    {
                        scoreList [i].SetRank(i + 1);
                    }

                    current.SetScores(scoreList.GetRange(0, Mathf.Min(MAX_RANK, scoreList.Count)).ToArray());

                    if (callback != null)
                    {
                        callback(true);
                    }
#if !UNITY_WEBPLAYER
                    PlayerPrefsSerializer.Save("scores_" + board, current.scores);
#endif
                    return;
                }
            }
            Debug.LogError("Leaderboard not found");
            if (callback != null)
            {
                callback(false);
            }
        }