安全上下文
此特征只可用于
安全上下文
(HTTPS),在某些或所有
支持浏览器
.
只读
length
property returns an integer value indicating the number of items in the input source list represented by the
XRInputSourceArray
对象。
let inputSourceCount = xrInputSourceArray.length;
An integer value indicating the number of
XRInputSource
objects representing WebXR input sources are includled in the array.
In this example, a game that requires at least one input source uses
length
to check this before proceeding to allow the user to play the game.
let sources = xrSession.inputSources;
if (sources.length === 0) {
showAlertDialog("You need to have at least one controller to play Super Duper Shark Jump Fest 9000.",
[
{ label: "Shop Now", url: "https://www.amazon.com/s?k=vr+controllers" },
{ label: "Quit" handler: quitGame }
]);
}
Here, if
length
is 0, a hypothetical
showAlertDialog()
function is called with a prompt string explaining the need for a controller, and an array of objects, each describing a button and what should happen when it's clicked. The first takes the user to an Amazon.com search for VR controllers, and the second calls a
quitGame()
function to start shutting the game program down.
| 规范 | 状态 | 注释 |
|---|---|---|
|
WebXR 设备 API
The definition of 'XRInputSourceArray.length' in that specification. |
工作草案 | 初始定义。 |
| 桌面 | 移动 | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
length
|
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
length
Navigator.xr
WebGLRenderingContext.makeXRCompatible()
XR
XRBoundedReferenceSpace
XRFrame
XRInputSource
XRInputSourceEvent
XRInputSourcesChangeEvent
XRPose
XRReferenceSpace
XRReferenceSpaceEvent
XRRenderState
XRRigidTransform
XRSession
XRSessionEvent
XRSpace
XRView
XRViewerPose
XRViewport
XRWebGLLayer