Skip to main content
Version: 5.15.0

Implementing Game Information Loading

Step 1. Write a method for loading game information

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

BackendGameData.cs

Before modification

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

After modification

public void GameDataGet()
{
Debug.Log("Call 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(); // Receive 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(); //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 modification (Step 2. Implementing Game Information Insertion)

void Test()
{
BackendLogin.Instance.CustomLogin("user1", "1234"); // Log in to BACKND

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

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

After modification

void Test()
{
BackendLogin.Instance.CustomLogin("user1", "1234"); // Log in to BACKND

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.