Create a Snippet Template
Introduction
As a developer, you can create your own Snippet template that will define how the Snippets of the Snippets Set you created online are displayed in your Unity project. This is a very flexible system that allows you, the developer, to customize how you want your Snippets to be shown to the user.
For every Snippet that you will generate, the system will create a prefab variant of a template prefab. You can find a sample template prefab to start from in the folder Packages/com.snippets.sdk/Editor/SnippetsTemplates/SnippetTemplate.prefab
. You have to copy this prefab and paste it into your Asset folder so that you can modify it according to your needs.
This is the structure of the base prefab:
-
The child TextPlayer, which contains the script
SnippetTmpTextPlayer
, is responsible for showing the text of the Snippet. This is particularly important for accessibility purposes, as it allows the Snippet to be read by screen readers. The script has a parameter, Disable Text When Not Playing that allows you to show the text only when the character is speaking, and hide it otherwise. Its child, TextLabel, has aTextMeshPro
component that you can modify to change the text style as you want. Notice that if you want, you can also change the whole logic of the text management, by not using theSnippetTmpTextPlayer
script, but using your own script that inherits from the base classSnippetTextPlayer
and that manages the text display. -
The child AudioPlayer, which contains the script
SnippetAudioSourceSoundPlayer
, is responsible for playing the audio of the Snippet. The script plays the audio through the Unity Audio System, and it is associated to anAudioSource
contained in the child AudioSource. Also in this case, you can change the audio settings of theAudioSource
as you want. Notice that you can also change the whole logic of the audio management, by not using theSnippetAudioSourceSoundPlayer
script, but using your own script that inherits from the base classSnippetSoundPlayer
and that manages the audio playback. -
The child AvatarPlayer, which contains the script
SnippetAvatarAnimatorPlayer
, is responsible for showing the avatar of the Snippet and playing its animations. In the default template there is a child of this element that has the very telling name Substitute-this-with-your-avatar. You can choose to do two things with this child: you can do nothing, and in that case, the system will try to take the avatar from the data saved on the server; or you can substitute this gameobject with an avatar featuring a skinned mesh render and a bone structure compatible with the avatar you selected online. What happens is that in the first case, the generated Snippets will have the avatar you selected online, while in the second case you will have the avatar that you put as a child of this gameobject. Notice that if you want, you can also change the whole logic of the avatar management, by not using theSnippetAvatarAnimatorPlayer
script, but using your own script that inherits from the base classSnippetAvatarPlayer
and that manages the avatar animation display. -
The main root object SnippetTemplate has the script
SnippetPlayer
that is responsible for the coordination of all the children gameobjects. It ensures that the avatar animation is playing together with the audio file and the text writing. You should assign to the field Snippet Text Player, Snippet Sound Player, and Snippet Avatar Player the corresponding children of the prefab. You can also not assign some of them if you don't want that playback feature to be used: for instance, if you leave the Snippet Sound Player to null, the avatar will show the animation and the text, but have no sound. This allows for full flexibility of visualization. There is an additional parameter, Play On Enable, that allows you to choose if the Snippet should start playing as soon as it is instantiated, or if it should wait for a manual call to thePlay()
method to start playing. This is useful if you want to instantiate the Snippet prefab and then play it later, for instance when the user clicks on a button.
If you are in doubt about how to create your own Snippet template, you can start by using the default one.