Skip to main content
Version: 5.11.4

Pre-arrangements

The following tasks must be completed in advance to implement login/sign-up functions.

  1. Insert BACKND initialization logic
  2. Create a script exclusive to login/sign-up in BACKND

1. Create BACKND initialization logic script

This example covers the logic after Step 9 of BACKND developer documentation - Getting Started.
Therefore, the initialization logic in Getting Started must be written to test this example properly.

The location of the file of BackendManager.cs does not affect the test.

BackendManager.cs script

Add a test method that will call synchronous methods from asynchronous methods following the initialization logic in Getting Started.

Before editing

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

// 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
}
}
}

After editing

using UnityEngine;
using System.Threading.Tasks; // [Change] This namespace is needed to use the async function.

// 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();
}

// =======================================================
// [Addition] 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(() => {
// Adds later test cases
Debug.Log("Test complete.");
});
}
}

2. Create a script exclusive to login

Create a new script and change the name to BackendLogin.

BackendLogin.cs

Then, open the BackendLogin.cs script and change the content according to the following:

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

// Adds BACKND SDK namespace
using BackEnd;

public class BackendLogin {
private static BackendLogin _instance = null;

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

return _instance;
}
}

public void CustomSignUp(string id, string pw) {
// Logic for Step 2. Implementing Sign-up
}

public void CustomLogin(string id, string pw) {
// Logic for Step 3. Implementing Login
}

public void UpdateNickname(string nickname) {
// Logic for Step 4. Implementing Nickname Change
}
}