Unity Sample Integration

This release is compatible with all Unity-supported LTS versions.

Warning

Beta versions are not supported.

Integrating the Genvid MILE SDK into your Unity project is a simple process. We provide a Unity package containing the 3 DLLs required and the scripts and prefab for using it.

You can find the package under /engine-integration/unity/genvid_sdk.unitypackage.

In this section, we use our own sample to explain how to integrate the API into your project and how to use it. The Unity sample is similar to our D3D11 DirectX Sample Application and exposes the same functionalities.

How to Run the Sample

This guide assumes that your system is already properly configured to run the Genvid DirectX sample and that you can run the Genvid services. For information on running the services, see Start a Local Cluster.

To run the Unity sample:

  1. Install the package in the project.

    Follow the Unity asset documentation to import the package into the project.

  2. Build the project.

    Follow the Unity publishing documentation to build the project using the editor.

  3. Update the game executable name and path in the game templates (/templates/local/unity.nomad.tmpl and /templates/cloud/unity.nomad.tmpl). You can specify the absolute path of the executable, or set the GENVID_UNITY_PROJECT_DIR environment variable to your project path (the path containing the /app folder).

  4. For Cloud Deployment Only

    Package the build contents:

    genvid-sdk package app/build -d images -n unity_Cube
    
  5. Clean the cluster config and load the Unity sample.

    genvid-sdk setup # Create the local cluster.
    genvid-sdk clean-config # Remove any previously loaded sample configurations.
    genvid-sdk load-config-sdk # Configure the basic services for the SDK.
    genvid-sdk load-config config/game.hcl --with-consul-template --job-template-dir templates/local # Load the Unity demo job.
    genvid-sdk load-config config/sample.hcl # Load the encoding configuration.
    genvid-sdk load-config config/events.json # Load the event definitions.
    
  6. For Cloud Deployment Only

    • Specify the cluster when loading configurations -c {cluster-id}

    • Use the cloud template when uploading the game config.

    • Upload the content you previously compressed.

    genvid-sdk -c {cluster-id} upload-images unity_Cube -d images --update-config
    
  7. Load the sample website.

    The Genvid MILE SDK includes a sample website which lets you be a spectator of your own stream. See the Web Sample section for more information.

    To load the sample website, navigate to the folder samples/cube/web and run the following commands.

    py web.py build
    py web.py load
    

    For cloud deployment:

    py web.py build-cloud
    py web.py -c {cluster-id} upload-images --update-config
    py web.py -c {cluster-id} load
    
  8. Launch the game with all of the required Genvid services.

    genvid-sdk start
    

    For cloud deployment:

    genvid-sdk -c {cluster-id} start
    
  9. Use the command genvid-sdk open web to see the website.

    For cloud deployment:

    genvid-sdk -c {cluster-id} open web
    
  10. When you’re finished, stop the stack using the command genvid-sdk stop.

    For cloud deployment:

    genvid-sdk -c {cluster-id} stop
    

Game Script Files

You can find additional script files we use for the Unity sample in the Assets/Scripts folder of the project.

Game.cs

This file performs the camera and scene changes. It also performs the various interactions with the Genvid prefab and the scene.

MovementCube.cs

This file moves the objects in the scene. It also updates popularity and colors of each associated game object.

CubeColor.cs

This file formats the cube color and cube name in the same class.

CubeColorChanged.cs

This file formats the CubeColor into a List which is needed for JSON parsing.

CubePopularity.cs

This file formats the cube popularity and cube name in the same class.

CubeData.cs

This file formats the cube location, name, color, popularity, and leader selection in the same class.

Editor/Build.cs

This file builds the Unity sample project via the Python script in various configurations.