Implementing Game Information Editing
1. Write a game information edit method
Add content to the LevelUp and GameDataUpdate methods in BackendGameData.cs written in Pre-arrangements.
BackendGameData.cs
Before editing
public void LevelUp() {
// Step 4. Implementing Game Information Editing
}
public void GameDataUpdate() {
// Step 4. Implementing Game Information Editing
}
After editing
public void LevelUp() {
Debug.Log("Increases the level by 1.");
userData.level += 1;
userData.atk += 3.5f;
userData.info = "Changes details.";
}
// Edit game information
public void GameDataUpdate() {
if(userData == null) {
Debug.LogError("Data downloaded from the server or newly inserted data does not exist. Use "Insert" or "Get" to create data.");
return;
}
Param param = new Param();
param.Add("level", userData.level);
param.Add("atk", userData.atk);
param.Add("info", userData.info);
param.Add("equipment", userData.equipment);
param.Add("inventory", userData.inventory);
BackendReturnObject bro = null;
if(string.IsNullOrEmpty(gameDataRowInDate)) {
Debug.Log("Requests my latest game information data to be edited.");
bro = Backend.GameData.Update("USER_DATA", new Where(), param);
} else {
Debug.Log($"Requests {gameDataRowInDate} to be edited.");
bro = Backend.GameData.UpdateV2("USER_DATA", gameDataRowInDate, Backend.UserInDate, param);
}
if(bro.IsSuccess()) {
Debug.Log("Successfully edited game information data. : " + bro);
} else {
Debug.LogError("Failed to edit game information data. : " + bro);
}
}
2. Add method call to BackendManager.cs
BackendManager, which is automatically called when the game is executed, must be used to call this method.
Add it so that the method may be called after BACKND initialization and BACKND login.
BackendManager.cs
Before editing(After Step 3. Game Information Loading)
async void Test() {
await Task.Run(() => {
BackendLogin.Instance.CustomLogin("user1", "1234"); // BACKND login
BackendGameData.Instance.GameDataGet(); //[Addition] Data loading method
Debug.Log("Test complete.");
});
}
After editing
async void Test() {
await Task.Run(() => {
BackendLogin.Instance.CustomLogin("user1", "1234"); // BACKND login
BackendGameData.Instance.GameDataGet(); // Data insertion method
// [Addition] When the loaded data from the server does not exist, new data is created and inserted
if(BackendGameData.userData == null) {
BackendGameData.Instance.GameDataInsert();
}
BackendGameData.Instance.LevelUp(); // [Addition] Locally saved data is changed
BackendGameData.Instance.GameDataUpdate(); //[Addition] Overwrites data saved in the server(only parts that have changed)
Debug.Log("Test complete.");
});
}
3. Test in Unity
After editing the script, execute Unity debugging and check the console log of Unity.
The process has been successfully completed when the log displays 'Requesting my latest game information data to be edited : statusCode : 204'.
When errors, such as statusCode : 400, 404, and 409, occur instead of the above log, you can check which error caused the failure in Update error case.
4. Check in the console
When a log on success appears on the Unity console, go to BACKND Console and check BACKND Base > Game Information Management > Data
to confirm that the row has been changed.
The value increases every time the method is called; therefore, it may differ from the value in the example below.