Connect to a cloud deployment
Before reading this document, make sure you are familiar with:
- Setting up Android Support for the GDK
- Ways to test your Android client
- Development authentication flow
- Creating workers with WorkerConnector
To connect your mobile application to a cloud deployment, you need to authenticate against our services. This guide describes how to authenticate using the development authentication flow which we provide for the early stages of game development. Altenatively, if you want to create your own authentication server, follow this guide.
Connecting your Android device or emulator to a cloud deployment
Start your Android Emulator in Android Studio or connect your Android device to your development computer.
If you start an emulator, ensure you choose the same CPU architecture for your virtual machine as your development computer. Using a different architecture might affect the performance of your emulator.
Upload your server-worker types. To do this, open a terminal window and from the root directory of your SpatialOS project, enter
spatial cloud upload <assembly name>.
In the same directory, start your cloud deployment using
spatial cloud launch --snapshot=snapshots/default.snapshot my_assembly <launch configuration>.json <deployment name>.
In the SpatialOS Console, tag your cloud deployment with the tag
To do this:
- From the SpatialOS Console, select your deployment name to display the project OVERVIEW screen.
- In the OVERVIEW screen, there’s a Tag field, add
dev_loginto the field.
Create a MonoBehaviour script which inherits from the
MobileWorkerConnectorand includes the functionality you want. In your Unity Editor, add this script it to your Android client-worker GameObject.
DevelopmentAuthTokenfield. Still in your Unity Editor, make sure your Android client-worker GameObject is selected and in the Inspector, locate the script you just added to it.
In the Inspector, in the script’s drop-down window, there is a field to add the authentication token that you created.
In the same drop-down window, ensure that the checkbox
ShouldConnectLocallyis not checked.
In the Unity Editor, navigate to SpatialOS > Build for cloud. Select your Android client-worker, and wait for the build to complete.
You know it’s complete when it says
Completed build for Cloud targetin your Unity Editor’s Console window.
Select SpatialOS > Launch mobile client > Android Device.
Play the game on your Android device or emulator.