Unity Sample Integration

This release supports all Unity LTS versions from 2018 to 2020.3.

Warning

Beta versions are not supported.

Note

The Unity plugin is also compatible with Unity version 5.6.

Integrating the Genvid 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.

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. 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.
    py unity.py load # Load jobs and configuration for the Unity demo.
    
  2. Load the sample website.

    The Genvid SDK includes a sample website which allows you to 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
    
  3. Install the package in the project.

    py unity.py prepare
    

    Note

    You can now specify the engine version you want to use. If you wish to do so, the package, prepare and build steps will all need to be specified with the desired version.

    When you prepare the project, add the option -v or --version and the engine version-number at the end of the build command.

    For example, to prepare using Unity Engine Version 2019.3.6f1 use:

    py unity.py prepare -v 2019.3.6f1
    

    If your version of Unity cannot be found for some reason, you can manually set an environment variable for a specific version of Unity. To manually set it, declare the variable name in the format: UNITYENGINEDIR_{version}

    Example: UNITYENGINEDIR_2019.3.6f1

    Note

    The py unity.py prepare command unpacks the Genvid packages into the project. Unity 2020 versions try to compile the project scripts before all resources are extracted. Some of the project scripts under samples/cube/unity/app/Assets/Scripts reference functionality from the Genvid C sharp library, contained in the Genvid package. Therefore, the project scripts can’t be compiled right away. Unity then provides the following warning pop up.

    ../../../_images/Safe_Mode_Prompt.png

    Selecting either Enter Safe Mode or Ignore lets the py unity.py prepare command progress with the unpacking. Once the necessary resources are unpacked, the links get updated, and errors get resolved.

  4. Build the project and the website.

    py unity.py build
    

    This imports the genvid.unitypackage available under /engine-integration/unity and builds the Unity project available under samples/cube/unity/app.

    Note

    You can now specify the engine version you want to use. If you wish to do so, the package, prepare and build steps will all need to be specified with the desired version.

    When you build the project, add the option -v or --version and the engine version-number at the end of the build command.

    For example, to prepare using Unity Engine Version 2019.3.6f1 use:

    py unity.py build -v 2019.3.6f1
    

    If your version of Unity cannot be found for some reason, you can manually set an environment variable for a specific version of Unity. To manually set it, declare the variable name in the format: UNITYENGINEDIR_{version}

    Example: UNITYENGINEDIR_2019.3.6f1

    Other available options:

    • -b: Build in 32-bit.
    • -d: Build in debug.

    You can also do the import manually by starting the project and building it from the Genvid menu.

  5. Launch the game with all of the required Genvid services:

    genvid-sdk start
    

    Use the command genvid-sdk open web to see the website.

    If you want to stop the stack, use the command genvid-sdk 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.