### VisionOSWindow Examples Source: https://developer.vuplex.com/webview/VisionOSWindow Code examples demonstrating how to interact with the VisionOSWindow class, including checking if the window is open, closing it, reopening it, and managing fullscreen capabilities. ```C# #if UNITY_VISIONOS && !UNITY_EDITOR var webView = await VisionOSWebView.CreateInWindow(); if (webView.Window.IsOpen) { Debug.Log("Window is open"); } #endif ``` ```C# #if UNITY_VISIONOS && !UNITY_EDITOR webView.Window.Close(); #endif ``` ```C# #if UNITY_VISIONOS && !UNITY_EDITOR webView.Window.Open(); #endif ``` ```C# #if UNITY_VISIONOS && !UNITY_EDITOR webView.Window.Open( new VisionOSWindowOptions { Size = new Vector2Int(1000, 1000), Position = new VisionOSWindowPosition( VisionOSWindowPositionType.Trailing, VisionOSWindowPosition.UnityBoundedSceneID ) } ); #endif ``` ```C# #if UNITY_VISIONOS && !UNITY_EDITOR var webView = await VisionOSWebView.CreateInWindow(); // Disable the JavaScript Fullscreen API. webView.Window.SetFullscreenEnabled(false); #endif ``` -------------------------------- ### 3D WebView C# Example: Loading a Webpage Source: https://developer.vuplex.com/webview/overview Demonstrates how to load a webpage using the IWebView interface in a Unity C# script. ```C# using UnityEngine; using Vuplex.WebView; public class WebLoader : MonoBehaviour { public CanvasWebViewPrefab webViewPrefab; void Start() { if (webViewPrefab != null) { // Ensure the web view is ready before loading webViewPrefab.WebView.WaitUntilInitialized(() => { webViewPrefab.WebView.LoadUrl("https://www.example.com"); }); } } } ``` -------------------------------- ### SetPixelDensity Example Source: https://developer.vuplex.com/webview/IWithPixelDensity Example demonstrating how to use the IWithPixelDensity interface to set the pixel density of a webview. ```csharp await webViewPrefab.WaitUntilInitialized(); var webViewWithPixelDensity = webViewPrefab.WebView as IWithPixelDensity; if (webViewWithPixelDensity == null) { Debug.Log("This 3D WebView plugin doesn't yet support IWithPixelDensity: " + webViewPrefab.WebView.PluginType); } else { webViewWithPixelDensity.SetPixelDensity(2); } ``` -------------------------------- ### 3D WebView C# Example: Executing JavaScript Source: https://developer.vuplex.com/webview/overview Shows how to execute JavaScript code within a web view using the ExecuteJavaScript method. ```C# using UnityEngine; using Vuplex.WebView; public class JavaScriptExecutor : MonoBehaviour { public CanvasWebViewPrefab webViewPrefab; void Update() { // Example: Execute JavaScript when the space bar is pressed if (Input.GetKeyDown(KeyCode.Space) && webViewPrefab != null) { webViewPrefab.WebView.ExecuteJavaScript("alert('Hello from Unity!');"); } } } ``` -------------------------------- ### VisionOSWebView Window Event Handling Example Source: https://developer.vuplex.com/webview/VisionOSWebView Example demonstrating how to create a VisionOSWebView in a new window and attach an event handler to detect when the window is closed. ```csharp #if UNITY_VISIONOS && !UNITY_EDITOR var webView = await VisionOSWebView.CreateInWindow(); // Add an event handler to detect when the user closes the window. webView.Window.Closed += (sender, eventArgs) => { Debug.Log("window closed"); }; #endif ``` -------------------------------- ### Load URL After Initialization Example Source: https://developer.vuplex.com/webview/WebViewPrefab Illustrates how to safely load a URL into the WebView after ensuring the WebView component has finished initializing. ```csharp await webViewPrefab.WaitUntilInitialized(); // Now the WebView property is ready. webViewPrefab.WebView.LoadUrl("https://vuplex.com"); ``` -------------------------------- ### Vuplex WebView Initialization and Messaging Example Source: https://developer.vuplex.com/webview/IWebView Demonstrates how to wait for the WebView to initialize, add JavaScript to send a message, and handle incoming messages from JavaScript. ```C# await webViewPrefab.WaitUntilInitialized(); // Add JavaScript to the page that sends a message. webViewPrefab.WebView.PageLoadScripts.Add(@" window.vuplex.postMessage('Hello from JavaScript!'); "); webViewPrefab.WebView.MessageEmitted += (sender, eventArgs) => { Debug.Log("Message received from JavaScript: " + eventArgs.Value); }; ``` -------------------------------- ### Set Pixel Density Example Source: https://developer.vuplex.com/webview/WebViewPrefab Demonstrates how to increase the pixel density of the WebViewPrefab to improve the sharpness of web content on high DPI displays. ```csharp // Increase the pixel density to 2 for high DPI screens. webViewPrefab.PixelDensity = 2; ``` -------------------------------- ### Set Resolution Example Source: https://developer.vuplex.com/webview/WebViewPrefab Shows how to adjust the WebViewPrefab's resolution to control the perceived size of web content, making it appear larger or smaller. ```csharp // Set the resolution to 1800px per Unity unit. webViewPrefab.Resolution = 1800; ``` -------------------------------- ### Instantiate Keyboard in WebViewPrefab Source: https://developer.vuplex.com/webview/Keyboard Demonstrates how to instantiate a Keyboard object and parent it under a WebViewPrefab in Unity. This setup positions the keyboard relative to the prefab. ```csharp // Add a keyboard under a WebViewPrefab. var keyboard = Keyboard.Instantiate(); keyboard.transform.SetParent(webViewPrefab.transform, false); keyboard.transform.localPosition = new Vector3(0, -0.31f, 0); keyboard.transform.localEulerAngles = Vector3.zero; ``` -------------------------------- ### IWithFind Interface Example Source: https://developer.vuplex.com/webview/IWithFind Demonstrates how to use the IWithFind interface to search for text within a web page, handle results, and clear matches. It includes checks for interface availability and navigation between matches. ```C# await webViewPrefab.WaitUntilInitialized; // Search for the word "and" in the page. var webViewWithFind = webViewPrefab.WebView as IWithFind; if (webViewWithFind == null) { Debug.Log("This 3D WebView plugin doesn't yet support IWithFind: " + webViewPrefab.WebView.PluginType); return; } var result = await webViewWithFind.Find("and", true); Debug.Log($"Number of matches: {result.MatchCount}. Index of current match: {result.CurrentMatchIndex}"); if (result.MatchCount > 1) { // Later, scroll to the next instance of "and" in the page. await webViewWithFind.Find("and", true); // Later, go back to the first match. await webViewWithFind.Find("and", false); } // Later, clear all matches. webViewWithFind.ClearFindMatches(); ``` -------------------------------- ### Get Raw Texture Data Source: https://developer.vuplex.com/webview/IWebView Example demonstrating how to get raw texture data from a WebView and load it into a Unity Texture2D. Note that on iOS, video content is excluded from the texture data. ```C# var webView = webViewPrefab.WebView; var textureData = await webView.GetRawTextureData(); var texture = new Texture2D( webView.Size.x, webView.Size.y, TextureFormat.RGBA32, false, false ); texture.LoadRawTextureData(textureData); texture.Apply(); ``` -------------------------------- ### Get IFrameElementID Example Source: https://developer.vuplex.com/webview/WebGLWebView Demonstrates how to retrieve the iframe element ID from a WebGLWebView instance in a Unity WebGL build. ```C# await canvasWebViewPrefab.WaitUntilInitialized(); #if UNITY_WEBGL && !UNITY_EDITOR var webGLWebView = canvasWebViewPrefab.WebView as WebGLWebView; Debug.Log("IFrame ID: " + webGLWebView.IFrameElementID); #endif ``` -------------------------------- ### WebViewPrefab API Documentation Source: https://developer.vuplex.com/webview/WebViewPrefab Provides comprehensive documentation for key methods of the WebViewPrefab class in Vuplex, including instantiation, destruction, resizing, and option setting. ```APIDOC WebViewPrefab.Destroy() - Destroys the instance and its children. - Note: This method is not required if the instance's parent is destroyed using Object.Destroy(). - Example: webViewPrefab.Destroy(); WebViewPrefab.Instantiate(float width, float height) - Creates a new WebViewPrefab instance with specified dimensions in Unity units. - The default resolution is 1300px per Unity unit, adjustable via the Resolution property. - The WebView property becomes available after initialization, indicated by WaitUntilInitialized(). - Parameters: - width: The desired width of the webview in Unity units. - height: The desired height of the webview in Unity units. - Example: // Create a 0.5 x 0.5 instance var webViewPrefab = WebViewPrefab.Instantiate(0.5f, 0.5f); // Position the prefab webViewPrefab.transform.parent = transform; webViewPrefab.transform.localPosition = new Vector3(0, 0f, 0.5f); webViewPrefab.transform.LookAt(transform); // Load a URL after initialization await webViewPrefab.WaitUntilInitialized(); webViewPrefab.WebView.LoadUrl("https://vuplex.com"); WebViewPrefab.Instantiate(float width, float height, WebViewOptions options) - Creates a new WebViewPrefab instance with specified dimensions and custom options. - Parameters: - width: The desired width of the webview in Unity units. - height: The desired height of the webview in Unity units. - options: An object of WebViewOptions to customize behavior. WebViewPrefab.Instantiate(IWebView webView) - Initializes a new WebViewPrefab instance with an existing, initialized IWebView instance. - Allows multiple WebViewPrefabs to share the same IWebView or to wrap an IWebView created by IWithPopups.PopupRequested. - Parameters: - webView: An existing, initialized IWebView instance. - Example: await firstWebViewPrefab.WaitUntilInitialized(); var secondWebViewPrefab = WebViewPrefab.Instantiate(firstWebViewPrefab.WebView); // TODO: Position secondWebViewPrefab. WebViewPrefab.Resize(float width, float height) - Resizes the prefab mesh and the webview to the given dimensions in Unity units. - Parameters: - width: The new width in Unity units. - height: The new height in Unity units. - See also: [Resolution](#Resolution) - Example: webViewPrefab.Resize(1.2f, 0.5f); WebViewPrefab.SetOptionsForInitialization(WebViewOptions options) - Sets options that alter the webview created during initialization. - Must be called before the prefab initializes (e.g., immediately after instantiation or activation). - Parameters: - options: WebViewOptions to configure the webview. - Example: // In a script: // public BaseWebViewPrefab webViewPrefab; // ... // webViewPrefab.gameObject.SetActive(true); // webViewPrefab.SetOptionsForInitialization(new WebViewOptions { preferredPlugins = new WebPluginType[] { WebPluginType.Android } }); WebViewPrefab.SetPointerInputDetector(IPointerInputDetector pointerInputDetector) - Overrides the default pointer input detection mechanism, which uses Unity's event system. - Parameters: - pointerInputDetector: An instance implementing IPointerInputDetector. - Example: var yourCustomInputDetector = webViewPrefab.Collider.AddComponent(); webViewPrefab.SetPointerInputDetector(yourCustomInputDetector); ``` -------------------------------- ### Get WebView Size Source: https://developer.vuplex.com/webview/IWebView Gets the webview's dimensions in pixels. This property is useful for understanding the current rendering resolution of the web content. ```C# await webViewPrefab.WaitUntilInitialized(); Debug.Log("Size: " + webViewPrefab.WebView.Size); ``` -------------------------------- ### WebView Prefab Initialization and State Source: https://developer.vuplex.com/webview/WebViewPrefab Methods and events related to the initialization and state of the WebView prefab. Includes setting an existing WebView and waiting for initialization. ```APIDOC SetWebViewForInitialization: void SetWebViewForInitialization(IWebView webView) - Description: Allows passing an existing, initialized IWebView to the prefab before it initializes. This bypasses the default creation of a new IWebView. - Constraints: Must be called prior to prefab initialization (e.g., immediately after instantiation or activation). WaitUntilInitialized: Task WaitUntilInitialized() - Description: Returns a Task that completes when the prefab has finished initializing and its WebView property is ready for use. - Returns: A Task that signals completion upon initialization. - Example: await webViewPrefab.WaitUntilInitialized(); // WebView property is now ready. webViewPrefab.WebView.LoadUrl("https://vuplex.com"); Initialized: EventHandler Initialized - Description: Event that fires when the prefab finishes initializing, making its WebView property available. - See also: WaitUntilInitialized() ``` -------------------------------- ### LoadProgressChanged Event Source: https://developer.vuplex.com/webview/IWebView Indicates changes in the loading status of a web page, such as starting, updating progress, finishing, or failing. This event is useful for implementing load progress bars or detecting when a page has completed loading. For WebGL, only 'Started' and 'Finished' events are supported. ```APIDOC LoadProgressChanged: Signature: EventHandler LoadProgressChanged Description: Indicates changes in the loading status of a web page. This event can be used, for example, to detect when a page finishes loading or to implement a load progress bar. It indicates the following types of load events: Started, Updated, Finished, Failed. Parameters: sender: The object that raised the event. eventArgs: ProgressChangedEventArgs containing load status information. Type: ProgressChangeType - Indicates the type of load event (Started, Updated, Finished, Failed). Progress: A float value representing the loading progress (0.0 to 1.0), only available for 'Updated' events. Limitations: - For 2D WebView for WebGL, LoadProgressChanged only indicates ProgressChangeType.Started and Finished events, and it's unable to indicate the Failed or Updated events. See also: - WaitForNextPageLoadToFinish() Example: await webViewPrefab.WaitUntilInitialized(); webViewPrefab.WebView.LoadProgressChanged += (sender, eventArgs) => { Debug.Log($"Load progress changed: {eventArgs.Type}, {eventArgs.Progress}"); if (eventArgs.Type == ProgressChangeType.Finished) { Debug.Log("The page finished loading"); } }; ``` ```csharp await webViewPrefab.WaitUntilInitialized(); webViewPrefab.WebView.LoadProgressChanged += (sender, eventArgs) => { Debug.Log($"Load progress changed: {eventArgs.Type}, {eventArgs.Progress}"); if (eventArgs.Type == ProgressChangeType.Finished) { Debug.Log("The page finished loading"); } }; ``` -------------------------------- ### Material Property Source: https://developer.vuplex.com/webview/CanvasWebViewPrefab Gets or sets the prefab's material. This property is not used when running in Native 2D Mode. ```APIDOC Material: Type: Material Description: Gets or sets the prefab's material. Note: This property is unused when running in Native 2D Mode. ``` -------------------------------- ### C# Example: Create PDF from WebView Source: https://developer.vuplex.com/webview/IWithPdfCreation Demonstrates how to use the `IWithPdfCreation` interface to create a PDF from the current web page in a Vuplex WebView. It includes error handling for unsupported plugins and shows how to move the generated PDF file. ```C# await webViewPrefab.WaitUntilInitialized(); var webViewWithPdfCreation = webViewPrefab.WebView as IWithPdfCreation; if (webViewWithPdfCreation == null) { Debug.Log("This 3D WebView plugin doesn't yet support IWithPdfCreation: " + webViewPrefab.WebView.PluginType); return; } var pdfFilePath = await webViewWithPdfCreation.CreatePdf(); // Now that the PDF has been created, do something with it. // For example, you can move it to a different location. File.Move(pdfFilePath, someOtherLocation); ``` -------------------------------- ### Instantiating CanvasKeyboard Programmatically Source: https://developer.vuplex.com/webview/CanvasKeyboard Shows how to create a new instance of CanvasKeyboard at runtime and configure its RectTransform properties. ```C# // Create a CanvasKeyboard. var keyboard = CanvasKeyboard.Instantiate(); keyboard.transform.SetParent(canvas.transform, false); var rectTransform = keyboard.transform as RectTransform; rectTransform.anchoredPosition3D = Vector3.zero; rectTransform.offsetMin = Vector2.zero; rectTransform.offsetMax = Vector2.zero; rectTransform.sizeDelta = new Vector2(650, 162); ``` -------------------------------- ### Get Current URL Source: https://developer.vuplex.com/webview/IWebView Retrieves the current URL of the web page. This property is updated after the page finishes loading. ```C# // Get the page's URL after it finishes loading. await webViewPrefab.WaitUntilInitialized(); await webViewPrefab.WebView.WaitForNextPageLoadToFinish(); Debug.Log("Page URL: " + webViewPrefab.WebView.Url); ``` -------------------------------- ### Get Page Title Source: https://developer.vuplex.com/webview/IWebView Retrieves the current title of the web page. This property is updated after the page finishes loading. ```C# // Get the page's title after it finishes loading. await webViewPrefab.WaitUntilInitialized(); await webViewPrefab.WebView.WaitForNextPageLoadToFinish(); Debug.Log("Page title: " + webViewPrefab.WebView.Title); ``` -------------------------------- ### WebViewPrefab Public Methods Source: https://developer.vuplex.com/webview/WebViewPrefab Provides essential methods for interacting with and managing a WebView Prefab instance. Includes methods for point conversion, destruction, instantiation with various overloads, resizing, configuration, and waiting for initialization. ```APIDOC WebViewPrefab: BrowserToScreenPoint(int xInPixels, int yInPixels) -> Vector2 Converts a point from browser coordinates (pixels) to screen coordinates. Parameters: xInPixels: The X coordinate in browser pixels. yInPixels: The Y coordinate in browser pixels. Returns: A Vector2 representing the point in screen coordinates. Destroy() -> void Destroys the WebView Prefab instance. Instantiate(float width, float height, WebViewOptions options) -> WebViewPrefab Creates a new WebView Prefab instance with specified dimensions and options. Parameters: width: The desired width of the webview. height: The desired height of the webview. options: WebViewOptions to configure the instance. Returns: The newly created WebViewPrefab instance. Instantiate(float width, float height) -> WebViewPrefab Creates a new WebView Prefab instance with specified dimensions. Parameters: width: The desired width of the webview. height: The desired height of the webview. Returns: The newly created WebViewPrefab instance. Instantiate(IWebView webView) -> WebViewPrefab Creates a new WebView Prefab instance using an existing IWebView implementation. Parameters: webView: An IWebView instance to use. Returns: The newly created WebViewPrefab instance. Resize(float width, float height) -> void Resizes the webview to the specified dimensions. Parameters: width: The new width of the webview. height: The new height of the webview. SetOptionsForInitialization(WebViewOptions options) -> void Sets webview options that will be used when the webview is initialized. Parameters: options: WebViewOptions to configure the instance. SetPointerInputDetector(IPointerInputDetector pointerInputDetector) -> void Sets a custom pointer input detector for the webview. Parameters: pointerInputDetector: An IPointerInputDetector instance. SetWebViewForInitialization(IWebView webView) -> void Sets an IWebView instance that will be used when the webview is initialized. Parameters: webView: An IWebView instance to use. WaitUntilInitialized() -> Task Asynchronously waits until the webview has finished initializing. Returns: A Task that completes when the webview is initialized. WorldToNormalized(Vector3 worldPoint) -> Vector2 Converts a point from world space coordinates to normalized screen coordinates (0 to 1). Parameters: worldPoint: The point in world space. Returns: A Vector2 representing the point in normalized screen coordinates. ``` -------------------------------- ### VisionOSWebView API Reference Source: https://developer.vuplex.com/webview/VisionOSWebView Provides detailed information on the VisionOSWebView class, its properties, and methods for visionOS development. Includes methods for creating webviews in windows, accessing native components, and managing platform-specific features like camera and microphone. ```APIDOC VisionOSWebView API Reference: Class: Vuplex.WebView.VisionOSWebView Inherits: Vuplex.WebView.IWebView Summary: VisionOSWebView is the IWebView implementation used by 3D WebView for visionOS. It also includes additional APIs for visionOS-specific functionality. Public Properties: - Window: Signature: VisionOSWindow Window Description: If the webview was created via CreateInWindow(), this property is a VisionOSWindow instance that provides APIs to manipulate the native SwiftUI window, such as closing and re-opening it. If the webview was not created via CreateInWindow() (e.g. it was created via a CanvasWebViewPrefab), then this property is null. Example: #if UNITY_VISIONOS && !UNITY_EDITOR var webView = await VisionOSWebView.CreateInWindow(); // Add an event handler to detect when the user closes the window. webView.Window.Closed += (sender, eventArgs) => { Debug.Log("window closed"); }; #endif Public Methods: - CreateInWindow(): Signature: Task CreateInWindow() Description: Creates a new VisionOSWebView instance within its own native window. Returns: A Task that resolves to the created VisionOSWebView. - CreateInWindow(VisionOSWindowOptions options): Signature: Task CreateInWindow(VisionOSWindowOptions options) Description: Creates a new VisionOSWebView instance within its own native window with specified options. Parameters: options: VisionOSWindowOptions to configure the new window. Returns: A Task that resolves to the created VisionOSWebView. - GetNativeWebView(): Signature: IntPtr GetNativeWebView() Description: Returns a pointer to the native webview object. Returns: A pointer to the native webview. - SetCameraEnabled(bool enabled): Signature: static void SetCameraEnabled(bool enabled) Description: Enables or disables the camera for the webview. Parameters: enabled: True to enable the camera, false otherwise. - SetMicrophoneEnabled(bool enabled): Signature: static void SetMicrophoneEnabled(bool enabled) Description: Enables or disables the microphone for the webview. Parameters: enabled: True to enable the microphone, false otherwise. - SetTargetFrameRate(uint targetFrameRate): Signature: void SetTargetFrameRate(uint targetFrameRate) Description: Sets the target frame rate for the webview's rendering. Parameters: targetFrameRate: The desired frame rate. ``` -------------------------------- ### CanvasWebViewPrefab Public Methods Source: https://developer.vuplex.com/webview/CanvasWebViewPrefab Provides an overview of the core public methods available on the CanvasWebViewPrefab class for managing web view instances. This includes methods for converting screen points, destroying the web view, instantiating new prefabs with different configurations, setting initialization options, and waiting for the web view to become ready. ```APIDOC CanvasWebViewPrefab: BrowserToScreenPoint(int xInPixels, int yInPixels) -> Vector2 Converts a point from browser coordinates (pixels) to screen coordinates. Parameters: xInPixels: The X coordinate in browser pixels. yInPixels: The Y coordinate in browser pixels. Returns: A Vector2 representing the point in screen coordinates. Destroy() -> void Destroys the web view instance and releases associated resources. Instantiate(IWebView webView) -> CanvasWebViewPrefab Creates a new CanvasWebViewPrefab instance associated with a specific IWebView. Parameters: webView: The IWebView instance to associate with the new prefab. Returns: The newly created CanvasWebViewPrefab instance. Instantiate() -> CanvasWebViewPrefab Creates a new CanvasWebViewPrefab instance with default settings. Returns: The newly created CanvasWebViewPrefab instance. Instantiate(WebViewOptions options) -> CanvasWebViewPrefab Creates a new CanvasWebViewPrefab instance with specified initialization options. Parameters: options: WebViewOptions to configure the new instance. Returns: The newly created CanvasWebViewPrefab instance. SetOptionsForInitialization(WebViewOptions options) -> void Sets the WebViewOptions that will be used when the web view is initialized. Parameters: options: The WebViewOptions to apply. SetPointerInputDetector(IPointerInputDetector pointerInputDetector) -> void Sets a custom pointer input detector for handling input events. Parameters: pointerInputDetector: The IPointerInputDetector to use. SetWebViewForInitialization(IWebView webView) -> void Sets a specific IWebView instance to be used when the web view initializes. Parameters: webView: The IWebView instance to use. WaitUntilInitialized() -> Task Asynchronously waits until the web view has completed its initialization process. Returns: A Task that completes when the web view is initialized. ``` -------------------------------- ### Setting User-Agent with IWithSettableUserAgent Source: https://developer.vuplex.com/webview/IWithSettableUserAgent Example demonstrating how to cast a WebViewPrefab's WebView to IWithSettableUserAgent and set a mobile or custom User-Agent string. ```C# await webViewPrefab.WaitUntilInitialized(); var webViewWithUserAgent = webViewPrefab.WebView as IWithSettableUserAgent; if (webViewWithUserAgent != null) { // Set a flag indicating a mobile User-Agent. webViewWithUserAgent.SetUserAgent(true); // OR set a custom User-Agent string. webViewWithUserAgent.SetUserAgent("Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:91.0) Gecko/20100101 Firefox/91.0"); } ``` -------------------------------- ### Vuplex WebView Core Methods Source: https://developer.vuplex.com/webview/IWebView Provides documentation for core methods of the Vuplex WebView API, including coordinate transformations, clipboard operations, message posting, reloading, resizing, and scrolling. Each method includes its signature, a description of its functionality, parameter details, return values, and usage examples. Important notes highlight platform-specific limitations or alternative methods. ```APIDOC WebView Methods: NormalizedToPoint: [Vector2Int](https://docs.unity3d.com/ScriptReference/Vector2Int.html) NormalizedToPoint([Vector2](https://docs.unity3d.com/ScriptReference/Vector2.html) normalizedPoint) - Returns a point in pixels for the given normalized point. - Parameters: - normalizedPoint: The normalized point to convert. - Returns: A Vector2Int representing the point in pixels. - Example: webViewPrefab.Clicked += (sender, eventArgs) => { var pointInPixels = webViewPrefab.WebView.NormalizedToPoint(eventArgs.Point); Debug.Log("Point in pixels: " + pointInPixels); }; - See also: [PointToNormalized()](#PointToNormalized) Paste: void Paste() - Pastes text from the clipboard. - Parameters: None. - Returns: void. - Example: webViewPrefab.WebView.Paste(); - Important note: [2D WebView for WebGL](https://store.vuplex.com/webview/webgl) doesn't support this API due to browser limitations. - See also: [Copy()](#Copy), [Cut()](#Cut) PointToNormalized: [Vector2](https://docs.unity3d.com/ScriptReference/Vector2.html) PointToNormalized(int xInPixels, int yInPixels) - Returns a normalized point for the given x and y coordinates in pixels. - Parameters: - xInPixels: The x-coordinate in pixels. - yInPixels: The y-coordinate in pixels. - Returns: A Vector2 representing the normalized point. - Example: var webView = webViewPrefab.WebView; // Scroll to the right by 50 pixels at (100px, 1300px). webView.Scroll( webView.PointToNormalized(50, 0), webView.PointToNormalized(100, 1300) ); - See also: [NormalizedToPoint()](#NormalizedToPoint) PostMessage: void PostMessage(string data) - Posts a message that JavaScript within the webview can listen for using `window.vuplex.addEventListener('message', function(message) {})`. - Parameters: - data: The string data to send with the message. - Returns: void. - Example: await webViewPrefab.WebView.WaitUntilInitialized(); // Add some JavaScript to the page to receive the message. webViewPrefab.WebView.PageLoadScripts(@"\n window.vuplex.addEventListener('message', function(event) {\n console.log('Message received from C#: ' + event.data);\n });\n"); // When the page finishes loading, send a message from C# to JavaScript. await webViewPrefab.WebView.WaitForNextPageLoadToFinish(); webViewPrefab.WebView.PostMessage("Hello from C#"); Reload: void Reload() - Reloads the current page. - Parameters: None. - Returns: void. - Example: webViewPrefab.WebView.Reload(); Resize: void Resize(int width, int height) - Resizes the webview to the given dimensions in pixels. - Parameters: - width: The new width in pixels. - height: The new height in pixels. - Important notes: - If you're using [WebViewPrefab](#WebViewPrefab), you should call [WebViewPrefab.Resize()](/webview/WebViewPrefab#Resize) instead. - On visionOS, if the webview was created with [VisionOSWebView.CreateInWindow()](/webview/VisionOSWebView#CreateInWindow), then calling Resize() has no effect. - See also: [Size](#Size) Scroll (delta): void Scroll(int scrollDeltaXInPixels, int scrollDeltaYInPixels) - Scrolls the top-level document by the given delta in pixels. - Parameters: - scrollDeltaXInPixels: The amount to scroll horizontally in pixels. - scrollDeltaYInPixels: The amount to scroll vertically in pixels. - Example: // Scroll down by 50 pixels. webViewPrefab.WebView.Scroll(0, 50); // Scroll to the left by 20 pixels. webViewPrefab.WebView.Scroll(-20, 0); - Important note: For [2D WebView for WebGL](https://store.vuplex.com/webview/webgl), this API is often disabled due to browser limitations. - Alternative: [Scroll(Vector2, Vector2)](#Scroll) to scroll at a specific location. ``` -------------------------------- ### Handle WebView Initialization and Events Source: https://developer.vuplex.com/webview/CanvasWebViewPrefab Provides examples of how to wait for a WebView to initialize and how to subscribe to various events like Clicked, Initialized, PointerEntered, PointerExited, and Scrolled. These events allow for custom behavior based on user interaction or WebView state changes. ```APIDOC WebViewPrefab Methods: SetPointerInputDetector(IPointerInputDetector pointerInputDetector) - Overrides the default pointer input detection mechanism for the prefab. - Parameters: - pointerInputDetector: An implementation of IPointerInputDetector to handle input events. SetWebViewForInitialization(IWebView webView) - Allows passing an existing, initialized IWebView to the prefab before it initializes. - This method must be called prior to the prefab initializing. WaitUntilInitialized() Task - Returns a Task that completes when the prefab is initialized and its WebView property is ready. - Example: await canvasWebViewPrefab.WaitUntilInitialized(); // Now the WebView property is ready. canvasWebViewPrefab.WebView.LoadUrl("https://vuplex.com"); - See also: Initialized WebViewPrefab Events: Clicked EventHandler - Indicates that the prefab was clicked. - The prefab automatically calls IWebView.Click() for you. - Example: canvasWebViewPrefab.Clicked += (sender, eventArgs) => { Debug.Log("WebViewPrefab was clicked at point: " + eventArgs.Point); }; - Important note: Not supported in Native 2D Mode. Initialized EventHandler - Indicates that the prefab finished initializing and its WebView property is ready. - See also: WaitUntilInitialized() PointerEntered EventHandler - Indicates that the pointer (e.g., mouse cursor) entered the prefab. PointerExited EventHandler - Indicates that the pointer (e.g., mouse cursor) exited the prefab. Scrolled EventHandler - Indicates that the prefab was scrolled. - The prefab automatically calls IWebView.Scroll() for you. - Example: canvasWebViewPrefab.Scrolled += (sender, eventArgs) => { Debug.Log($"WebViewPrefab was scrolled. Point: {eventArgs.Point}, scroll delta: {eventArgs.ScrollDelta}"); }; - Important note: Not supported in Native 2D Mode. ``` -------------------------------- ### WebGLWebView SetGeolocationEnabled Example Source: https://developer.vuplex.com/webview/WebGLWebView Shows how to enable or disable the JavaScript Geolocation API for webviews. The default is false, meaning geolocation services are off by default. ```csharp void Awake() { #if UNITY_WEBGL && !UNITY_EDITOR WebGLWebView.SetGeolocationEnabled(true); #endif } ``` -------------------------------- ### Check IFrame Content Access Example Source: https://developer.vuplex.com/webview/WebGLWebView Shows how to check if the WebGLWebView can access its iframe content, which affects the availability of certain IWebView APIs. ```C# await canvasWebViewPrefab.WaitUntilInitialized(); #if UNITY_WEBGL && !UNITY_EDITOR var webGLWebView = canvasWebViewPrefab.WebView as WebGLWebView; if (webGLWebView.CanAccessIFrameContent()) { Debug.Log("The iframe content can be accessed 👍"); } #endif ``` -------------------------------- ### AndroidGeckoWebView API Documentation Source: https://developer.vuplex.com/webview/AndroidGeckoWebView Comprehensive documentation for the AndroidGeckoWebView class, detailing its public methods and events. This includes static methods for global configurations and instance methods for managing individual web view states, session data, and platform-specific operations. ```APIDOC AndroidGeckoWebView: class : IWebView Namespace: Vuplex.WebView Description: AndroidGeckoWebView is the IWebView implementation used by 3D WebView for Android with Gecko Engine. It also includes additional APIs for Gecko-specific functionality. Public methods: static void EnsureBuiltInExtension(string uri, string id) Description: Ensures that a built-in extension is available for the given URI and ID. Parameters: uri: The URI of the extension. id: The ID of the extension. static AndroidJavaObject GetGeckoRuntime() Description: Returns the underlying GeckoRuntime object. Returns: An AndroidJavaObject representing the GeckoRuntime. AndroidJavaObject GetNativeWebView() Description: Returns the native Android WebView object. Returns: An AndroidJavaObject representing the native WebView. string GetSessionState() Description: Gets the current session state of the web view. Returns: A string representing the session state. void Pause() Description: Pauses the web view. static void PauseAll() Description: Pauses all web views. static void RestoreAudioFocus() Description: Restores audio focus for web views. void RestoreSessionState() Description: Restores the web view to its previous session state. void Resume() Description: Resumes the web view. static void ResumeAll() Description: Resumes all web views. static void RunOnAndroidUIThread(Action function) Description: Executes a function on the Android UI thread. Parameters: function: The action to execute. static void SetConsoleOutputEnabled(bool enabled) Description: Enables or disables console output for web views. Parameters: enabled: True to enable console output, false otherwise. static void SetDebugLoggingEnabled(bool enabled) Description: Enables or disables debug logging for web views. Parameters: enabled: True to enable debug logging, false otherwise. static void SetDrmEnabled(bool enabled) Description: Enables or disables Digital Rights Management (DRM) for web views. Parameters: enabled: True to enable DRM, false otherwise. static void SetGeolocationEnabled(bool enabled) Description: Enables or disables geolocation services for web views. Parameters: enabled: True to enable geolocation, false otherwise. static void SetLocales(string[] locales) Description: Sets the locales for the web view. Parameters: locales: An array of locale strings. static void SetPixelDensity(float pixelDensity) Description: Sets the pixel density for the web view. Parameters: pixelDensity: The pixel density value. static void SetPreferences(Dictionary preferences) Description: Sets custom preferences for the web view. Parameters: preferences: A dictionary of preference keys and values. void SetSurface(IntPtr surface) Description: Sets the native surface for the web view. Parameters: surface: A pointer to the native surface. static void SetXRContext(IntPtr externalXRContext) Description: Sets the XR context for the web view. Parameters: externalXRContext: A pointer to the external XR context. Public events: EventHandler ClientCertificateRequested Description: Occurs when a client certificate is requested. EventHandler FileSelectionRequested Description: Occurs when a file selection is requested. EventHandler ScriptAlerted Description: Occurs when a JavaScript alert dialog is shown. EventHandler> ScriptConfirmRequested Description: Occurs when a JavaScript confirm dialog is shown. ``` -------------------------------- ### Get Plugin Type Source: https://developer.vuplex.com/webview/IWebView Retrieves the instance's plugin type. This property provides information about the specific type of plugin being used by the WebView. ```C# await webViewPrefab.WaitUntilInitialized(); Debug.Log("Plugin type: " + webViewPrefab.WebView.PluginType); ``` -------------------------------- ### SetMicrophoneEnabled Source: https://developer.vuplex.com/webview/iOSWebView Enables only the microphone for WebRTC functionality without activating the camera. Specific setup steps are necessary on iOS, as outlined in the Vuplex WebRTC documentation. ```C# static void SetMicrophoneEnabled(bool enabled) // Example: void Awake() { #if UNITY_IOS && !UNITY_EDITOR iOSWebView.SetMicrophoneEnabled(true); #endif } ``` -------------------------------- ### Using Advanced WebView Features (IWithPopups) Source: https://developer.vuplex.com/webview/additional-interfaces Demonstrates how to access and use advanced WebView functionalities, such as handling popups, by casting the IWebView instance to a specific interface like IWithPopups. This example shows how to set popup behavior and subscribe to popup requests. ```csharp await webViewPrefab.WaitUntilInitialized(); var webViewWithPopups = webViewPrefab.WebView as IWithPopups; if (webViewWithPopups != null) { webViewWithPopups.SetPopupMode(PopupMode.NotifyWithoutLoading); webViewWithPopups.PopupRequested += (sender, eventArgs) => { Debug.Log("Popup requested: " + eventArgs.Url); }; } ``` -------------------------------- ### SetCameraEnabled Source: https://developer.vuplex.com/webview/iOSWebView Enables only the camera for WebRTC functionality without activating the microphone. Additional setup steps are required on iOS, as detailed in the Vuplex WebRTC documentation. ```C# static void SetCameraEnabled(bool enabled) // Example: void Awake() { #if UNITY_IOS && !UNITY_EDITOR iOSWebView.SetCameraEnabled(true); #endif } ``` -------------------------------- ### Vuplex WebView Platform-Specific Implementations Source: https://developer.vuplex.com/webview/WebViewPrefab Details the platform-specific implementations of the IWebView interface, catering to various operating systems and rendering pipelines within Unity. ```APIDOC API Reference: Platform-specific: - AndroidWebView: Implementation for Android platforms. - AndroidGeckoWebView: Gecko-based WebView implementation for Android. - iOSWebView: Implementation for iOS platforms. - StandaloneWebView: Implementation for standalone desktop builds. - UwpWebView: Implementation for Universal Windows Platform (UWP). - VisionOSWebView: Implementation for Apple VisionOS. - WebGLWebView: Implementation for WebGL builds. ``` -------------------------------- ### 3D WebView Core API Reference Source: https://developer.vuplex.com/webview/overview Provides access to core web view functionalities, including loading URLs, handling user input, and managing browser events. This API is designed to be unified across multiple platforms. ```APIDOC IWebView: // Interface for controlling a web view. // Methods: LoadUrl(url: string): void // Loads a webpage from the specified URL. LoadHtml(html: string, baseUrl: string = null): void // Loads HTML content directly. // baseUrl: Optional base URL for resolving relative paths in the HTML. ExecuteJavaScript(javaScript: string): void // Executes arbitrary JavaScript code within the web view. // Events: OnPageLoadStarted: Event // Fired when a page begins to load, providing the URL. OnPageLoadFinished: Event // Fired when a page finishes loading, providing the URL. OnConsoleMessage: Event // Fired when a console message is logged by the web view. // Parameters: message (string), lineNumber (int) OnUrlChanged: Event // Fired when the web view's URL changes. // Properties: Url: string // Gets or sets the current URL of the web view. CanGoBack: bool // Indicates if the web view can navigate back. CanGoForward: bool // Indicates if the web view can navigate forward. // Related Interfaces: // WebViewPrefab: MonoBehaviour for 3D integration. // CanvasWebViewPrefab: MonoBehaviour for 2D UI integration. // Keyboard: Interface for on-screen keyboard input. // Advanced features: Additional interfaces for complex interactions. // Platform-specific interfaces: For platform-specific controls. ``` ```APIDOC WebViewPrefab: // MonoBehaviour for integrating a web view into a 3D scene. // Renders to a Texture2D and handles 3D user interactions. // Properties: WebView: IWebView // The underlying IWebView instance. // Methods: // Inherits methods from IWebView. // Handles user interactions like click, scroll, hover, drag. // Related Interfaces: // CanvasWebViewPrefab: For 2D UI integration. ``` ```APIDOC CanvasWebViewPrefab: // MonoBehaviour for integrating a web view into a 2D UI canvas. // Renders to a Texture2D and handles 2D user interactions. // Properties: WebView: IWebView // The underlying IWebView instance. // Methods: // Inherits methods from IWebView. // Handles user interactions like click, scroll, hover, drag. // Related Interfaces: // WebViewPrefab: For 3D scene integration. ``` ```APIDOC Keyboard: // Interface for managing on-screen keyboard input. // Methods: Show(): void // Displays the on-screen keyboard. Hide(): void // Hides the on-screen keyboard. // Properties: IsVisible: bool // Indicates if the keyboard is currently visible. // Related Interfaces: // CanvasKeyboard: Platform-specific keyboard for Canvas. ```