UISoundPlayer Class |
Namespace: KSPDev.GUIUtils
The UISoundPlayer type exposes the following members.
Name | Description | |
---|---|---|
![]() | UISoundPlayer | Initializes a new instance of the UISoundPlayer class |
Name | Description | |
---|---|---|
![]() ![]() | CacheSound | Loads the sound into cache but doesn't play it. |
![]() ![]() | Play | Plays the specified sound. |
Use this player when the source of the sound is a GUI object (e.g. a GUI control). This class implements all the boilerplate to load and play the sound resources. All the sounds are cached within the scene, so repeating requests to the same sound won't add extra latency.
If latency is ciritcal for the caller, then the sound resource can be pre-cached via the CacheSound(String) method. It will increase the scene loading time, though.
This module is initialized from the KSPDev Utils loader.
public class UISoundPlayerDemo1 : PartModule { public override void OnAwake() { // To not loose the latency on the sound play pre-cache it. UISoundPlayer.instance.CacheSound("ooo.ogg"); } public override void OnUpdate() { if (Input.GetKeyDown("O")) { UISoundPlayer.instance.Play("ooo.ogg"); // Played from cache. No delay. } if (Input.GetKeyDown("P")) { UISoundPlayer.instance.Play("ppp.ogg"); // May delay the game while loading the resource. } } }