Usage

  • 2 minutes to read

Alright, lets get to actually using UWB.

Platform Support

UWB aims to support all desktop platforms (Windows, Linux, MacOS). The core currently does support all desktop platforms, however you will have to factor in what engine you want to use. Each engine has their own different platform support. See the engine page for each engine's platform support.

Warning

UWB does NOT support IL2CPP. This is because UWB requires launching a separate process, which uses System.Diagnostics.Process API that IL2CPP doesn't support.

UWB does however support being code trimmed.

Components

By default, UWB provides two different components for handling web viewing from a Raw Image:

While both of these components are fundamentally the same (they both inherit from BaseUwbClientManager), the WebBrowserUIFull has an additional FullscreenHandler for users who want fullscreen controls.

A WebBrowserUIControls component is also provided, to wrap around some methods provided in WebBrowserClient and expose them to Unity's UI system.

Options

Most options that you will ever need is in the WebBrowserClient, which is the core class for interfacing with UWB.

A lot options are exposed in the editor.

Web Browser Basic

The options are all very self-explanatory. If you need more info about one, hover over it for it's tooltip. Some options are explained in more details further along in the docs.

API

For calling methods on the engine (such as going back/forward/refresh, loading HTML, executing JS, etc...) are provided by the WebBrowserClient (see the API docs for a full reference). The WebBrowserClient lives as a property on BaseUwbClientManager. Any component that inherits from BaseUwbClientManager (such as WebBrowserUIFull) will have the WebBrowserClient exposed via browserClient property.

Some example code of loading a website from a method would look like:

using UnityEngine;
using VoltstroStudios.UnityWebBrowser;
using VoltstroStudios.UnityWebBrowser.Core;

public class ExampleLoadingSite : MonoBehaviour
{
    //You need a reference to UWB's WebBrowserClient, which is an object kept on BaseUwbClientManager
    //All of UWB's higher level components (such as WebBrowserUIBasic or WebBrowserUIFull) inherit from BaseUwbClientManager
    //so we can use that as the data type
    [SerializeField] //SerializeField allows us to set this in the editor
    private BaseUwbClientManager clientManager;
        
    private WebBrowserClient webBrowserClient;

    private void Start()
    {
        //You could also use Unity's GetComponent<BaseUwbClientManager>() method if this script exists on the same object.

        //Makes life easier having a local reference to WebBrowserClient
        webBrowserClient = clientManager.browserClient;
    }

    //Call this from were ever, and it will load 'https://voltstro.dev'
    public void LoadMySite()
    {
        webBrowserClient.LoadUrl("https://voltstro.dev");
    }
}

Samples

You can import one of the samples UWB includes via the package manager. Open the Package Manager and go to the UWB package, you will see the samples and be able to import them into your project.

UPM Sample