Sample of Account(GS2 UIKit for Unity)

sample implementation of GS2-Account functionality using GS2 UIKit for Unity

Performs account creation and login process.

Repository

https://github.com/gs2io/gs2-uikit-for-unity-sample/tree/main/Account

GS2-Deploy template

https://github.com/gs2io/gs2-uikit-for-unity-sample/blob/main/Account/initialize_account_template.yaml

Project details

img.png

Open the project and you will see the above.

img_2.png

When I run it, at first it shows “Not Logged-in”.

img_1.png

After waiting for a while, the display will change to “Logged-in” and the user ID of the logged-in user will be shown in the lower right corner.

Project Description

img_3.png

Notice the hierarchy of the scene. The Game Object with the GS2 logo is assigned a UI Kit component.

Canvas/View

img_4.png

You can see that two components are allocated.

Gs2AccountLoggedInEnabler.

In the Add Component menu, you can add the following paths. img_5.png

This component can enable or disable GameObjects depending on the login status.

If you specify a GameObject as Target without checking Logged In, If you specify a GameObject in Target without checking Logged In, the GameObject specified in Target will be enabled when the user is not logged in, and disabled when the user is logged in.

Conversely, if the Logged In checkbox is checked, the GameObject specified as Target will be enabled when the user logs in. If “Logged In” is checked, the GameObject specified as Target will be enabled when logged in, and disabled when not logged in.

In this sample, “NotFoggedIn” is enabled when not logged in, and “LoggedIn” is enabled when logged in.

Canvas/View/LoggedIn

img_6.png

Again, you can see two components assigned.

Gs2AccountOwnAccountContext

Specifies the context to be used by the child elements of this GameObject. Gs2AccountOwnAccountContext specifies the context for the currently logged in GS2-Account account.

A ScriptableObject called “OwnAccount” is specified.

img_8.png img_7.png

If we check the ScriptableObject specified in OwnAccount, If you check the ScriptableObject specified in OwnAccount, you will see that a ScriptableObject representing your own account in the namespace named game-0001 is specified.

Gs2AccountOwnAccountFetcher.

Gets and holds information about the account specified in Gs2AccountOwnAccountContext.

Canvas/View/LoggedIn/UserId

img_9.png

Gs2AccountAccountLabel.

Outputs the account information obtained by Gs2AccountOwnAccountFetcher of the parent node in the format specified by Format.

In the sample, {userId} is specified, so it is replaced with your own user ID. A placeholder can be added to the Format by clicking the Add Format Parameter button.

The formatted string is passed to the OnUpdate(String) event. In this case, the value is reflected in the Text set to the same GameObject.

Process/Gs2AutoLogin

The prefab that executes the login process is set.

img_11.png

A prefab that executes such an API can be added from the context menu.

img_10.png

AutoLogin.

Specifies the namespace of the GS2-Account used to create and login to the account and the encryption key of the GS2-Key used for the login process.

OnAutoLogin sets the event handler to be called when login succeeds. By default, it disables its own GameObject so that the login process does not run multiply.

OnError sets the event handler to be called when login fails. Here, a function is called to output the contents of the error.