Skip to main content
Version: 5.11.8

Implementing Game Information Loading

1. Write a game information loading method

Add content to the GameDataGet method in BackendGameData.cs written in Pre-arrangements.

BackendGameData.cs

Before editing

    public void GameDataGet() {
// Step 3. Implementing Game Information Loading
}

After editing

    public void GameDataGet() {
Debug.Log("Calls the game information lookup method.");
var bro = Backend.GameData.GetMyData("USER_DATA", new Where());
if(bro.IsSuccess()) {
Debug.Log("Game information lookup successful. : " + bro);


LitJson.JsonData gameDataJson = bro.FlattenRows(); // Receives data returned in JSON format.

// If the number of returned data cases is 0, the data does not exist.
if(gameDataJson.Count <= 0) {
Debug.LogWarning("The data does not exist.");
} else {
gameDataRowInDate = gameDataJson[0]["inDate"].ToString(); //This is the unique value of the loaded game information.

userData = new UserData();

userData.level = int.Parse(gameDataJson[0]["level"].ToString());
userData.atk = float.Parse(gameDataJson[0]["atk"].ToString());
userData.info = gameDataJson[0]["info"].ToString();

foreach(string itemKey in gameDataJson[0]["inventory"].Keys) {
userData.inventory.Add(itemKey, int.Parse(gameDataJson[0]["inventory"][itemKey].ToString()));
}

foreach(LitJson.JsonData equip in gameDataJson[0]["equipment"]) {
userData.equipment.Add(equip.ToString());
}

Debug.Log(userData.ToString());
}
} else {
Debug.LogError("Failed to look up game information. : " + 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(Step 2. Implementing Game Information Insertion)

    async void Test() {
await Task.Run(() => {
BackendLogin.Instance.CustomLogin("user1","1234"); // BACKND login

BackendGameData.Instance.GameDataInsert(); //[Addition] Data insertion method

Debug.Log("Test complete.");
});
}

After editing

    async void Test() {
await Task.Run(() => {
BackendLogin.Instance.CustomLogin("user1", "1234"); // BACKND login

BackendGameData.Instance.GameDataGet(); //[Addition] Data loading method

Debug.Log("Test complete.");
});
}

3. Test in Unity

After editing the script, execute Unity debugging and check the console log of Unity.
Check that the logs for each parsed data are being printed correctly.

The method has been successfully called when the log displays the item names properly.
When errors, such as statusCode : 400, 404, and 409, occur instead of the above log, you can check which error caused the failure in GetMyData error case.