Esempio n. 1
0
    public IEnumerator Start()
    {
        scoresDownloaded = false;
        bool scoresDownloadedTemp = true;

        serverAccessed = false;
        levelScores    = new string[4];
        int stage = GameManager.GetStage();
        int level = GameManager.GetLevel();

        bool notUpdated = false;

        for (int stars = 0; stars < 4; stars++)
        {
            WWWForm form = new WWWForm();
            form.AddField("stagePost", stage);
            form.AddField("levelPost", level);
            form.AddField("starsPost", stars);

            WWW highscoresData = new WWW("https://" + url, form);
            yield return(highscoresData);         // on attend que les scores soient téléchargés

            if (!string.IsNullOrEmpty(highscoresData.error))
            {
                Debug.print(highscoresData.error);
                levelScores[stars]   = "Unable to access server";
                scoresDownloadedTemp = false; // si un est faux, il devient faux
                // ET METTRE EN PLACE LE STOCKAGE DES NOUVEAUX TEMPS EN LOCAL POUR LES ENVOYER PLUS TARD QD LA CONNEXION SE REFAIT
            }
            else
            {
                levelScores[stars] = highscoresData.text;
            }

            print("enter");
            int localScore = (stage == 0 ? LocalHighScores.GetLocalChallengeScore(level, stars) : LocalHighScores.localScores[10 * (stage - 1) + level][stars]);
            if (localScore != 0 && int.Parse(GetDataValue(levelScores[stars], "Time")) > localScore)  //temps local meilleur => on update
            {
                notUpdated = true;
                yield return(UploadScore.insertScore(PlayerPrefs.GetString("PlayerPseudo"), stage, level, localScore, stars));

                Debug.print("LocalScore put online");
            }
        }
        if (notUpdated)
        {
            print("Restart");
            yield return(Start());  // on retélécharge les scores !
        }
        scoresDownloaded = scoresDownloadedTemp;
        serverAccessed   = true;
        Debug.print("Highscores Downloaded in " + Time.time + ", " + scoresDownloaded);
        GameObject.FindWithTag("ScoresScript").GetComponent <DisplayScores>().displayScores(SQLScores.GetLevelScores(stage, level));
    }