Skip to main content
Version: 5.11.4

Pre-arrangements

The following tasks must be completed in advance to implement coupon functions.

  1. A chart for using the mail
  2. Logic of completed login method
  3. Logic of completed game information management method
  4. Create a script exclusive to the mail

1. A chart for using the mail

The information from a chart that allows you to use mail functions is required to implement the items provided after claiming the mail.
Go to BACKND Console, and in BACKND Base > Chart Management, change the Mail Use status to Enabled for the chart that holds the item to be provided as a coupon reward.
If there are no registered charts, first proceed with 4. Implementing Chart Functions Step 2. Registering Charts to the Console.

Click the Edit button on the right of the chart.

Set the Mail Use status to Enabled.

After the change, the mail function is displayed as Enabled.

2. Logic of completed login method

All BACKND functions except login and sign-up require a login process to successfully call their methods.
If the login logic has not been implemented, please fully implement it according to the guidelines in 1. Implementing Login/Sign-up.

3. Logic of completed game information management method

This example also shows the process leading up to the logic that saves items returned after claiming the mail.
Therefore, 2. Implementing Game Information Functions, which is used to save mail data, must first be implemented.
If the game information function logic has not been implemented, please fully implement it according to 2. Implementing Game Information Functions.

4. Create a script exclusive to the mail

Create a new script and change the name to BackendPost.
Then, open the BackendPost.cs script and change the content according to the following:

BackendPost.cs

using System.Collections.Generic;
using System.Text;
using UnityEngine;

// Adds BACKND SDK namespace
using BackEnd;

public class Post {
public bool isCanReceive = false;

public string title; // Mail title
public string content; // Mail content
public string inDate; // Mail inDate

// The string is the name of the mail item and the int is the count
public Dictionary<string, int> postReward = new Dictionary<string, int>();

public override string ToString() {
string result = string.Empty;
result += $"title : {title}\n";
result += $"content : {content}\n";
result += $"inDate : {inDate}\n";

if(isCanReceive) {
result += "Mail Item\n";

foreach(string itemKey in postReward.Keys) {
result += $"| {itemKey} : {postReward[itemKey]}ea\n";
}
}
else {
result += "Unsupported mail item.";
}

return result;
}
}

public class BackendPost {
private static BackendPost _instance = null;

public static BackendPost Instance {
get {
if(_instance == null) {
_instance = new BackendPost();
}

return _instance;
}
}

private List<Post> _postList = new List<Post>();

public void SavePostToLocal(LitJson.JsonData item) {
foreach(LitJson.JsonData itemJson in item) {
if(itemJson["item"].ContainsKey("itemType")) {
int itemId = int.Parse(itemJson["item"]["itemId"].ToString());
string itemType = itemJson["item"]["itemType"].ToString();
string itemName = itemJson["item"]["itemName"].ToString();
int itemCount = int.Parse(itemJson["itemCount"].ToString());

if(BackendGameData.userData.inventory.ContainsKey(itemName)) {
BackendGameData.userData.inventory[itemName] += itemCount;
}
else {
BackendGameData.userData.inventory.Add(itemName, itemCount);
}

Debug.Log($"Item received. : {itemName} - {itemCount}ea");
}
else {
Debug.LogError("Unsupported item.");
}
}
}

public void PostListGet(PostType postType) {
// Step 3. Loading Mail
}

public void PostReceive(PostType postType, int index) {
// Step 4. Claiming and Saving Individual Pieces of Mail
}

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

BackendManager.cs

using UnityEngine;
using System.Threading.Tasks;

// Adds BACKND SDK namespace
using BackEnd;

public class BackendManager : MonoBehaviour {
void Start() {
var bro = Backend.Initialize(true); // Initialize BACKND

// Response value for BACKND initialization
if(bro.IsSuccess()) {
Debug.Log("Initialization successful : " + bro); // If successful, 'statusCode 204 Success'
} else {
Debug.LogError("Initialization failed : " + bro); // If failed, a 4xx statusCode error occurs
}

Test();
}

// A method that allows synchronous methods to be called from asynchronous methods(cannot be accessed by the Unity UI)
async void Test() {
await Task.Run(() => {
BackendLogin.Instance.CustomLogin("user1", "1234"); // BACKND login method

// Adds mail logic

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