Skip to main content
Version: SDK-5.11.4

Full Code

BackendGuild.cs

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

// Adds BACKND SDK namespace
using BackEnd;

public class BackendGuild {
private static BackendGuild _instance = null;

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

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 = Backend.Guild.CreateGuildV3(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 = Backend.Guild.GetGuildIndateByGuildNameV3(guildName);

if(bro.IsSuccess() == false) {
Debug.LogError($"An error occurred while searching {guildName}. : " + bro);
return;
}

string guildInDate = bro.GetFlattenJSON()["guildInDate"].ToString();

bro = Backend.Guild.ApplyGuildV3(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 AcceptGuildJoinRequest(int index) {
var bro = Backend.Guild.GetApplicantsV3();

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(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 = Backend.Guild.ApproveApplicantV3(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 = Backend.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);
}
}

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(() => {

// #Step 1
BackendLogin.Instance.CustomLogin("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.

BackendGuild.Instance.CreateGuild("Desired_guild_name"); // Method for creating guilds

// #Step 2
BackendLogin.Instance.CustomSignUp("guildUser", "1234"); // New sign-up of user for the guild
BackendLogin.Instance.UpdateNickname("guildUser"); // Nickname registration of user for the guild

// The guild name entered in CreateGuild during Step 1 should be entered as the parameter value.
BackendGuild.Instance.RequestGuildJoin("Desired_guild_name");

// #Step 3
BackendLogin.Instance.CustomLogin("user1", "1234");
BackendGuild.Instance.AcceptGuildJoinRequest(0); // From users who sent join requests, accepts the one who sent the most recent request.

// #Step 4
BackendGuild.Instance.ContributeGoods(); // Guild goods contribution(addition) method

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