Essential Kit
Loading...
Searching...
No Matches
WebViewsealed

Provides a cross-platform interface to display web contents inside your application. More...

Public Member Functions

void Show ()
 Displays the webview on the top of Unity view.
 
void Hide ()
 Hides the web view.
 
void LoadURL (URLString url)
 Connects to a given URL and asynchronously loads the content.
 
void LoadHtmlString (string htmlString, URLString? baseURL=null)
 Loads the webpage contents.
 
void LoadData (byte[] data, string mimeType, string textEncodingName, URLString? baseURL=null)
 Loads the webpage contents from specified file.
 
void Reload ()
 Reloads the current page.
 
void StopLoading ()
 Stops loading the current page contents.
 
void RunJavaScript (string script, EventCallback< WebViewRunJavaScriptResult > callback)
 Executes a JavaScript string.
 
void AddURLScheme (string urlScheme)
 Registers the specified scheme, after which web view will start to listen for custom URL.
 
void ClearCache ()
 Clears all stored cached URL responses.
 

Static Public Member Functions

static WebView CreateInstance (WebViewUnitySettings settings=null)
 Initializes a new instance of the MessageComposer class.
 

Properties

string URL [get]
 The active URL. (read-only)
 
string Title [get]
 The page title. (read-only)
 
Rect Frame [get, set]
 The frame rectangle describes the webview’s position and size.
 
WebViewStyle Style [get, set]
 An enum value that determines the appearence of webview.
 
bool AutoShowOnLoadFinish [get, set]
 A boolean value indicating whether webview can auto show itself when load request is finished.
 
bool ScalesPageToFit [get, set]
 A boolean value indicating whether web view scales webpages to fit the view and the user can change the scale.
 
bool CanBounce [get, set]
 A Boolean value that controls whether the web view bounces past the edge of content and back again.
 
Color BackgroundColor [get, set]
 The background color of the webview.
 
double Progress [get]
 The value indicates the progress of load request.
 
bool IsLoading [get]
 A boolean value indicating whether this webview is loading content.
 
bool JavaScriptEnabled [get, set]
 A boolean value indicating whether this webview allows java script execution.
 

Events

static Callback< WebViewOnShow
 Event that will be called when webview is first displayed.
 
static Callback< WebViewOnHide
 Event that will be called when webview is dismissed.
 
static Callback< WebViewOnLoadStart
 Event that will be called when web view begins load request.
 
static EventCallback< WebViewOnLoadFinish
 Event that will be called when web view has finished loading.
 
static Callback< string > OnURLSchemeMatchFound
 Event that will be called when web view has finished loading.
 

Detailed Description

To do so, drag and drop the WebView prefab into scene heirarchy, which is placed under folder Assets/VoxelBusters/NativePlugins/Prefab. And then send it a request to display web content. You can also use this class to move back and forward in the history, just like web browser by setting control type to eWebviewControlType.TOOLBAR.

The following code illustrates how to load webpage using web view.

using UnityEngine;
using System.Collections;
public class ExampleClass : MonoBehaviour
{
public WebView m_webView;
private void Start()
{
// set web view properties
m_webView = WebView.CreateInstance();
m_webView.SetFullScreen();
// start request
m_webView.LoadURL(new URLString("https://www.google.com"));
}
private void OnEnable()
{
// registering for event
WebView.OnShow += OnShow;
WebView.OnHide += OnHide;
WebView.OnLoadStart += OnLoadStart;
WebView.OnLoadFinish += OnLoadFinish;
}
private void OnDisable()
{
// unregistering event
WebView.OnShow -= OnShow;
WebView.OnHide -= OnHide;
WebView.OnLoadStart -= OnLoadStart;
WebView.OnLoadFinish -= OnLoadFinish;
}
private void OnShow(WebView result)
{
if (m_webView == result)
{
Debug.Log("Showing webview.");
}
}
private void OnHide(WebView result)
{
if (m_webView == result)
{
Debug.Log("Hiding webview.");
}
}
private void OnLoadStart(WebView result)
{
if (m_webView == result)
{
Debug.Log("Started loading request with url:" + m_webView.URL);
}
}
private void OnLoadFinish(WebView result, Error error)
{
if (m_webView == result)
{
if (error == null)
{
Debug.Log("Webview did finish loading request successfully.");
} <br>
else
{
Debug.Log("Webview did fail to load request. Error: " + error.Description);
}
}
}
}
Provides a cross-platform interface to display web contents inside your application.
Definition WebView.cs:105
static WebView CreateInstance(WebViewUnitySettings settings=null)
Initializes a new instance of the MessageComposer class.
Definition WebView.cs:439
void LoadURL(URLString url)
Connects to a given URL and asynchronously loads the content.
Definition WebView.cs:541
string URL
The active URL. (read-only)
Definition WebView.cs:152
Namespace for essential kit features. You need to import this namespace along with VoxelBusters....
Definition AddressBook.cs:8
Struct value to represent the location of a resource, such as an item on a remote server or the path ...
Definition URLString.cs:12

Member Function Documentation

◆ LoadURL()

void LoadURL ( URLString url)
Parameters
urlA URL identifying the location of the content to load.
Note
Don’t use this method to load local HTML files, instead use LoadHtmlString(string, URLString).

References URLString.IsValid, and URLString.ToString().

◆ LoadHtmlString()

void LoadHtmlString ( string htmlString,
URLString? baseURL = null )
Parameters
htmlStringThe contents of the webpage.
baseURLThe base URL for the content.

◆ LoadData()

void LoadData ( byte[] data,
string mimeType,
string textEncodingName,
URLString? baseURL = null )
Parameters
dataThe data to use as the contents of the webpage.
mimeTypeThe MIME type of the content.
textEncodingNameThe content's character encoding name.
baseURLThe base URL for the content.

Referenced by WebViewExtensions.LoadTexture().

◆ RunJavaScript()

void RunJavaScript ( string script,
EventCallback< WebViewRunJavaScriptResult > callback )
Parameters
scriptThe JavaScript string to evaluate.
callbackCallback method that will be invoked after operation is completed.

◆ AddURLScheme()

void AddURLScheme ( string urlScheme)

This approach is used for communicating web view with Unity. When web view starts loading contents, it will check against registered schemes. And incase if a match is found, web view will raise DidReceiveMessageEvent along with URL information.

Parameters
urlSchemeThe scheme name of the URL.