Sample of Account(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
Project details
Open the project and you will see the above.
When I run it, at first it shows “Not Logged-in”.
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
Notice the hierarchy of the scene. The Game Object with the GS2 logo is assigned a UI Kit component.
Canvas/View
You can see that two components are allocated.
Gs2AccountLoggedInEnabler.
In the Add Component menu, you can add the following paths.
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
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.
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
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.
A prefab that executes such an API can be added from the context menu.
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.