Skip to main content
Version: 6.0.0

Loading Mail

1. Write the logic for the mail loading method

Add content to the MailListGet method in BackndMail.cs written in Pre-arrangements.
If the chart was created with a name other than 'Item DataTable,' change the chartName in the MailListGet method to the name of the chart you set in the console.

BackndMail.cs

Before editing

    public void MailListGet(MailType mailType) {
// Step 3. Loading Mail
}

After editing

    public void MailListGet(MailType mailType) {
var bro = Backnd.Mail.GetMailList(mailType);

// If the chart was created with a name other than 'Item DataTable,'
// set the corresponding value to the name of the chart set in the console.
string chartName = "Item DataTable";

if(bro.IsSuccess() == false) {
Debug.LogError("An error occurred while loading the mail.");
return;
}

Debug.Log("Successfully requested mail list to be loaded. : " + bro);

if(bro.GetFlattenJSON()["postList"].Count <= 0) {
Debug.LogWarning("There is no mail to receive.");
return;
}

foreach(BACKND.LitJson.JsonData postListJson in bro.GetFlattenJSON()["postList"]) {
Post post = new Post();

post.title = postListJson["title"].ToString();
post.content = postListJson["content"].ToString();
post.inDate = postListJson["inDate"].ToString();

// Item in the mail
if(mailType == MailType.User) {
if(postListJson["itemLocation"]["tableName"].ToString() == "USER_DATA") {
if(postListJson["itemLocation"]["column"].ToString() == "inventory") {
foreach(string itemKey in postListJson["item"].Keys) post.postReward.Add(itemKey, int.Parse(postListJson["item"][itemKey].ToString()));
} else {
Debug.LogWarning("This column information is not supported yet. : " + postListJson["itemLocation"]["column"].ToString());
}
} else {
Debug.LogWarning("This table information is not supported yet. : " + postListJson["itemLocation"]["tableName"].ToString());
}
} else {
foreach(BACKND.LitJson.JsonData itemJson in postListJson["items"]) {
if(itemJson["chartName"].ToString() == chartName) {
string itemName = itemJson["item"]["itemName"].ToString();
int itemCount = int.Parse(itemJson["itemCount"].ToString());

if(post.postReward.ContainsKey(itemName)) {
post.postReward[itemName] += itemCount;
} else {
post.postReward.Add(itemName, itemCount);
}

post.isCanReceive = true;
} else {
Debug.LogWarning("This chart information is not supported yet. : " + itemJson["chartName"].ToString());
post.isCanReceive = false;
}
}
}
_mailList.Add(post);
}

for(int i = 0; i < _mailList.Count; i++) {
Debug.Log($"Mail No. {i}\n" + _mailList[i].ToString());
}
}

2. Add method call to BackndManager.cs

BackndManager, 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.

BackndManager.cs

Before editing

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

// Adds mail logic

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

After editing

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

BackndMail.Instance.MailListGet(MailType.Admin); // [Addition] Loads the mail list

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

3. Test in Unity

After editing the script, execute Unity debugging and check the console log of Unity.

The method has been successfully called when the log displays 'List of the mail sent from the console'.
When errors, such as statusCode : 400, 404, and 409, occur instead of the above log, you can check which errors caused the failure in GetMailList error case.

Error information

When the warning log, 'This chart information is not supported yet,' appears
The chart used in this code is called 'Item DataTable' by default. If the title of the registered chart at the time of sending the mail is not 'Item DataTable,' please change chartName in the code above to the name of the chart you set instead of 'Item DataTable.'

4. Use the console to check if the mail has been looked up

When the mail is looked up, the recipient field of the mail shows the user marked as Unclaimed.
When the user claims the mail, the date of the claim is recorded on Claimed Date.

Before looking up the mail

After looking up the mail