This repository was archived by the owner on Dec 19, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 9
Back End connection
Olaf Szmidt edited this page Dec 21, 2017
·
1 revision
If you want to test the connection with the back-end, the steps are the following:
- Go to the main scene, which can be found in
Assets/Scenes/Main.unity
. - Make sure that there is a game object called World Controller with the
WorldControls.cs
script attached and aSocketIOController
prefab as a child. It also has another child, something calledVIC
. It stands for Very Important Cube. On the early stages of the development, the scene would not render without an object on it, that's why we added an invisible cube. Do not remove it. - Click on the
SocketIOController
and in the inspector you'll be able to see the host and port variables. - Run the main aimmo game (only working on the unity branch), open it in a browser and 'Save' the game or level you want to visualise in Unity. A more detailed explanation on how to run it can be found on the repository's README.
- Find out which port the game is running in and put that value in the
SocketIOController
. - Click the play button on Unity, and you should be seeing a map with an avatar moving in it.
As explained above, the game object World Controller should have the WorldControls
component attached to it and there should be the appropriate prefab in the SocketIOController
field.
Regarding the code, we will discuss how it works when it's built to WebGL since locally it works in a simpler way for the sake of testing. The steps are the following:
-
Start: The map feature managers and the player manager are initialised. So is the
dataQueue
. There is an external call, namedSendAllConnect
, which will call a method in the Javascript that contains the Unity view. When this method is called it means that Unity has loaded the scene and can safely set the host and the port. (See the unity.html on the unity branch). -
EstablishConnection: This is the last call made from the Javascript which will set up the socket connection. When the back-end is also connected, it will emit a
world-init
event to which the Unity client will respond withclient-ready
and its user id. After that, it will only be listening to theworld-update
event. -
WorldUpdate: Every time the server sends an update, this method will put the JSON in the
dataQueue
. -
Update: This is the Unity
MonoBehaviour
update function, which will dequeue an update everyProcessingInterval
seconds and delegate it toProcessUpdate
which will finally change the view in the scene through the managers.