InputManager class
Manages the collection of objects that perform processing on the device to expose user actions as inputs to the API.
Signature:
export declare class InputManager extends ExternalObject
Extends: ExternalObject
Remarks
Use Runtime.getInputManager() to get an instance of this class.
Properties
Property | Modifiers | Type | Description |
---|---|---|---|
AudioRoute |
| typeof AudioRoute | Describes the physical device being used to transfer audio signals |
HapticFeedback |
| typeof HapticFeedback | Kinds of haptic feedback available. These vibrations vary in intensity, duration, and can be preset patterns. |
Methods
Method | Modifiers | Description |
---|---|---|
createMicrophoneRecorder(options) | Creates and returns a MicrophoneRecorder instance that can be used to record audio from the device microphone. | |
getAccelerometerSubject() | Get a subject that will receive accelerometer updates every frame. | |
getAudioRoute() | Get the current audio route. | |
getAudioRouteUpdates() | Get a subject to listen for updates to the audio route, for instance if headphones are plugged in during game play. | |
getDeviceVolume() | Get the current playback volume of the device | |
getMicrophoneAudioNode(audioCtx) | Enable the device's microphone and get an AudioNode that can be used with the Web Audio Api to analyze audio captured by the microphone. | |
getSpeechToText(settings) | Get the speech to text object acting globally against the device mic input | |
playHapticFeedback(type) | Trigger haptic (vibration) feedback of various kinds. |
InputManager.AudioRoute property
Warning: This API is now obsolete.
Use AudioRoute
Describes the physical device being used to transfer audio signals
Signature:
static readonly AudioRoute: typeof AudioRoute;
InputManager.createMicrophoneRecorder() method
Creates and returns a MicrophoneRecorder instance that can be used to record audio from the device microphone.
Signature:
createMicrophoneRecorder(options?: MicrophoneRecorderOptions): Promise<MicrophoneRecorder>;
Parameters
Parameter | Type | Description |
---|---|---|
options | MicrophoneRecorderOptions | (Optional) The options for creating the microphone recorder. |
Returns:
Promise<MicrophoneRecorder>
A promise that resolves with the created MicrophoneRecorder instance.
Remarks
A new recorder instance is created every time this method is called. You can record using multiple recorders at the same time.
InputManager.getAccelerometerSubject() method
Get a subject that will receive accelerometer updates every frame.
Signature:
getAccelerometerSubject(): Subject<Vector3>;
Returns:
Remarks
The subject emits a Vector3 representing the vector of the measured acceleration in m/s^2.
This is interchangeable with DeviceMotionEvent.accelerationIncludingGravity
For example, a phone held in the ideal portrait mode would have the acceleration {x: 0, y: -9.8, z: 0}
.
InputManager.getAudioRoute() method
Get the current audio route.
Signature:
getAudioRoute(): Promise<Enum<typeof AudioRoute>>;
Returns:
Promise<Enum<typeof AudioRoute>>
InputManager.getAudioRouteUpdates() method
Get a subject to listen for updates to the audio route, for instance if headphones are plugged in during game play.
Signature:
getAudioRouteUpdates(): Subject<Enum<typeof AudioRoute>>;
Returns:
Subject<Enum<typeof AudioRoute>>
InputManager.getDeviceVolume() method
Get the current playback volume of the device
Signature:
getDeviceVolume(): Promise<number>;
Returns:
Promise<number>
A floating point value between 0 and 1, with 1 being full volume and 0 being no volume
InputManager.getMicrophoneAudioNode() method
Enable the device's microphone and get an AudioNode that can be used with the Web Audio Api to analyze audio captured by the microphone.
Signature:
getMicrophoneAudioNode(audioCtx: AudioContext): Promise<MicrophoneAudioNode>;
Parameters
Parameter | Type | Description |
---|---|---|
audioCtx | AudioContext | An AudioContext object that the returned AudioNode object will operate within |
Returns:
Promise<MicrophoneAudioNode>
Remarks
Be aware that Safari on iOS has limited support for many aspects of the javascript audio API, and when embedded within an application there are even more. Do not attempt to use this API to save audio recordings, use it for analysing data only. To record audio from the microphone and save it as an asset, use a MicrophoneRecorder which you can get by calling InputManager.createMicrophoneRecorder().
This call can take up to half a second to run, try to perform this operation behind the scenes
InputManager.getSpeechToText() method
Get the speech to text object acting globally against the device mic input
Signature:
getSpeechToText(settings?: SpeechToTextConfig): Promise<SpeechToText>;
Parameters
Parameter | Type | Description |
---|---|---|
settings | SpeechToTextConfig | (Optional) Device default used if not supplied |
Returns:
Promise<SpeechToText>
InputManager.HapticFeedback property
Warning: This API is now obsolete.
Use HapticFeedback
Kinds of haptic feedback available. These vibrations vary in intensity, duration, and can be preset patterns.
Signature:
static readonly HapticFeedback: typeof HapticFeedback;
Remarks
The initial set including Selection, Impacts, and Notifications, map to the iOS Taptic engine's presets. See https://developer.apple.com/documentation/uikit/uifeedbackgenerator.
InputManager.playHapticFeedback() method
Trigger haptic (vibration) feedback of various kinds.
Signature:
playHapticFeedback(type?: Enum<typeof HapticFeedback>): void;
Parameters
Parameter | Type | Description |
---|---|---|
type | Enum<typeof HapticFeedback> | (Optional) Preset haptic type to play |
Returns:
void
Remarks
When used sparingly to emphasize important moments during play, this can add another dimension to the game feel. If the haptic feedback is meant to be in response to a touch event, make sure to call this method on the "touchstart" event rather than "touchend" or "click", to eliminate any delay.
Updated 7 months ago