Skip to main content
Version: 5.11.4

Claiming and Saving All Mail

1. Send a new piece of mail

The piece of mail sent earlier in Step 2. Sending Mail From the Console cannot be loaded again because it was claimed in Step 4. Claiming and Saving Individual Pieces of Mail.

Therefore, you must proceed with Step 2. Sending Mail From the Console once more and create a new piece of mail to properly claim the piece of mail.

The piece of mail required for the test is the same as the one created in Step 2. Sending Mail From the Console.

2. Write the logic for the method of claiming and saving all mail

Add content to the PostReceive method in BackendPost.cs written in Pre-arrangements.
To call this method, the PostListGet method must be implemented in advance.

BackendPost.cs

Before editing

    public void PostReceiveAll(PostType postType) {
// Step 5. Claiming and Saving All Mail
}

After editing

    public void PostReceiveAll(PostType postType) {
if(_postList.Count <= 0) {
Debug.LogWarning("There is no mail to receive. Or, call the mail list loading first.");
return;
}

Debug.Log($"{postType.ToString()} Requesting all pieces of mail to be claimed.");

var bro = Backend.UPost.ReceivePostItemAll(postType);

if(bro.IsSuccess() == false) {
Debug.LogError($"{postType.ToString()} An error occurred while claiming all mail : " + bro);
return;
}

Debug.Log("Successfully claimed all mail. : " + bro);

_postList.Clear();

foreach(LitJson.JsonData postItemsJson in bro.GetFlattenJSON()["postItems"]) {
SavePostToLocal(postItemsJson);
}

BackendGameData.Instance.GameDataUpdate();
}

3. 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(After Step 4. Claiming and Saving Individual Pieces of Mail)

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

// Loads game data and saves it locally.(caching)
BackendGameData.Instance.GameDataGet();

// Loads the mail list and saves the inDate values locally.
BackendPost.Instance.PostListGet(PostType.Admin);

// Claims the mail by reading the position of the saved piece of mail. Here, the index is the order of the mail; 0 is the topmost and 1 is the next.
BackendPost.Instance.PostReceive(PostType.Admin,0);

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

After editing

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

// Loads game data and saves it locally.(caching)
BackendGameData.Instance.GameDataGet();

// Loads the mail list and saves the inDate values locally.
BackendPost.Instance.PostListGet(PostType.Admin);

// Claims all pieces of mail that have been looked up.
BackendPost.Instance.PostReceiveAll(PostType.Admin);

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

4. 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 'Successfully edited the item name and game information data attached to the mail. : statusCode : 204'.
When errors, such as statusCode : 400, 404, and 409, occur instead of the above log, you can check which errors caused the failure in ReceivePostItemAll error case.

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