WebViewPrefab

class : MonoBehaviour

WebViewPrefab is the easiest way to create and interact with an IWebView. It takes care of wiring the IWebView up to its prefab's textures and input handlers, so all you need to do is load some web content from a URL or HTML string, and then the user can view and interact with the web content.

WebViewPrefab automatically handles pointer click, scroll, and drag events (also used for scrolling) from Unity's input event system.

Example:

// Create a 0.5 x 0.5 instance of of the prefab
var webViewPrefab = WebViewPrefab.Instantiate(0.5f, 0.5f);
// Position the prefab how we want it
webViewPrefab.transform.parent = transform;
webViewPrefab.transform.localPosition = new Vector3(0, 0f, 0.5f);
webViewPrefab.transform.LookAt(transform);
// Load a URL once the prefab finishes initializing
webViewPrefab.Initialized += (sender, e) => {
    webViewPrefab.WebView.LoadUrl("https://vuplex.com");
};

If your use case requires a high degree of customization, you can instead create an IWebView outside of the prefab using Web.CreateWebView() and then hook it up to your own textures.

Summary

Public properties

ClickingEnabled

bool ClickingEnabled

Clicking is enabled by default, but can be disabled by setting this property to false.

ScrollingEnabled

bool ScrollingEnabled

Scrolling is enabled by default, but can be disabled by setting this property to false.

WebView

IWebView WebView

A reference to the prefab's IWebView instance, which is available after the Initialized event is raised. Before initialization is complete, this property is null.

Public methods

Destroy

void Destroy()

Destroys the WebViewPrefab and its children. Note that you don't need to call this method if you destroy the WebViewPrefab's parent with UnityEngine.Object.Destroy().

Init

void Init(float width, float height)

Asynchronously initializes the WebViewPrefab instance. You only need to call this method directly if you place a WebViewPrefab prefab in your scene using the Unity Editor; it's not needed if you instantiate the prefab programmatically using Instantiate(). This method asynchronously initializes the WebView property, which is available after the Initialized event is fired.

Init

void Init(float width, float height, WebViewOptions options)

Like Init(float width, float height), except it also accepts an object of options flags that can be used to alter the webview's behavior.

Instantiate

static WebViewPrefab Instantiate(float width, float height)

Creates a new instance of the WebViewPrefab prefab with the given dimensions in Unity units and initializes it asynchronously. The WebView property is available after initialization completes, which is indicated by the Initialized event.

Instantiate

static WebViewPrefab Instantiate(float width, float height, WebViewOptions options)

Like Instantiate(float width, float height), except it also accepts an object of options flags that can be used to tweak the generated webview's behavior.

Resize

void Resize(float width, float height)

Resizes the prefab mesh and webview to the given dimensions in Unity units.

Public events

Clicked

EventHandler Clicked

Indicates that the prefab was clicked. Note that the prefab automatically calls the IWebView.Click() method for you.

Initialized

EventHandler Initialized

Indicates that the prefab finished initializing, so its WebView property is ready to use.