Audio Controls for Unity

Configuring Background Music for the SDK

If you have music you’d like to play in the background for users when they are interacting with the SDK, you can use the Skillz Audio API to configure this.

Step 1: Ensure your music file is in the correct location

The file which contains the background music you’d like to play must be located in this directory:

“Assets/StreamingAssets”

Screen_Shot_2019-03-07_at_1.20.17_PM.png

The directory must be called “StreamingAssets”, with matching case. This is so that the Unity export will pass that file to the correct location in the respective native project structure.

Step 2: Call the API method to set the music source

Use setSkillzBackgroundMusic to set the background music that will play in the Skillz SDK.  This file name must match exactly with the file’s name in Step 1.

SkillzCrossplatform.setSkillzBackgroundMusic("music.mp3");
SkillzCrossplatform.LaunchSkillz(SkillzGameController());

This can be called anywhere after the app launches, but it is recommended to call this before launching the Skillz SDK.

Syncing Your In-Game Volume with the Skillz SDK Audio

Note: On Android the functions in this section can only be used in-game after Skillz has launched.

Users can set volume settings from within the SDK via Accounts -> Audio Settings.

unnamed.png

Each volume is represented as a range between 0 and 1, with 0 being muted and 1 being full volume.

If you would like your in-game volume to match with the values set by the user in the SDK (and vice-versa), use these instructions to synchronize the settings.

Step 1: Synchronizing your In-game audio with the Skillz SDK

For your game’s music, use getSkillzMusicVolume when initially setting the music volume for your game to ensure that value matches the value set inside of the SDK.  In our example, we have a menu with a volume slider to control the in-game music volume, and to initialize its value we call the API like so:

SkillzCrossPlatform.getSkillzMusicVolume();

For your game’s music, use getSFXVolume when initially setting the music volume for your game to ensure that value matches the value set inside of the SDK.  In our example, we have a menu with a volume slider to control the in-game music volume, and to initialize its value we call the API like so:

SkillzCrossPlatform.getSFXVolume();

Our end result when initializing the settings inside of a test app is similar to that pictured below. If a user adjusts their volume sliders in the Skillz menu, that change will reflect in these in-app sliders:

unity_audio.jpg

Step 2: Synchronizing the Skillz SDK with your in-game audio

If you utilize an in-game menu which allows the user to change their volume settings, use these methods to ensure the Skillz SDK will obey these settings.  

When a user changes your game’s music volume, use setSkillzMusicVolume to synchronize that value with the SDK.  Ensure the value is a float between 0 and 1. (Note: Please make sure to sanitize your values; the API can take in values outside of the 0-1 range but this will cause problems). Using the example from Step 1 above, our code would look like this:

SkillzCrossPlatform.setSkillzMusicVolume(volume);

When a user changes your game’s sound effects volume, use setSFXVolume to synchronize with the SDK.  Ensure the value is a float between 0 and 1. (Note: Please make sure to sanitize your values; the API can take in values outside of the 0-1 range but this will cause problems). Using the example from Step 1 above, our code would look like this:

SkillzCrossPlatform.setSFXVolume(volume);