/// <summary> /// Saves multiple MoBack Objects(Row) with a single call. /// </summary> /// <returns>A Unity coroutine IEnumerator.</returns> private IEnumerator SaveMultipleObjects() { if (demoBatchObjects == null || demoBatchObjects.Count <= 0) { Display("No data in object"); } saveButton.enabled = false; MoBackTableInterface demoBatchTable = new MoBackTableInterface(DemoBatchTableName); MoBackRequest saveMultipleObjectsRequest = demoBatchTable.RequestB.SaveMultipleObjects(demoBatchObjects); yield return(saveMultipleObjectsRequest.Run()); if (saveMultipleObjectsRequest.State == MoBackRequest.RequestState.COMPLETED) { foreach (var item in demoBatchObjects) { Display("Object saved"); } } if (saveMultipleObjectsRequest.State == MoBackRequest.RequestState.ERROR) { Display(saveMultipleObjectsRequest.errorDetails.Message); } saveButton.enabled = true; }
/// <summary> /// Gets the score and Debug.Logs it in the console as well as displays it in DisplayText. /// </summary> /// <returns>A Unity coroutine IEnumerator.</returns> public IEnumerator FetchScore() { // Create a variable to hold the recieved results from the server. string score = null; // Fetch data from the specified table and send the request with a specific parameter of EqualTo(), which will only return // values that are equal to "MoBackUser" under the column of "Name". table = new MoBackTableInterface("TestMoback"); MoBackRequest <List <MoBackRow> > tableContentsFetch = table.GetRows(new MoBackRequestParameters().EqualTo("Name", "MoBackUser")); yield return(tableContentsFetch.Run()); // If the fetch request is successful, display the data. if (tableContentsFetch.State == MoBackRequest.RequestState.COMPLETED) { List <MoBackRow> rows = tableContentsFetch.ResponseValue; for (int i = 0; i < rows.Count; i++) { if (rows[i].GetString("Name") == "MoBackUser") { // Display the score in the debug console and in the DisplayText text object in the scene. score = rows[i].GetInt("Score").ToString(); Debug.Log("Score: " + score); menuHandler.Display("Score: " + score.ToString()); } } } else { Debug.Log(tableContentsFetch.errorDetails); } }
/// <summary> /// Login this instance. /// </summary> /// <returns>A Unity coroutine IEnumerator.</returns> private IEnumerator Login() { MoBackRequest loginRequest = demoUser.Login(); yield return(loginRequest.Run()); // If login request can't complete -> exit. if (loginRequest.State != MoBackRequest.RequestState.COMPLETED) { Debug.LogError("Login request error: " + loginRequest.message); Display(loginRequest.message); yield break; } else { Display("User Login Success"); } // If login request is complete, but we can't loggin. Mostly due to invalid credential (wrong password or username) -> exit. if (!demoUser.IsLoggedIn) { Debug.LogError("invalid credential?"); Display(loginRequest.message); yield break; } else { ChangeScene(signedInPrompt); } }
/// <summary> /// Deletes the multiple objects. /// </summary> /// <returns>A Unity coroutine IEnumerator.</returns> private IEnumerator DeleteMultipleObjects() { if (demoBatchObjects == null || demoBatchObjects.Count <= 0) { Debug.LogError("Need to populate demoBatchObjects first"); Display("Need to populate demoBatchObjects first"); yield break; } deleteButton.enabled = false; MoBackTableInterface demoBatchTable = new MoBackTableInterface(DemoBatchTableName); MoBackRequest deleteMultipleObjectsRequest = demoBatchTable.RequestB.DeleteMultipleOjbects(demoBatchObjects); yield return(deleteMultipleObjectsRequest.Run()); if (deleteMultipleObjectsRequest.State == MoBackRequest.RequestState.COMPLETED) { Display("Object deleted "); demoBatchObjects = new List <MoBackRow>(); } else if (deleteMultipleObjectsRequest.State == MoBackRequest.RequestState.ERROR) { Display(deleteMultipleObjectsRequest.errorDetails.Message); } deleteButton.enabled = false; }
/// <summary> /// Signs up. /// </summary> /// <returns>A Unity coroutine IEnumerator.</returns> private IEnumerator SignUp() { // Add custom values if any demoUser.SetValue(firstNameColumn, signUpFirstNameField.text); demoUser.SetValue(lastNameColumn, signUpLastNameField.text); demoUser.SetValue(ageColumn, signUpAgeField.text); // Create signup request. MoBackRequest signUpNewUserRequest = demoUser.SignUp(); // Send SignUp request. yield return(signUpNewUserRequest.Run()); // If request can't complete, exit. if (signUpNewUserRequest.State != MoBackRequest.RequestState.COMPLETED) { Debug.LogError("Error: Account creation unsuccessful."); Display("Account creation unsuccessful"); yield break; } else { ChangeScene(signedInPrompt); Display("User account creation successful"); } // If signup request is complete, but we can't sign up. Mostly because there is already an existence account. // We give a error message here. if (!demoUser.CompleteSignedUp) { Debug.LogError("Error: User already exists. New column won't be stored on the server."); Display("User already exists - New column won't be stored on the server"); } }
public IEnumerator Data() //здесь происходит поиск данных по ID и при + результате внесение их в переменные для дальнейшей работы { exampleTable = new MoBackTableInterface("PlayersData"); MoBackRequest <List <MoBackRow> > tableContentsFetch = exampleTable.GetRows(); yield return(tableContentsFetch.Run()); if (tableContentsFetch.State == MoBackRequest.RequestState.COMPLETED) { rows = tableContentsFetch.ResponseValue; for (int i = 0; i < rows.Count; i++) { if (rows [i].GetString("IDcode") == currentID) { rowPosition = i; MoBackRequest response1 = exampleTable.DeleteObject(rows [rowPosition].GetString("objectId")); yield return(response1.Run()); a = rows [i].GetFloat("aValue"); b = rows [i].GetFloat("bValue"); x = rows [i].GetFloat("xValue"); y = rows [i].GetFloat("yValue"); maxScene = rows [i].GetInt("maxScene"); break; } } } else { Debug.Log(tableContentsFetch.errorDetails); } initialized = true; }
/// <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>(); } }
/// <summary> /// Updates the user info. /// </summary> /// <returns>A Unity coroutine IEnumerator.</returns> private IEnumerator UpdateUserInfo() { updateUserInfoButton.enabled = false; // Check if user is signed in. if (!demoUser.IsLoggedIn) { MoBackRequest loginNewUser = demoUser.Login(); yield return(loginNewUser.Run()); if (loginNewUser.State != MoBackRequest.RequestState.COMPLETED) { Debug.LogError("Error: Login attempt unsuccessful."); Display("Login attempt unsuccessful"); yield break; } } // Check is new value is entered in field. if (string.IsNullOrEmpty(userInfoFirstNameField.text) && string.IsNullOrEmpty(userInfoLastNameField.text) && string.IsNullOrEmpty(userInfoAgeField.text)) { updateUserInfoButton.enabled = true; Display("No New Value Entered."); yield break; } else { // Set new value entered in field. if (!string.IsNullOrEmpty(userInfoFirstNameField.text)) { demoUser.SetValue(firstNameColumn, userInfoFirstNameField.text); } if (!string.IsNullOrEmpty(userInfoLastNameField.text)) { demoUser.SetValue(lastNameColumn, userInfoLastNameField.text); } if (!string.IsNullOrEmpty(userInfoAgeField.text)) { demoUser.SetValue(ageColumn, userInfoAgeField.text); } } // Update to server. MoBackRequest updateUserInfoRequest = demoUser.UpdateUserInfo(); yield return(updateUserInfoRequest.Run()); if (updateUserInfoRequest.State != MoBackRequest.RequestState.COMPLETED) { Debug.LogError("Error: Update user info request unsuccessful."); Display("Update user info request unsuccessful"); } else { Display("User information updated"); } updateUserInfoButton.enabled = true; }
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()); }
/// <summary> /// Removes the relation. /// </summary> /// <returns>The relation.</returns> private IEnumerator RemoveRelation() { MoBackRequest removeRelations = playerRow.RemoveRelations(DemoRelationColumn, items.ToArray()); yield return(removeRelations.Run()); if (removeRelations.State != MoBackRequest.RequestState.COMPLETED) { Debug.LogError("Can't remove relation objects. " + removeRelations.errorDetails.Message); } else { Display("Relation removed"); } }
/// <summary> /// Invites the friend. /// </summary> /// <returns>A Unity coroutine IEnumerator.</returns> private IEnumerator InviteFriend() { sendInviteButton.enabled = false; MoBackRequest sendInvitationRequest = demoUser.SendInvitation(inviteEmailField.text); yield return(sendInvitationRequest.Run()); sendInviteButton.enabled = true; if (sendInvitationRequest.State == MoBackRequest.RequestState.COMPLETED) { Display("Invitation request sent"); } else { Display(sendInvitationRequest.errorDetails.Message); } }
/// <summary> /// Resets the password. /// </summary> /// <returns>A Unity coroutine IEnumerator.</returns> private IEnumerator ResetPassword() { resetPasswordButton.enabled = false; MoBackRequest resetThisUserPasswordRequest = demoUser.ResetPassword(); yield return(resetThisUserPasswordRequest.Run()); resetPasswordButton.enabled = true; if (resetThisUserPasswordRequest.State == MoBackRequest.RequestState.COMPLETED) { Display("Password request sent"); } else { Display(resetThisUserPasswordRequest.errorDetails.Message); } }
/// <summary> /// Deleteuser this instance. /// </summary> /// <returns>A Unity coroutine IEnumerator.</returns> private IEnumerator DeleteUser() { deleteUserButton.enabled = false; MoBackRequest deleteCurrentUser = demoUser.DeleteCurrentUser(); yield return(deleteCurrentUser.Run()); deleteUserButton.enabled = true; if (deleteCurrentUser.State == MoBackRequest.RequestState.COMPLETED) { ChangeScene(loginPrompt); Display("Deleted current user"); } else { Display(deleteCurrentUser.errorDetails.Message); } }
/// <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"); } }
/// <summary> /// Gets the user info. /// </summary> /// <returns>A Unity coroutine IEnumerator.</returns> private IEnumerator GetUserInfo() { // Check if user is signed in. if (!demoUser.IsLoggedIn) { MoBackRequest loginNewUser = demoUser.Login(); yield return(loginNewUser.Run()); if (loginNewUser.State != MoBackRequest.RequestState.COMPLETED) { Debug.LogError("Error: Login attempt unsuccessful."); Display("Login attempt unsuccessful"); yield break; } } getUserInfoButton.enabled = false; MoBackRequest getUserInfo = demoUser.GetUserInfo(); yield return(getUserInfo.Run()); getUserInfoButton.enabled = true; if (getUserInfo.State != MoBackRequest.RequestState.COMPLETED) { Debug.LogError("Error: User info request unsuccessful."); Display("User info request unsuccessful"); Debug.Log(getUserInfo.errorDetails); yield break; } // Extract values from server. string firstName = demoUser.GetString(firstNameColumn); string lastName = demoUser.GetString(lastNameColumn); string age = demoUser.GetString(ageColumn); //Create a debug text. string debugString = string.Format("Name: {0} {1} \nAge: {2}", firstName, lastName, age); Debug.Log(debugString); Display(debugString); }
/// <summary> /// Gets the relation pointer. /// </summary> /// <returns>The relation pointer.</returns> private IEnumerator GetRelationPointer() { MoBackRequest <List <MoBackPointer> > getRelationPointers = playerRow.GetAllPointerObjects(DemoRelationColumn); yield return(getRelationPointers.Run()); if (getRelationPointers.State != MoBackRequest.RequestState.COMPLETED) { Debug.LogError("Can't get relation pointers. " + getRelationPointers.errorDetails.Message); yield break; } string data = "Object ID:"; foreach (var itemdata in getRelationPointers.ResponseValue) { Debug.Log("Object ID: " + itemdata.objectID); data += ", " + itemdata.objectID; } Display(data); }
/// <summary> /// Logins the user. /// </summary> /// <returns>The user.</returns> /// <param name="name">Name.</param> /// <param name="password">Password.</param> public IEnumerator LoginUser() { // Disable all buttons while signing up and logging in. uploadFileButton.enabled = false; downloadFileButton.enabled = false; deleteFileButton.enabled = false; // Create a new user. demoUser = new MoBackUser(demoMobackUser, demoMoBackPassword, demoMoBackEmail); // Sign up for the demo user. MoBackRequest signUpRequest = demoUser.SignUp(); yield return(signUpRequest.Run()); MoBackRequest currentLoginRequest = demoUser.Login(); yield return(currentLoginRequest.Run()); if (currentLoginRequest.State == MoBackRequest.RequestState.COMPLETED) { if (demoUser.IsLoggedIn) { // enable all button when logging complete. uploadFileButton.enabled = true; downloadFileButton.enabled = true; deleteFileButton.enabled = true; Debug.Log("Login Complete"); } else { Debug.Log("Can't log in"); } DisplayMessage(currentLoginRequest.message); } else if (currentLoginRequest.State == MoBackRequest.RequestState.ERROR) { DisplayMessage(currentLoginRequest.errorDetails.Message); } }
/// <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); } }
/// <summary> /// Gets the relation. /// </summary> /// <returns>The relation.</returns> private IEnumerator GetRelation() { MoBackRequest <List <MoBackRow> > getRelationObjects = playerRow.GetAllRelationObjects(DemoRelationColumn); yield return(getRelationObjects.Run()); if (getRelationObjects.State != MoBackRequest.RequestState.COMPLETED) { Debug.LogError("Can't get relation objects. " + getRelationObjects.errorDetails.Message); yield break; } string data = "My relations: "; Debug.Log("My relations: "); foreach (var item in getRelationObjects.ResponseValue) { Debug.Log(string.Format("Item: {0}", item.GetValue(ItemTypeColumn))); data += ", " + item.GetValue(ItemTypeColumn); } Display(data); }
/// <summary> /// Deletes the file from the server. /// </summary> /// <returns>A Unity coroutine IEnumerator.</returns> /// <param name="name">Name.</param> public IEnumerator DeleteFile(MoBackFile moBackFile) { if (moBackFile == null) { Debug.LogError("moback file is null"); yield break; } deleteFileButton.enabled = false; MoBackRequest deleteFileRequest = moBackFile.DeleteFile(); yield return(deleteFileRequest.Run()); if (deleteFileRequest.State == MoBackRequest.RequestState.COMPLETED) { // Since we stored the file's url on a row in a table. When delete the file, we need to remove the row as well. DisplayMessage("Delete File Success"); MoBackRequest deleteMoBackObject = moBackFile.DeleteMoBackObject(); yield return(deleteMoBackObject.Run()); if (deleteMoBackObject.State == MoBackRequest.RequestState.COMPLETED) { DisplayMessage("Delete object"); } else if (deleteMoBackObject.State == MoBackRequest.RequestState.ERROR) { deleteFileButton.enabled = true; DisplayMessage("Unable to delete the MoBack row associated with the file: " + moBackFile.Name); } } else if (deleteFileRequest.State == MoBackRequest.RequestState.ERROR) { DisplayMessage("Unable to delete the file: " + moBackFile.Name); } deleteFileButton.enabled = true; }
/// <summary> /// Uploads the file. /// </summary> /// <returns>A Unity coroutine IEnumerator.</returns> /// <param name="name">Name of the file to upload from StreamingAssets folder.</param> public IEnumerator UploadFile(MoBackFile mobackFile) { if (mobackFile == null) { Debug.LogError("moback file is null"); yield break; } // Prevent multiple click while uploading. uploadFileButton.enabled = false; // Run the request. MoBackRequest uploadFileRequest = mobackFile.UploadFile(); yield return(uploadFileRequest.Run()); if (uploadFileRequest.State == MoBackRequest.RequestState.COMPLETED) { // We need to store the file's url (which is received after complete uploading the file) to a row, otherwise, we can't access it. MoBackRequest saveFileToTableRequest = mobackFile.Save(); yield return(saveFileToTableRequest.Run()); if (saveFileToTableRequest.State == MoBackRequest.RequestState.COMPLETED) { DisplayMessage("Finish save file to table"); } else if (saveFileToTableRequest.State == MoBackRequest.RequestState.ERROR) { Debug.LogError("Can't create a new MoBack object on server"); } } else if (uploadFileRequest.State == MoBackRequest.RequestState.ERROR) { Debug.LogError("can't upload file"); } uploadFileButton.enabled = true; }
/// <summary> /// Creates the relation. /// </summary> /// <returns>The relation.</returns> private IEnumerator CreateRelation() { MoBackTableInterface childTable = new MoBackTableInterface(ChildRelationTableName); MoBackRequest saveOjbectsRequest = childTable.RequestB.SaveMultipleObjects(items.ToList()); yield return(saveOjbectsRequest.Run()); MoBackRequest createRelationRequest = playerRow.AddRelations(DemoRelationColumn, items.ToArray()); yield return(createRelationRequest.Run()); if (createRelationRequest.State != MoBackRequest.RequestState.COMPLETED) { Debug.LogError("Can't create relation. " + createRelationRequest.errorDetails.Message); yield break; } else { Display("Relation Created"); ChangeScene(relationScene); } }