|
| 1 | +# What is GameSwift SDK? |
| 2 | +GameSwift SDK is a Unity toolset created to integrate with GameSwift ID ecosystem. Our SDK is multiplatform - you can build your game for PC, mobile and even browser! |
| 3 | +_Aside from GameSwift SDK, we are preparing GameSwift analytics_. |
| 4 | + |
1 | 5 | # Getting started
|
2 | 6 | In order to integrate your Unity game with GameSwift gaming ecosystem, [import](https://docs.unity3d.com/Manual/upm-ui-giturl.html) our package to your project by providing git url.
|
3 | 7 | ```
|
4 | 8 | https://github.com/GameSwift/gameswift-sdk.git
|
5 | 9 | ```
|
6 | 10 |
|
7 |
| -After succesful import, you can handle GameSwift login in 2 ways: with or without [GameSwift launcher](https://launcher.gameswift.io/). As long as your game targets Windows or MacOS, we strongly recommend to [use data passed from our launcher](#logging-in-from-launcher). By doing so, you don'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](#logging-in-without-launcher) with GameSwift backend manually. |
| 11 | +You can handle GameSwift login in 2 ways: [with launcher](#logging-in-from-launcher) or [without launcher](#logging-in-without-launcher). You can download GameSwift launcher [here](https://launcher.gameswift.io/). |
| 12 | +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. |
| 13 | +If you are building for mobile or web, you will need to create a login screen and implement connection with GameSwift backend manually. |
8 | 14 |
|
9 |
| -## Logging in from launcher |
10 |
| -1. Create script that launches at the very beggining of your game. |
11 |
| -2. Within this script, call `GameSwiftSdkId.GetUserInformationFromLauncher` if game is not run from the editor. |
12 |
| -3. Create success and failure handlers. `HandleSuccess` will be called if we succesful log in from launcher. `HandleFailure` will be called otherwise. |
| 15 | +### Logging in from launcher |
| 16 | +1. Create a login class, which will be launched on application startup. |
| 17 | +2. Call a method `GameSwiftSdkId.ReadUserInfoFromLauncher` in order to retrieve `AccessToken` from launcher's command-line arguments and store it in the SDK's `GameSwiftSdkId.Instance.CmdAccessToken` field used later in the authorization step. |
| 18 | +3. Create success and fail handlers for this method. |
| 19 | +4. In the success handler call `GameSwiftSdkId.Authorize` method, which will perform all of the next steps for you automatically. Remember to use stored `GameSwiftSdkId.Instance.CmdAccessToken` here. Also, provide your `clientId` and `redirectUri`. If the process is finished successfully you will be authorized and a new `AccessToken` will be stored in the SDK's `GameSwiftSdkId.Instance.AccessToken` field. From now on you should be using this token in each request. |
13 | 20 |
|
14 | 21 | ```cs
|
15 |
| -using GameSwiftSDK.Core; |
16 |
| -using GameSwiftSDK.Id; |
17 |
| -using GameSwiftSDK.Id.Responses; |
18 |
| -using UnityEngine; |
19 |
| - |
20 | 22 | public class GameSwiftLauncherLogin : MonoBehaviour
|
21 | 23 | {
|
22 |
| - [SerializeField] |
23 |
| - private RectTransform _waitScreen; |
24 |
| - |
25 | 24 | private void Awake()
|
26 | 25 | {
|
27 | 26 | if (Application.isEditor == false)
|
28 | 27 | {
|
29 |
| - GameSwiftSdkId.GetUserInformationFromLauncher(HandleSuccess, HandleFailure); |
| 28 | + GameSwiftSdkId.ReadUserInfoFromLauncher(HandleSuccess, HandleFailure); |
30 | 29 | }
|
31 | 30 | }
|
32 | 31 |
|
33 | 32 | private void HandleSuccess(OauthUserInfoResponse response)
|
34 | 33 | {
|
35 |
| - _waitScreen.gameObject.SetActive(false); |
| 34 | + GameSwiftSdkId.Authorize(GameSwiftSdkId.Instance.CmdAccessToken, |
| 35 | + CLIENT_ID, REDIRECT_URI, HandleAuthorizeSuccess, HandleFailure); |
36 | 36 | }
|
37 | 37 |
|
38 | 38 | private void HandleFailure(BaseSdkFailResponse response)
|
39 | 39 | {
|
40 |
| - Debug.LogError($"Log in error, code: {response.statusCode}, message: {response.Message}"); |
| 40 | + Debug.LogError($"Login error, code: {response.statusCode}, message: {response.Message}"); |
41 | 41 | Application.Quit();
|
42 | 42 | }
|
| 43 | + |
| 44 | + private void HandleAuthorizeSuccess(OauthUserInfoResponse response) |
| 45 | + { |
| 46 | + // your code on success login |
| 47 | + } |
43 | 48 | }
|
44 | 49 | ```
|
45 | 50 |
|
46 |
| -## Logging in without launcher |
47 |
| -1. Create script that launches at the very beggining of your game. |
48 |
| -2. Within this script, call `GameSwiftSdkId.Login`, passing read user credentials. |
49 |
| -3. Create success and failure handlers. `HandleSuccess` will be called if we succesful log in from launcher. `HandleFailure` will be called otherwise. |
| 51 | +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. |
| 52 | +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: |
50 | 53 |
|
51 |
| -```cs |
52 |
| -using GameSwiftSDK.Core; |
53 |
| -using GameSwiftSDK.Id; |
54 |
| -using GameSwiftSDK.Id.Responses; |
55 |
| -using UnityEngine; |
56 |
| -using UnityEngine.UI; |
| 54 | +- `GameSwiftSdkId.GetAuthorizationCode` - use stored `GameSwiftSdkId.Instance.CmdAccessToken` here and provide your `clientId` and `redirectUri`. |
| 55 | +- `GameSwiftSdkId.RetrieveOauthToken` - provide `authorizationCode` retrieved from the previous method's response (`AuthorizeResponse`) and provide your `clientId` and `redirectUri` again. This will generate an `AccessToken` returned in the request's response (`TokenResponse`). |
| 56 | +- `GameSwiftSdkId.GetOauthUserInformation` - use your newly generated `AccessToken` 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. |
| 57 | + |
| 58 | +### Logging in without launcher |
| 59 | +1. Create a login class, which will be attached to a login screen. |
| 60 | +2. On a login event call a method `GameSwiftSdkId.LoginAndAuthorize` where you need to pass user's `emailOrNickname`, `password`, your `clientId` and `redirectUri` values. |
| 61 | +3. Create success and fail handlers for this method. |
| 62 | +4. If the process is finished successfully you will be logged in, authorized and a new `AccessToken` will be stored in the SDK's `GameSwiftSdkId.Instance.AccessToken` field. From now on you should be using this token in each request. |
57 | 63 |
|
| 64 | +```cs |
58 | 65 | public class GameSwiftManualLogin : MonoBehaviour
|
59 | 66 | {
|
60 |
| - [SerializeField] |
61 |
| - private RectTransform _loginScreen; |
62 |
| - |
63 |
| - [SerializeField] |
64 |
| - private InputField _emailOrNickname; |
| 67 | + private const string CLIENT_ID = "yourClientId"; |
| 68 | + private const string REDIRECT_URI = "yourRedirectUri"; |
65 | 69 |
|
66 |
| - [SerializeField] |
67 |
| - private InputField _password; |
| 70 | + [SerializeField] private TMP_InputField emailOrNickname; |
| 71 | + [SerializeField] private TMP_InputField password; |
68 | 72 |
|
69 | 73 | private void Awake()
|
70 | 74 | {
|
71 |
| - GameSwiftSdkId.Login(_emailOrNickname.text, _password.text, HandleSuccess, HandleFailure); |
| 75 | + GameSwiftSdkId.LoginAndAuthorize(emailOrNickname.text, password.text, |
| 76 | + CLIENT_ID, REDIRECT_URI, HandleSuccess, HandleFailure); |
72 | 77 | }
|
73 | 78 |
|
74 |
| - private void HandleSuccess(LoginResponse response) |
| 79 | + private void HandleSuccess(LoginResponse response) |
75 | 80 | {
|
76 |
| - _loginScreen.gameObject.SetActive(false); |
| 81 | + // your code on success login |
77 | 82 | }
|
78 | 83 |
|
79 |
| - private void HandleFailure(BaseSdkFailResponse response) |
| 84 | + private void HandleFailure(BaseSdkFailResponse response) |
80 | 85 | {
|
81 |
| - Debug.LogError($"Log in error, code: {response.statusCode}, message: {response.Message}"); |
82 |
| - Application.Quit(); |
| 86 | + Debug.LogError($"Login error, code: {response.statusCode}, message: {response.Message}"); |
83 | 87 | }
|
84 | 88 | }
|
85 | 89 | ```
|
86 | 90 |
|
87 |
| -# Troubleshooting |
88 |
| -In case of any problems, feel free to contact us at [[email protected]](mailto:[email protected]). |
| 91 | +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: |
| 92 | +- `GameSwiftSdkId.Login` - provide user's `emailOrNickname` and `password`. |
| 93 | +- `GameSwiftSdkId.GetAuthorizationCode` - use the `AccessToken` retrieved from `GameSwiftSdkId.Login` method's response (`LoginResponse`) here. Also, provide your `clientId` and `redirectUri`. |
| 94 | +- `GameSwiftSdkId.RetrieveOauthToken` - provide `authorizationCode` retrieved from the previous method's response (`AuthorizeResponse`) and provide your `clientId` and `redirectUri` again. This will generate an `AccessToken` returned in the request's response (`TokenResponse`). |
| 95 | +- `GameSwiftSdkId.GetOauthUserInformation` - use your newly generated `AccessToken` 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. |
| 96 | + |
| 97 | +### Multiple Logins Blocker |
| 98 | +You need to have your client set up to block multiple login attempts for this component to work. |
| 99 | +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. |
| 100 | +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. |
| 101 | +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. |
| 102 | + |
| 103 | +# Hello Hero |
| 104 | +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! |
| 105 | + |
| 106 | + |
| 107 | + |
| 108 | +# Contact Us |
| 109 | + |
0 commit comments