Click or drag to resize

UISoundPlayerCacheSound Method

Loads the sound into cache but doesn't play it.

Namespace:  KSPDev.GUIUtils
Assembly:  KSPDev_Utils.2.0 (in KSPDev_Utils.2.0.dll) Version: 2.0 for KSP v1.8+
Syntax
C#
public void CacheSound(
	string audioPath
)
Request Example View Source

Parameters

audioPath
Type: SystemString
File path relative to GameData.
Remarks
Use this method when the sound is expected to be frequently played in the scene. However, it it only makes sense to pre-cache a resource if the first usage of the sound is a latency critical. The latency difference is not hight enough to be significant for the GUI actions.
Examples
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.
    }
  }
}
See Also