安全上下文
此特征只可用于
安全上下文
(HTTPS),在某些或所有
支持浏览器
.
XRInputSourceArray
方法
forEach()
executes the specified callback once for each input source in the array, starting at index 0 and progressing until the end of the list.
xrInputSourceArray.forEach(callback, thisArg);
callback
A function to execute once for each entry in the array
xrInputSourceArray
. The callback accepts up to three parameters:
currentValue
XRInputSource
object which is the value of the item from within the
xrInputSourceArray
which is currently being processed.
currentIndex
可选
currentValue
is located. If you don't need to know the index number, you can omit this.
sourceList
可选
XRInputSourceArray
object which is being processed. If you don't need this information, you may omit this.
thisArg
可选
this
while executing the callback. Note that if you use
arrow function notation
(
=>
) to provide the callback, you can omit
thisArg
, since all arrow functions lexically bind
this
.
Undefined.
This example snippet gets the list of inputs for a session and tries to handle each type of input device it supports using.
let inputSources = xrSession.inputSources;
inputSources.forEach((input) => {
if (input.gamepad) {
checkGamepad(input.gamepad);
} else {
if (input.targetRayMode === "tracked-pointer" &&
input.handedness === player.handedness) {
/* Handle main hand controller */
handleMainHandInput(input);
} else {
/* Handle other inputs */
}
}
});
For each input in the llist, the callback dispatches gamepad inputs to a
checkGamepad()
with the input's
Gamepad
object, taken from its
gamepad
property, as an input
For other devices, we look for
tracked-pointer
devices in the player's main hand, dispatching those to a
handleMainHandInput()
方法。
| 规范 | 状态 | 注释 |
|---|---|---|
|
WebXR 设备 API
The definition of 'XRInputSourceArray' in that specification. 1 |
工作草案 |
XRInputSourceArray
interface
|
[1]
见
Iterator-like methods
in
Information contained in a WebIDL file
for information on how an
iterable
declaration in an interface definition causes
entries()
,
forEach()
,
keys()
,和
values()
methods to be exposed from objects that implement the interface.
| 桌面 | 移动 | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
forEach()
|
Chrome 79 | Edge 79 | Firefox No | IE No | Opera No | Safari No | WebView Android No | Chrome Android 79 | Firefox Android No | Opera Android No | Safari iOS No | Samsung Internet Android 11.2 |
完整支持
不支持
XRInputSourceArray
Navigator.xr
WebGLRenderingContext.makeXRCompatible()
XR
XRBoundedReferenceSpace
XRFrame
XRInputSource
XRInputSourceEvent
XRInputSourcesChangeEvent
XRPose
XRReferenceSpace
XRReferenceSpaceEvent
XRRenderState
XRRigidTransform
XRSession
XRSessionEvent
XRSpace
XRView
XRViewerPose
XRViewport
XRWebGLLayer