Thock

Thock.cs is a script responsible for handling key presses and playing sounds based on the key pressed. It supports both regular keys and special keys.

Input Handling

  • handleInput (bool): If true, key presses will be handled.

  • useSingleton (bool): Allows the use of a static instance of Thock.

Sound Pack

  • soundPack (SoundPack_SO): The SoundPack_SO object that contains the sound file and key mappings.

Fallback

  • specialCharactersTable (StringToKeycodeTable): A table containing mappings for special characters.

  • useFallbackSounds (bool): If true, fallback keys will be used when a key is pressed that is not in the namedKeys dictionary.

  • createRandomFallbackKeys (bool): If true, random fallback keys will be created if 0 fallback keys are set.

Audio Sources

  • audioSourceCount (int): The number of audio sources that will be created at runtime.

  • volume (float): The volume of the audio sources.

  • spatialAudio (bool): If true, the audio sources will play in relation to the keys position on the keyboard.

  • revertSpatialAudio (bool): If true, the audio pan will be inverted.

  • spatialAudioDistance (float): The distance the audio sources will pan from the center.

  • stereoAudioMapping (StereoAudioMapping): The stereo audio mapping that will be used for spatial audio.

  • audioMixerGroup (AudioMixerGroup): (Optional) The audio mixer group that the audio sources will be assigned to.

Events

  • onKey (UnityEvent): Event that is invoked when a key is pressed. The key is passed as a string.

Debug

  • debugLogs (bool): If true, debug messages will be printed to the console.

Public Methods

  • Type(KeyCode key) (void): Play sound based on key pressed.

  • Type(string key) (void): Play sound based on string.

  • TypeRandomKey() (void): Play random sound.

  • EnableInput() (void): Enable handling of key presses.

  • DisableInput() (void): Disable handling of key presses.

  • SetVolume(float vol) (void): Set the volume of the audio sources.

  • SetSoundPack(SoundPack_SO soundPack) (void): Set the sound pack dynamically.

Editor

  • GenerateNewSoundPack() (void): Generate a new sound pack asset.

Last updated