Implementing Game Information Modification
1. Write a method for modifying game information
Add content to the LevelUp and GameDataUpdate methods in BackendGameData.cs written in Pre-arrangements.
BackendGameData.cs
Before modification
public void LevelUp()
{
// Step 4. Implementing Game Information Modification
}
public void GameDataUpdate()
{
// Step 4. Implementing Game Information Modification
}
After modification
public void LevelUp()
{
Debug.Log("Increases the level by 1.");
userData.level += 1;
userData.atk += 3.5f;
userData.info = "Changes details.";
}
// Modify 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("Requesting my latest game information data to be modified.");
bro = Backend.GameData.Update("USER_DATA", new Where(), param);
}
else
{
Debug.Log($"Requesting the game information data of {gameDataRowInDate} to be modified.");
bro = Backend.GameData.UpdateV2("USER_DATA", gameDataRowInDate, Backend.UserInDate, param);
}
if (bro.IsSuccess())
{
Debug.Log("Successfully modified game information data. : " + bro);
}
else
{
Debug.LogError("Failed to modify 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 modification (After Step 3. Implementing Game Information Loading)
void Test()
{
BackendLogin.Instance.CustomLogin("user1", "1234"); // Log in to BACKND
BackendGameData.Instance.GameDataGet(); //[Addition] Data loading method
Debug.Log("Test complete.");
}
After modification
void Test()
{
BackendLogin.Instance.CustomLogin("user1", "1234"); // Log in to BACKND
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] Change locally saved data
BackendGameData.Instance.GameDataUpdate(); // [Addition] Overwrite 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.