WebViewPrefab

class : MonoBehaviour

WebViewPrefab is the easiest way to create and interact with an IWebView. It takes care of creating and initializing an IWebView, displaying its texture, and handling click and scroll events from the user. 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 it.

WebViewPrefab handles standard events from Unity's input system (like IPointerClickHandler), so it works with input modules that extend BaseInputModule, like Unity's Standalone Input Module and third-party modules, like those from the Google VR and Oculus SDKs.

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 hook it up to your own custom GameObject.

Summary

Public properties

ClickingEnabled

bool ClickingEnabled

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

DragToScrollThreshold

float DragToScrollThreshold

In order to prevent dragging-to-scroll from triggering unwanted clicks, a click is discarded if the pointer drags beyond this threshold before PointerUp occurs. The default threshold is 0.15.

ScrollSensitivity

static float ScrollSensitivity

Allows the scroll sensitivity to be adjusted. The default sensitivity is 0.001.

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 GameObject.Destroy().

Init

void Init()

Asynchronously initializes the WebViewPrefab using the width and height set via the Unity editor.

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)

Asynchronously initializes the WebViewPrefab to the specified size.

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.