01 Running a model game - project-SIMPLE/simple.toolchain GitHub Wiki
In what follows, we assume that the user has a GAMA model adapted to VR and a Unity project with at least one scene containing the prefabs needed to connect to GAMA. See the tutorial for more information on designing this GAMA model and the Unity project.
The model can be launched in different ways: from a headset/directly from unity in play mode - with/without middleware. The middleware makes it possible to better manage the connections between GAMA and Unity and is mandatory in the context of a multi-player game. It is thus recommended to use it.
We will see in the following two ways to launch the game with the middleware: from Unity in play mode; from a VR headset. In all cases it will be necessary to run the middleware, connect GAMA to it, and launch the simulation from GAMA before, i.e. start the Unity experiment of the GAMA model.
The middleware can be downloaded here. All the information about the running of the middleware can be found in the middleware wiki.
To run the model/game from Unity, follow the following steps:
- Run the middleware
- If you're using Windows: run
start.bat
, located in the project root directory. - If you're using MacOS or Linux: run
start.sh
, located in the project root directory.
The middleware will open a new page (http://localhost:8000) on your default web browser. if this page does not appear, just reload the page.
You should then get this page:
2. Run GAMA
This step can be done before step 1. In this case, the middleware is connected directly to GAMA and you can proceed to step 4.
3. Connect GAMA to the middleware
On the middleware web page, click on "Try Connection". GAMA should after be connected (appearing in green).
4. Launch the experiment
In GAMA, runs the experiment integrating the connection with Unity. As an example, we will run the experiment "vr_xp" of the model provided with GAMA's Unity plugin: "Plugin models/LinkToUnity/Models/Code Examples/Send Static data.gaml"
On the middleware web page, you should be able to see the status of the experiment in orange ("simulation paused")
5. Push on the Unity Play button
Open the Scene that you want to run (it has to contain a Connection Manager and a Game manager). For example, in linked to the model "Send Static data.gaml" we will open in the "UnityVRTemplate" the Scene "Scenes/Code Examples/Receive Static Data". Then, clicks on the Play button.
6. Add the player
On the middleware web page, you should see the player trying to connect to the middleware in orange. Click the Add button to add it.
The middleware should turn green and you will see the geometry sent by GAMA in Unity.
Connecting a headset to GAMA is the same as running Unity with GAMA. The only difference is the need to set the correct IP and build and export the application on the headset.
Go to "Managers/Connection Manager" from the Scene and in the "Default IP" field, set the IP of the PC running GAMA (to replace "localhost"). Note that the headset and the PC must use the same WiFi network to work. Be sure as well that "Fixed Properties" is checked as it allows to use the IP defined in "Default IP".
In the File Menu, choose "Build Settings...".
In this panel, select "Android" then click on "Switch platform". In the "Scene in Build" panel, select the Scenes that you want to export on the headset. For example, the Scene "Scene/Code Examples/Receive Static Data". If the Scene is not available, open the scene in Unity, then click on "Add Open Scene" in the "Build Settings..." panel.
Then click on "Build and Run". You will need to select a file for the application. If your headset is not connected, a pop-up will appear. You will need to connect your headset and click on "Retry". To connect the headset, simply plug your headset to the computer using a USB-C cable and accept any authorization that appears. Note that the headset must be in "Developer Mode" to export the application to it.
Once the application is exported, it should start right on the headset if you have already set up a boundary. If you don't see the application running, just click on the "Meta" button on the right controller, quit the application, and run it again. To run the application, in the application panel of the headset, select applications from "Unknown source" and you should be able to find your application.