Пример #1
0
    /// <summary>
    /// Start this instance.
    /// </summary>
    /// <returns>A Unity coroutine IEnumerator.</returns>
    public IEnumerator Start()
    {
        nArray = new MoBackArray();
        MoBackRow newRow1 = new MoBackRow("TestMoback");

        // Create a new row for a new user with a score of 0 to start.
        newRow1.SetValue("Name", "MoBackUser");
        newRow1.SetValue("Score", 0);

        // Send the data to the table and wait for a response.
        MoBackRequest response = newRow1.Save();

        yield return(response.Run());

        // If the response to the request is an error, output the error details.
        if (response.State == MoBackRequest.RequestState.ERROR)
        {
            Debug.LogError(response.errorDetails);
        }

        if (menuHandler == null)
        {
            menuHandler = FindObjectOfType <DemoMenuHandler>();
        }
    }
Пример #2
0
    IEnumerator UpdateRow()
    {
        MoBackRow newRow = new MoBackRow("PlayersData");

        newRow.SetValue("IDcode", currentID);
        newRow.SetValue("aValue", GameObject.Find("Main").GetComponent <scene2script>().userData.a);
        newRow.SetValue("bValue", GameObject.Find("Main").GetComponent <scene2script>().userData.b);
        newRow.SetValue("xValue", GameObject.Find("Main").GetComponent <scene2script>().userData.x);
        newRow.SetValue("yValue", GameObject.Find("Main").GetComponent <scene2script>().userData.y);
        newRow.SetValue("maxScene", maxScene);
        MoBackRequest response = newRow.Save();

        yield return(response.Run());
    }
Пример #3
0
    /// <summary>
    /// Saves the name of the player.
    /// </summary>
    /// <returns>The player name.</returns>
    private IEnumerator SavePlayerName()
    {
        playerRow.SetValue("PlayerName", parentInput.text);

        MoBackRequest savePlayerInfoRequest = playerRow.Save();

        yield return(savePlayerInfoRequest.Run());

        if (savePlayerInfoRequest.State != MoBackRequest.RequestState.COMPLETED)
        {
            Debug.LogError("Can't save player info " + savePlayerInfoRequest.errorDetails.Message);
            yield break;
        }
        else
        {
            ChangeScene(inputItemScene);
            Display(parentInput.text + " saved to " + DemoRelationTableName + "Table");
        }
    }
Пример #4
0
    /// <summary>
    /// Updates an existing row with a new score and notifies the user when successful.
    /// </summary>
    /// <returns>A Unity coroutine IEnumerator.</returns>
    /// <param name="score">Score to submit.</param>
    public IEnumerator SubmitScore(int score)
    {
        // Create a new table called "TestMoBack" if it hasn't already been created; otherwise, specify which table you want to work with.
        table = new MoBackTableInterface("TestMoback");

        // Send a request for data to the server with a specific set of parameters.
        MoBackRequest <List <MoBackRow> > tableContentsFetch = table.GetRows(new MoBackRequestParameters().EqualTo("Name", "MoBackUser"));

        yield return(tableContentsFetch.Run());

        // Once the request has been completed, manipulate the fetched data.
        if (tableContentsFetch.State == MoBackRequest.RequestState.COMPLETED)
        {
            List <MoBackRow> rows = tableContentsFetch.ResponseValue;

            // Update the last item in the table to a new score and send to the server.
            MoBackRow newRow = rows[rows.Count - 1];
            newRow.SetValue("Score", score);
            MoBackRequest response = newRow.Save();

            // Wait for a response before displaying that the request was successful.
            yield return(response.Run());

            if (response.State == MoBackRequest.RequestState.COMPLETED)
            {
                menuHandler.Display("Score submitted successfully.");
            }
            else
            {
                menuHandler.Display("Request was not successful. Please double check your app ID and/or environment key.");

                // Display an error should one occur.
                Debug.Log(response.errorDetails);
            }
        }
        else
        {
            // Display an error should one occur.
            Debug.Log(tableContentsFetch.errorDetails);
        }
    }