Unity prefab for the Genvid SDK

Warning

This feature is currently in beta. The prefab is fully functional, but we expect to make some changes in the future to improve the user experience. Your feedback on this process is welcome.

For an even easier integration of the Genvid SDK into Unity, we created a prefab to easily integrate the SDK into your project.

This section covers documentation related to the use of the prefab with a description for each files available and a step by step description on how to use these properly.

Note that the prefab only works if you have the files needed indicated in the Unity sample project: Genvid.dll, GenvidPlugin.dll and GenvidSDKCSharp.dll. If you need more information about these files, please go to the section Genvid Unity Package.

  1. Files included in the prefab
  2. Genvid Session Manager - Initialization
  3. Genvid Session - Session management
  4. Genvid Video - How to handle the video stream
  5. Genvid Audio - How to handle the audio stream
  6. Genvid Streams - How to handle the data streams
  7. Genvid Events - How to handle the events
  8. Genvid Commands - How to handle the commands
Genvid prefab tree

Files included in the prefab

All the files included in the prefab are below. You can use the game object to drag and drop on your scene or directly use the script if you prefer. Note that for the sake of simplicity, only the prefab files are listed, but the script file attached to each prefab is available in Genvid/Scripts.

Genvid/Prefabs/Genvid/GenvidSessionManager.prefab
This object manages the associated GenvidSession.
Genvid/Prefabs/Genvid/GenvidSession.prefab
This object manages the associated audio stream, video stream, data streams, events, and commands.
Genvid/Prefabs/Genvid/Video.prefab
This object manages a video stream.
Genvid/Prefabs/Genvid/Audio.prefab
This object manages an audio stream.
Genvid/Prefabs/Genvid/Streams.prefab
This object manages a data stream.
Genvid/Prefabs/Genvid/Events.prefab
This object manages events.
Genvid/Prefabs/Genvid/Commands.prefab
This object manages commands.

Genvid Session Manager - Initialization

The initialization object of the prefab. You need to place this object in the scene with Activate SDK selected to have the Genvid SDK activated when starting the game. This object contains various properties that can be activated depending on your needs:

Activate SDK
This allows you to quickly activate/deactivate the Genvid SDK. Any prefab object on the scene will find the Genvid Session Manager and verify that it is active.
Auto Initialize
When checked, this option performs the initialize process for the Genvid SDK when starting the application (Awake). This needs to be done once in your application if you want to activate the Genvid SDK.
Session
The GenvidSession object used in the project needs to be added here to be able to activate properly.
Activate Debug Log
When checked, this option will display logs about the Genvid SDK for any successful operation done by the prefab.
Genvid Session Manager inspector view

Genvid Session - Session management

The session manager of the prefab. You need to place this object in the scene and add it into the Genvid Session Manager object public-property that has the Activate SDK selected. This object contains properties you that can be activated depending on your needs:

Video Stream
The GenvidVideo object used in the session needs to be added here to be able to activate properly.
Audio Stream
The GenvidAudio object used in the session needs to be added here to be able to activate properly.
Streams
The GenvidStreams object used in the session needs to be added here to be able to activate properly.
Events
The GenvidEvents object used in the session needs to be added here to be able to activate properly.
Commands
The GenvidCommands object used in the session needs to be added here to be able to activate properly.
Genvid Session inspector view

Genvid Video - How to handle the video stream

This GenvidVideo prefab object is needed to be able to stream the video from your game. Only one GenvidVideo object is accepted per GenvidSession. This object contains various properties you must set to perform the capture in the way you prefer:

Stream Name
The name of the video stream. Make sure to use a unique name compared to the other streams used in your application.
Capture Type

The type of video capture to use. Options in the selectable list are: Automatic, and Texture. Change from one Capture Type to another during runtime is not supported currently.

  • Automatic performs a video capture using the dxswapchain.
  • Texture performs a video capture via the texture or camera indicated in the Video Source property.
Video Source

This property is a private game object that will be used for the Texture video capture type. In the event you would need to modify in runtime for another camera or texture, you can use a command similar to this to perform this task:

GenvidSessionManager.Instance.Session.VideoStream.VideoSource = newVideoSource;
Genvid Video inspector view

Genvid Audio - How to handle the audio stream

This GenvidAudio prefab object is needed to be able to stream the audio from your game. Only one GenvidAudio object is accepted per GenvidSession. This object contains various properties you must set to perform the capture in the way you prefer:

Stream Name
The name of the audio stream. Make sure to use a unique name compared to the other streams used in your application.
Audio Format

The audio format to use for your capture. Options in the selectable list are: Unknown, S16LE, and F32LE. The Audio Format property is only used when using the Audio Mode Unity.

  • Unknown is not a supported type.
  • S16LE is for 16-bit audio.
  • F32LE is for 32-bit audio.
Audio Mode

Whether to perform audio capture and how. Options in the selectable list are: None, WASAPI, and Unity.

  • None doesn’t perform any audio capture, which can be useful for testing.
  • WASAPI captures audio from the machine running your application.
  • Unity captures audio using the AudioListener in the scene. This is the recommended mode
    for a Unity application with the Genvid SDK.
Genvid Audio inspector view

Genvid Streams - How to handle the data streams

This GenvidStreams prefab object is needed to be able to stream data from your game. You can have multiple data streams for the same GenvidStreams object. You need to modify the size of the Ids to have the number of data stream required for your application. Each element of this array contains several properties that can be modified:

Id
The name of the data stream. Make sure to use a unique name compared to the other streams used in your application.
Framerate

The rate at which the On Submit Stream function will be executed. 0 is the default value:

  • 0 means that the stream data is sent every frame (depending directly on the game framerate).
  • All other values use this formula: Min(value, Game Framerate).

For example, in a game running at 30 FPS:

  • At value 10, the stream is sent at Min(10, 30) = 10 Frames per second.
  • At value 100, the stream is sent at Min(100, 30) = 30 Frames per second.
On Submit Stream (String)

This is the function that will be executed according to the framerate selected. The String parameter received will always be the stream name. Afterwards, in the methods called, you are free to use which method is better to send your data:

  • SubmitAnnotation(object streamID, object data)
  • SubmitGameData(object streamID, object data)
  • SubmitNotification(object streamID, object data)

Each method needs the stream name that will receive the data and the data formatted into a class. Here’s an example on how we performed the submit data for the sample:

    public void SubmitGameData(string streamId)
    {
        ProjView = m_sceneCamera[m_currentActiveCamera].projectionMatrix * m_sceneCamera[m_currentActiveCamera].worldToCameraMatrix;

        if (GenvidSessionManager.Instance.ActivateSDK)
        {
            //Getting the cube information and send it into the game data stream
            var cubeDataArray = from c in m_Cubes select c.InfoData;
            CubesGameData gameData = new CubesGameData()
            {
                cubes = cubeDataArray.ToArray(),
                MatProjView = ProjView,
                camera = m_cameraCounter,
                scene = m_changeSceneCounter
            };

            GenvidSessionManager.Instance.Session.Streams.SubmitGameData(streamId, gameData);
        }
    }
Genvid Streams inspector view

Genvid Events - How to handle the events

You need the GenvidEvents prefab object to trigger your callback when an event occurs on the website. You can have multiple events for the same GenvidEvents object. You need to modify the size of the Ids to have the number of events required for your application. Each element of this array contains several properties that can be modified:

Id
The name of the event. Make sure to use a unique name compared to the other events used in your application.
On Event Triggered (String eventId, EventResult[] results, Int32 size, IntPtr data)

This is the function that executes when the event triggers from the website.

  • eventId is the eventId.
  • results is a list of the results from the event
  • size is the number of results available
  • data is a unique pointer related to the specific callback.

Here’s an example on how we performed the color change for the sample:

    public void OnEventChangeColor(string eventId, GenvidSDK.EventResult[] results, int numResult, IntPtr userData)
    {
        string cubeName = results[0].key.fields[0];
        var cube = m_Cubes.Find(o => o.name == cubeName);

        string cubeColor = results[0].key.fields[1];
        var color = m_NameToColors.Find(o => o.name == cubeColor);
        if (color != null && cube != null)
        {
            changeColorCube(cube, color);
        }
        else
        {
            Debug.LogError("Can't change cube" + cubeName + " with color: " + cubeColor);
        }
    }
Genvid Events inspector view

Genvid Commands - How to handle the commands

You need the GenvidCommands prefab object to trigger your callback when a command occurs on the website. You can have multiple commands for the same GenvidCommands object. You need to modify the size of the Ids to have the number of commands required for your application. You can modify several properties in each element of this array:

Id
This is the name of the command. Make sure to use a unique name compared to the other commands used in your application.
On Command Triggered (String commandId, String values, IntPtr data)

This function that executes when the command triggers from the website.

  • commandId is the id of the command.
  • values is the values send with the command.
  • data is a is a unique pointer related to the specific callback.

Here’s an example on how we performed the speed change for the sample:

    public void OnCommandDirection(string commandId, string value, IntPtr uniqueId)
    {
        char delimiter = ':';
        string[] substrings = value.Split(delimiter);
        var cube = m_Cubes.Find(o => o.name == substrings[0]);
        if (cube != null)
        {
            cube.ChangeDirection(int.Parse(substrings[1]), int.Parse(substrings[3]));
        }
    }
Genvid Commands inspector view