How does clicking and scrolling work?

3D WebView's prefabs (WebViewPrefab and CanvasWebViewPrefab) have a built-in input detector that automatically detects user input like clicking, dragging, and scrolling from the following sources:

Additionally, applications can customize how input is detected by using the approaches described in this section. A notable exception is that when Native 2D Mode is enabled, user interaction is detected directly by the native 2D webview rather than the prefab's input detector. For tips on troubleshooting clicking and scrolling, please see this article.

Unity's Event System

The prefabs' default input detectors listen for standard events sent through Unity's Event System, like IPointerDownHandler and IScrollHandler. So, they automatically work with input modules that send those standard events. Here are some of the compatible input modules:

Mixed Reality Toolkit 2 (MRTK2)

The prefabs' default input detectors also automatically detect input sent through MRTK2's input system. They do this by implementing IMixedRealityPointerHandler, so they automatically receive input events from MRTK2. They also detect touch interactions by adding a NearInteractionTouchable to the prefab. For an example of using 3D WebView with MRTK2, please see the Hololens webview example project. There is not currently an example project for using 3D WebView with MRTK3. I have a feature request for supporting MRTK3 and will update this article if I add an example project for it in the future. In the meantime, I recommend finding an MRTK3 sample scene that demonstrates using MRTK3 with a Unity Canvas and then adding a CanvasWebViewPrefab to that scene's Canvas.

Custom input detection

In rare cases, you may need to customize how 3D WebView's prefabs detect pointer input. For example, if your project uses a VR SDK that implements its own proprietary event system (like VRTK) instead of using Unity's event system, then the prefabs won't be able to automatically detect input. In a case like that, there are a couple of options for enabling 3D WebView's prefabs to receive input:

  1. The first option is to implement a custom IPointerInputDetector and then pass it to WebViewPrefab.SetPointerInputDetector(), like this:
var customInputDetector = webViewPrefab.Collider.gameObject.AddComponent<YourCustomInputDetector>();
webViewPrefab.SetPointerInputDetector(customInputDetector);
  1. Another option is to call IWebView methods directly on WebViewPrefab.WebView, like this:
webViewPrefab.WebView.Click(point);
webViewPrefab.WebView.Scroll(delta, point);