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 Files needed.
- Files included in the prefab
- Genvid Session Manager - Initialization
- Genvid Session - Session management
- Genvid Video - How to handle the video stream
- Genvid Audio - How to handle the audio stream
- Genvid Streams - How to handle the data streams
- Genvid Events - How to handle the events
- Genvid Commands - How to handle the commands
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 prefabsPackage/prefabsPackage/Scripts
.
This object is used to manage the GenvidSession associated to it.
prefabsPackage/Prefabs/Genvid/GenvidSessionManager.prefab
This object is used to manage the Audio stream, Video stream, Data streams, Events and Commands associated to it.
prefabsPackage/Prefabs/Genvid/GenvidSession.prefab
This object is used to manage a video stream.
prefabsPackage/Prefabs/Genvid/Video.prefab
This object is used to manage an audio stream.
prefabsPackage/Prefabs/Genvid/Audio.prefab
This object is used to manage a data stream.
prefabsPackage/Prefabs/Genvid/Streams.prefab
This object is used to manage events.
prefabsPackage/Prefabs/Genvid/Events.prefab
This object is used to manage commands.
prefabsPackage/Prefabs/Genvid/Commands.prefab
Genvid Session Manager - Initialization¶
The initialization object of the prefab. You will need to have this object
placed on the scene with the 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
TheGenvidSession
object used in the project needs to be added here to be able to activate properly.
Genvid Session - Session management¶
The session manager of the prefab. This object needs to be placed on the scene
and also added into the Genvid Session Manager
object public property that
has the Activate SDK
selected. This object contains various properties that
can be activated depending on your needs:
Video Stream
TheGenvidVideo
object used in the session needs to be added here to be able to activate properly.
Audio Stream
TheGenvidAudio
object used in the session needs to be added here to be able to activate properly.
Streams
TheGenvidStreams
object used in the session needs to be added here to be able to activate properly.
Events
TheGenvidEvents
object used in the session needs to be added here to be able to activate properly.
Commands
TheGenvidCommands
object used in the session needs to be added here to be able to activate properly.
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 that need to be 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
,Camera
, andTexture
.
Automatic
performs a video capture using thedxswapchain
.Camera
performs a video capture using the camera indicated in theVideo Source
property.Texture
performs a video capture via theTexture
indicated in theVideo Source
property.
Video Source
This property is a private game object that will be used for the
Camera
andTexture
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 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 that need to be 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
, andF32LE
. The Audio Format property is only used when using the Audio ModeUnity
.
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
, andUnity
.
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 theAudioListener
in the scene. This is the recommended mode- for a Unity application with the Genvid SDK.
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. When the framerate is set to 0, there is no limitation on sending the data and it will occur every frame.
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 Events - How to handle the events¶
This GenvidEvents
prefab object is needed 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, EventResult[], Int32, IntPtr)
This is the function that will be executed when the event is triggered from the website. The String parameter will be the eventId, the EventResult[] will be a list of the results from the event, the Int32 will be the number of results available and IntPtr 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) { changeColorCube(cube, color); } else { Debug.LogError("Can't change cube" + cubeName + " with color: " + cubeColor); } }
Genvid Commands - How to handle the commands¶
This GenvidCommands
prefab object is needed 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. Each element of this array
contains several properties that can be modified:
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, String, IntPtr)
This is the function that will be executed when the command is triggered from the website. The String parameter will be the commandId, the second String will be a list of the value of the command and the IntPtr 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])); } }