Getting started
In order to integrate your Unity game with the GameSwift gaming ecosystem, import our package to your project by providing the git URL.
After successful import, fill ClientAuthenticationSecret
field in Assets/Resources/GameSwiftSDK/GameSwiftConfig.asset
. It is a mandatory api authentication token, which is unique for every game using the SDK. These secrets are distributed by GameSwift.
You can handle GameSwift login in 2 ways: with launcher or without launcher. You can download GameSwift launcher here. As long as your game targets Windows or MacOS, we strongly recommend to use data passed from our launcher. By doing so, you won't need to implement any login screen for your game as launcher already handles user credentials in a secure way. If you are building for mobile or web, you will need to create a login screen and implement connection with GameSwift backend manually.
Logging in from Launcher
This section will help you integrate your game with GameSwift Launcher. This is a highly preferable and easier way of integrating with GameSwift ID as long as you build for PC or macOS. If you build for other platforms or prefer to do it manually (providing user email and password), please refer to the option below.
Create a login class, which will be launched on application startup.
Call a method
GameSwiftSdkId.ReadUserInfoFromLauncher
in order to retrieveAccessToken
from launcher's command-line arguments and store it in the SDK'sGameSwiftSdkId.Instance.CmdAccessToken
field used later in the authorization step.Create success and fail handlers for this method.
In the success handler call
GameSwiftSdkId.Authorize
method, which will perform all of the next steps for you automatically. Remember to use storedGameSwiftSdkId.Instance.CmdAccessToken
here. Also, provide yourclientId
andredirectUri
. If the process is finished successfully you will be authorized and a newAccessToken
will be stored in the SDK'sGameSwiftSdkId.Instance.AccessToken
field. From now on you should be using this token in each request.
Though we highly recommend using the above method, if you want to implement some specific for you project login use cases, you can execute authorization methods separately. Keep in mind though, that by doing this you will need to store AccessToken
in your project by yourself as the last step. In order to authorize this way, instead of instructions described in the point 4, in the GameSwiftSdkId.ReadUserInfoFromLauncher
success handler call these methods in sequence, one by one in their respective success handlers:
GameSwiftSdkId.GetAuthorizationCode
- use storedGameSwiftSdkId.Instance.CmdAccessToken
here and provide yourclientId
andredirectUri
.GameSwiftSdkId.RetrieveOauthToken
- provideauthorizationCode
retrieved from the previous method's response (AuthorizeResponse
) and provide yourclientId
andredirectUri
again. This will generate anAccessToken
returned in the request's response (TokenResponse
).GameSwiftSdkId.GetOauthUserInformation
- use your newly generatedAccessToken
here to get your user's information and on success store it somewhere in your project. From now on you should be using this token in each request.
Logging in without Launcher
This section will help you integrate your game with GameSwift ID without launcher integration. This process requires a few extra SDK calls.
Create a login class, which will be attached to a login screen.
On a login event call a method
GameSwiftSdkId.LoginAndAuthorize
where you need to pass user'semailOrNickname
,password
, yourclientId
andredirectUri
values.Create success and fail handlers for this method.
If the process is finished successfully you will be logged in, authorized and a new
AccessToken
will be stored in the SDK'sGameSwiftSdkId.Instance.AccessToken
field. From now on you should be using this token in each request.
Though we highly recommend using the above method, if you want to implement some specific for you project login use cases, you can execute separate login and authorization methods. In order to achieve this, instead of calling a GameSwiftSdkId.LoginAndAuthorize
method call these methods in sequence, one by one in their respective success handlers:
GameSwiftSdkId.Login
- provide user'semailOrNickname
andpassword
.GameSwiftSdkId.GetAuthorizationCode
- use theAccessToken
retrieved fromGameSwiftSdkId.Login
method's response (LoginResponse
) here. Also, provide yourclientId
andredirectUri
.GameSwiftSdkId.RetrieveOauthToken
- provideauthorizationCode
retrieved from the previous method's response (AuthorizeResponse
) and provide yourclientId
andredirectUri
again. This will generate anAccessToken
returned in the request's response (TokenResponse
).GameSwiftSdkId.GetOauthUserInformation
- use your newly generatedAccessToken
here to get your user's information and on success store it somewhere in your project. From now on you should be using this token in each request.
Multiple Logins Blocker
You need to have your client set up to block multiple login attempts for this component to work. To configure Multiple Logins Blocker
you need to edit MultipleLoginsBlockerData.asset
scriptable object which should be automatically created on Unity asset refresh in the Assets/Resources/GameSwiftSDK/
directory. When SDK instance in created this component will start working automatically in the background (if is turned on in the config file). Every specified number of seconds it will be sending hearbeats do the server to keep the lock. If you don't use our recommended login approaches, remember to call GameSwiftSdkId.GetOauthUserInformation
method as the last step of login process. This will be your first sent heartbeat and will initialize the process.
Hello Hero
Hello Hero is our sample application that shows how your game can be properly integrated with our SDK. In the aplication we can test requests to the GameSwift ID
and we can see some basic results in the panel Output
. Feel free to experiment with it!
Last updated