Prepare your project
Create your worker connector script
If you are using one of our Starter Projects, you can skip this section, as you already have one in your project.
If you added the GDK to an existing Unity project rather than using a Starter Project, then you need to create and add a MonoBehaviour script to your mobile client-worker GameObject. To do this:
- Create a MonoBehaviour script which inherits from the
WorkerConnector. This scripts contains support for both Android and iOS. You can base your implementation on the one in our Blank Starter Project.
- In your Unity Editor, add the MonoBehaviour script to your mobile client-worker GameObject.
Create your development authentication token
To connect to a cloud deployment using your mobile device, you need to use the development authentication flow which we provide for the early stages of game development. The GDK for Unity provides tooling around the development authentication flow to help you iterate faster on your mobile application.
- Open your project in your Unity Editor.
- Navigate to SpatialOS > GDK Tools configuration to open the configuration window.
In the Dev Auth Token Settings specify the lifetime of the token and the path to the Resources folder that you would like to store the generated token in.
Your token expires after the amount of days that you specified in the configuration window. Regenerate the token whenever that happens.
(for iOS) Ensure that Save token to file is checked.
Select Save and close the window.
Select SpatialOS > Dev Authentication Token > Generate Token. This stores the dev auth token inside the Unity Player Preferences. If Save token to file inside the configuration window is checked, it will also generate a
DevAuthToken.txtasset in the folder you specified in the configuration window. This token is used to authenticate when connecting to a cloud deployment.
If your worker connector inherits from the
DefaultMobileWorkerConnectorscript, it will automatically read the content inside
DevAuthToken.txtwhen running the application and authenticate against our services. See the section above to learn how to create a mobile worker connector.
If you want to create your own authentication server, follow this guide.