Accessible via the VisionOSWebView.Window property, this class provides APIs for manipulating the window of a webview created via VisionOSWebView.CreateInWindow().
bool IsOpen
Indicates whether the window is currently open.
#if UNITY_VISIONOS && !UNITY_EDITOR
var webView = await VisionOSWebView.CreateInWindow();
if (webView.Window.IsOpen) {
Debug.Log("Window is open");
}
#endif
void Close()
Closes the window. If the window is already closed, this method has no effect. Note that closing the window doesn't destroy the webview, and the window can be reopened by calling Open(). To destroy the webview, call IWebView.Dispose() instead.
#if UNITY_VISIONOS && !UNITY_EDITOR
webView.Window.Close();
#endif
void Open()
Reopens the window after it has previously been closed with Close(). If the window is already open, this method has no effect. This version of Open() opens the window using the size and position specified when the webview was created with CreateInWindow(). To open the window at a different size and position, use Open(VisionOSWindowOptions).
#if UNITY_VISIONOS && !UNITY_EDITOR
webView.Window.Open();
#endif
void Open(VisionOSWindowOptions options)
Like Open(), except it also accepts a VisionOSWindowOptions parameter for customizing the window's initial size and position.
#if UNITY_VISIONOS && !UNITY_EDITOR
webView.Window.Open(
new VisionOSWindowOptions {
Size = new Vector2Int(1000, 1000),
Position = new VisionOSWindowPosition(
VisionOSWindowPositionType.Trailing,
VisionOSWindowPosition.UnityBoundedSceneID
)
}
);
#endif
The VisionOSWindowsOptions.Size and Position options require visionOS 2.0. On visionOS 1.x, the Size and Position options are ignored, and a window always uses the system's default size and position.
See also: Fullscreen support in 3D WebView
void SetFullscreenEnabled(bool enabled)
Sets whether web pages can use the JavaScript Fullscreen API to make an HTML element occupy the entire webview. The default is true
, meaning that the JavaScript Fullscreen API is enabled by default.
#if UNITY_VISIONOS && !UNITY_EDITOR
var webView = await VisionOSWebView.CreateInWindow();
// Disable the JavaScript Fullscreen API.
webView.Window.SetFullscreenEnabled(false);
#endif
void SetScrollViewBounces(bool bounces)
Sets whether the scroll view bounces past the edge of content and back again. The default is true
.
#if UNITY_VISIONOS && !UNITY_EDITOR
var webView = await VisionOSWebView.CreateInWindow();
webView.Window.SetScrollViewBounces(false);
#endif
EventHandler Closed
Indicates that the window closed, either because the user pressed its close button or because the application called Close().
#if UNITY_VISIONOS && !UNITY_EDITOR
var webView = await VisionOSWebView.CreateInWindow();
// Add an event handler that destroys the webview when the user closes the window.
webView.Window.Closed += (sender, eventArgs) => {
webView.Dispose();
};
#endif