Loading Mail
1. Write the logic for the mail loading method
Add content to the PostListGet method in BackendPost.cs written in Pre-arrangements.
If the chart was created with a name other than 'Item Chart,' change the chartName in the PostListGet method to the name of the chart you set in the console.
BackendPost.cs
Before editing
public void PostListGet(PostType postType) {
// Step 3. Loading Mail
}
After editing
public void PostListGet(PostType postType) {
var bro = Backend.UPost.GetPostList(postType);
// If the chart was created with a name other than 'Item Chart,'
// set the corresponding value to the name of the chart set in the console.
string chartName = "Item Chart";
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(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(postType == PostType.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(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;
}
}
}
_postList.Add(post);
}
for(int i = 0; i < _postList.Count; i++) {
Debug.Log($"Mail No. {i}\n" + _postList[i].ToString());
}
}
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
async void Test() {
await Task.Run(() => {
BackendLogin.Instance.CustomLogin("user1", "1234"); // BACKND login method
// Adds mail logic
Debug.Log("Test complete.");
});
}
After editing
async void Test() {
await Task.Run(() => {
BackendLogin.Instance.CustomLogin("user1", "1234"); // BACKND login method
BackendPost.Instance.PostListGet(PostType.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 GetPostList 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 Chart' by default. If the title of the registered chart at the time of sending the mail is not 'Item Chart,' please change chartName in the code above to the name of the chart you set instead of 'Item Chart.'
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