Full Code
BackndGuild.cs
using System;
using System.Collections.Generic;
using System.Text;
using UnityEngine;
// Adds BACKND SDK namespace
using BACKND;
public class BackndGuild {
private static BackndGuild _instance = null;
public static BackndGuild Instance {
get {
if(_instance == null) {
_instance = new BackndGuild();
}
return _instance;
}
}
public void CreateGuild(string guildName) {
// goodsCount entering as 10 is the number of goods types that can be used and cannot be modified later.
var bro = Backnd.Guild.CreateGuild(guildName, 10);
if(bro.IsSuccess() == false) {
Debug.LogError("An error occurred while creating the guild. : " + bro);
return;
}
Debug.Log("Guild created. : " + bro);
}
public void RequestGuildJoin(string guildName) {
var bro = Backnd.Guild.GetGuildInDateByGuildName(guildName);
if(bro.IsSuccess() == false) {
Debug.LogError($"An error occurred while searching {guildName}. : " + bro);
return;
}
string guildInDate = bro.GetFlattenJSON()["guildInDate"].ToString();
bro = Backnd.Guild.RequestGuildJoin(guildInDate);
if(bro.IsSuccess() == false) {
Debug.LogError($"An error occurred while sending a join request to {guildName}({guildInDate}). : " + bro);
return;
}
Debug.Log($"Successfully sent guild join request to {guildName}({guildInDate}). : " + bro);
}
public void ApproveGuildJoinRequest(int index) {
var bro = Backnd.Guild.GetGuildJoinRequestList();
if(bro.IsSuccess() == false) {
Debug.LogError("An error occurred while loading the list of users who requested to join the guild. : " + bro);
return;
}
Debug.Log("Successfully loaded the list of users who requested to join the guild. : " + bro);
if(bro.FlattenRows().Count <= 0) {
Debug.LogError("There are no users who requested to join. : " + bro);
return;
}
List<Tuple<string, string>> requestUserList = new List<Tuple<string, string>>();
foreach(BACKND.LitJson.JsonData requestJson in bro.FlattenRows()) {
requestUserList.Add(new Tuple<string, string>(requestJson["nickname"].ToString(), requestJson["inDate"].ToString()));
}
string userString = "Join request list\n";
for(int i = 0; i < requestUserList.Count; i++) {
userString += $"{index}. {requestUserList[i].Item1}({requestUserList[i].Item2})\n";
}
Debug.Log(userString);
bro = Backnd.Guild.ApproveGuildJoinRequest(requestUserList[index].Item2);
if(bro.IsSuccess() == false) {
Debug.LogError($"An error occurred while approving the join request of {requestUserList[index].Item1}({requestUserList[index].Item2}). : " + bro);
return;
}
Debug.Log($"Successfully accepted the join request of {requestUserList[index].Item1}({requestUserList[index].Item2}).: " + bro);
}
public void ContributeGoods() {
var bro = Backnd.Guild.ContributeGoodsV3(goodsType.goods1, 100);
if(bro.IsSuccess() == false) {
Debug.LogError("An error occurred during guild contribution. : " + bro);
}
Debug.Log("Successfully contributed goods to the guild. : " + bro);
}
}
BackndManager.cs
using UnityEngine;
using System.Threading.Tasks;
// Adds BACKND SDK namespace
using BACKND;
public class BackndManager : MonoBehaviour {
void Start() {
var bro = Backnd.Initialize(); // 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(() => {
// #Step 1
BackndLogin.Instance.CustomSignIn("user1", "1234"); // Logs in as user1
// When 412 error occurs while creating a guild, the creation of the guild is unavailable because the user already belongs to a guild.
// Create a new user with CustomSignUp("user3", "1234") to generate a guild.
BackndGuild.Instance.CreateGuild("Desired_guild_name"); // Method for creating guilds
// #Step 2
BackndLogin.Instance.CustomSignUp("guildUser", "1234"); // New sign-up of user for the guild
BackndLogin.Instance.ChangeDisplayName("guildUser"); // Nickname registration of user for the guild
// The guild name entered in CreateGuild during Step 1 should be entered as the parameter value.
BackndGuild.Instance.RequestGuildJoin("Desired_guild_name");
// #Step 3
BackndLogin.Instance.CustomSignIn("user1", "1234");
BackndGuild.Instance.ApproveGuildJoinRequest(0); // From users who sent join requests, accepts the one who sent the most recent request.
// #Step 4
BackndGuild.Instance.ContributeGoods(); // Guild goods contribution(addition) method
Debug.Log("Test complete.");
});
}
}