Beispiel #1
0
    private IEnumerator GetAllUserHighScores(int userId, System.Action <ScoreBoardEntry[]> callBack)
    {
        WWWForm form = new WWWForm();

        form.AddField("userIDPost", userId);
        UnityWebRequest webRequest = UnityWebRequest.Post(highscoreUrl, form);

        yield return(webRequest.SendWebRequest());

        if (webRequest.isNetworkError || webRequest.isHttpError)
        {
            Debug.Log(webRequest.downloadHandler.text);
            Debug.Log(webRequest.error);
        }

        else
        {
            string entry = webRequest.downloadHandler.text;

            if (!entry.Contains("\t"))
            {
                throw new System.Exception("Improperly formatted data from database (QUERY CONTAINS AN ERROR " + entry);
            }


            string[] splitEntries = entry.Split('\n');

            ScoreBoardEntry[] returnEntries = new ScoreBoardEntry[splitEntries.Length - 1];


            for (int i = 0; i < returnEntries.Length; i++)
            {
                string[] temp = splitEntries[i].Split('\t');



                int    returnID, returnLevel, returnScore;
                string returnName;

                int.TryParse(temp[0], out returnID);
                int.TryParse(temp[1], out returnLevel);
                int.TryParse(temp[2], out returnScore);
                returnName = temp[3];

                //Debug.Log(returnID + " | " + returnLevel + " | " + returnScore + " | " + returnName);

                returnEntries[i] = new ScoreBoardEntry(returnID, returnLevel, returnScore, returnName);
            }


            callBack(returnEntries);
        }
    }
    public void Callback(ScoreBoardEntry data)
    {
        DigitComponent[] digitComps = MapSpawner.Instance.GetCurrentMapHolder().GetComponentsInChildren <DigitComponent>();

        for (int i = 0; i < digitComps.Length; i++)
        {
            if (i == 0)
            {
                digitComps[i].UpdateDisplayValue(scoreValue);
            }
            if (i == 1)
            {
                digitComps[i].UpdateDisplayValue(levelValue);
            }
        }


        // Level
        if (data.highLevel < levelValue)
        {
            doUploadScore = true;

            // Display "New Best Level"
            Debug.Log("New Best Level.  Old = " + data.highLevel + "  | New = " + levelValue);
        }


        DisplayHighscoreEffect(); // TEMP
        // Score
        if (data.highScore < scoreValue)
        {
            doUploadScore = true;

            // Display "New Best Score"
            Debug.Log("New Best Score. Old = " + data.highScore + "  | New = " + scoreValue);
            DisplayHighscoreEffect();
        }

        if (doUploadScore)
        {
            UploadUserScore scoreUploader = new UploadUserScore();

            int playerID;
            int.TryParse(GameManager.instance.loadedProfile.GetPlayerID(), out playerID);
            scoreUploader.UploadScore(new ScoreBoardEntry(playerID, levelValue, scoreValue));
        }
    }
Beispiel #3
0
    //public void GetScoreForUser()
    //{
    //    StartCoroutine(GetUserScore());
    //}

    private IEnumerator GetUserScore(int userId, System.Action <ScoreBoardEntry> callBack)
    {
        WWWForm form = new WWWForm();

        form.AddField("userIDPost", userId);
        UnityWebRequest webRequest = UnityWebRequest.Post(/*phpScriptsFolder + phpAddTheItemScriptLocation*/ url, form);

        //UnityWebRequest webRequest = UnityWebRequest.Post(/*phpScriptsFolder + phpAddTheItemScriptLocation*/ url, form);

        yield return(webRequest.SendWebRequest());

        if (webRequest.isNetworkError || webRequest.isHttpError)
        {
            Debug.Log(webRequest.downloadHandler.text);
            Debug.Log(webRequest.error);
        }
        else
        {
            //Debug.Log("Score Download Complete!");
            string entry = webRequest.downloadHandler.text;

            if (!entry.Contains("\t"))
            {
                throw new System.Exception("Improperly formatted data from database " + entry);
            }
            string[] temp = entry.Split('\t');

            int    returnID, returnLevel, returnScore;
            string returnName;

            int.TryParse(temp[0], out returnID);
            int.TryParse(temp[1], out returnLevel);
            int.TryParse(temp[2], out returnScore);
            returnName = temp[3];

            //Debug.Log(returnID +" | "+ returnLevel + " | " + returnScore);

            ScoreBoardEntry returnEntry = new ScoreBoardEntry(returnID, returnLevel, returnScore, returnName);



            callBack(returnEntry);
        }
    }
    private void MakeScoreDownloadRequest()
    {
        DownloadScore scoreDownloader = new DownloadScore();



        if (scoreDownloader != null)
        {
            scoreBoardEntries  = new ScoreBoardEntry[0];
            currentPlayerEntry = null;


            scoreDownloader.GetScoreForUser(GameManager.instance.loadedProfile.GetPlayerIDasInt(), CallbackUserScore);

            scoreDownloader.GetScoresForScoreboard(GameManager.instance.loadedProfile.GetPlayerIDasInt(), CallbackHighScores);


            // Store the coroutine so it can be retrieved in the event of a timeout
            waitRoutine = WaitForDownloadComplete();
            GameManager.instance.StartCoroutine(waitRoutine);
        }
    }
Beispiel #5
0
    IEnumerator LoadUserDatas()
    {
        PopupManager.Get().OpenLoading("", "Loading...");

        Task <UserData[]> task = UserDatabase.Get().GetAllUserData();

        yield return(TaskExtension.YieldWait(task));

        if (task.IsCompleted)
        {
            UserData[] userDatas = task.Result;
            if (userDatas.Length > 0)
            {
                foreach (UserData userData in userDatas)
                {
                    ScoreBoardEntry entry = Instantiate(scoreBoardEntryPrefab, scoreBoardTable);
                    entry.Init(userData.iconURL, userData.name, userData.highScore);
                    scoreBoardEntries.Add(entry);
                }
            }
        }
        PopupManager.Get().CloseLoading();
    }
Beispiel #6
0
    private IEnumerator UploadScoreCoroutine(ScoreBoardEntry data)
    {
        WWWForm form = new WWWForm();

        form.AddField("IDPost", data.playerId);
        form.AddField("levelNumPost", data.highLevel);
        form.AddField("highscorePost", data.highScore);

        UnityWebRequest webRequest = UnityWebRequest.Post(url, form);

        yield return(webRequest.SendWebRequest());

        if (webRequest.isNetworkError || webRequest.isHttpError)
        {
            Debug.Log(webRequest.error);
        }
        else
        {
            Debug.Log("Score Upload Complete!");
            Debug.Log(webRequest.url);
            Debug.Log(url);
            Debug.Log(webRequest.downloadHandler.text);
        }
    }
 public void CallbackUserScore(ScoreBoardEntry data)
 {
     currentPlayerEntry = data;
 }
Beispiel #8
0
 //[ContextMenu("Add Item")]  // Calls The AddItemToDB Coroutine from the inspector
 public void UploadScore(ScoreBoardEntry data)
 {
     GameManager.instance.StartCoroutine(UploadScoreCoroutine(data));
 }