Show / Hide Table of Contents

    Class WebView

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

    Inheritance
    System.Object
    WebView
    Namespace: VoxelBusters.EssentialKit
    Assembly: cs.temp.dll.dll
    Syntax
    public sealed class WebView : NativeFeatureBehaviour
    Examples

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

    using UnityEngine;
    using System.Collections;
    using VoxelBusters.EssentialKit;
    
    public class ExampleClass : MonoBehaviour 
    {
        private WebView m_webView;
    
        private void Start()
        {
            // set web view properties
            m_webView     = WebView.CreateInstance();
            m_webView.SetFullScreen();
    
            // start request
            m_webView.LoadURL(URLString.URLWithPath("http://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.");
                }   
                else
                {
                    Debug.Log("Webview did fail to load request. Error: " + error.Description);
                }
            }
        }
    }

    Properties

    AutoShowOnLoadFinish

    A boolean value indicating whether webview can auto show itself when load request is finished.

    Declaration
    public bool AutoShowOnLoadFinish { get; set; }
    Property Value
    Type Description
    System.Boolean

    BackgroundColor

    The background color of the webview.

    Declaration
    public Color BackgroundColor { get; set; }
    Property Value
    Type Description
    Color

    CanBounce

    A Boolean value that controls whether the web view bounces past the edge of content and back again.

    Declaration
    public bool CanBounce { get; set; }
    Property Value
    Type Description
    System.Boolean

    Frame

    The frame rectangle describes the webview’s position and size.

    Declaration
    public Rect Frame { get; set; }
    Property Value
    Type Description
    Rect

    IsLoading

    A boolean value indicating whether this webview is loading content.

    Declaration
    public bool IsLoading { get; }
    Property Value
    Type Description
    System.Boolean

    JavaScriptEnabled

    A boolean value indicating whether this webview allows java script execution.

    Declaration
    public bool JavaScriptEnabled { get; set; }
    Property Value
    Type Description
    System.Boolean

    Progress

    The value indicates the progress of load request.

    Declaration
    public double Progress { get; }
    Property Value
    Type Description
    System.Double

    ScalesPageToFit

    A boolean value indicating whether web view scales webpages to fit the view and the user can change the scale.

    Declaration
    public bool ScalesPageToFit { get; set; }
    Property Value
    Type Description
    System.Boolean

    Style

    An enum value that determines the appearence of webview.

    Declaration
    public WebViewStyle Style { get; set; }
    Property Value
    Type Description
    WebViewStyle

    Title

    The page title. (read-only)

    Declaration
    public string Title { get; }
    Property Value
    Type Description
    System.String

    UnitySettings

    Declaration
    public static WebViewUnitySettings UnitySettings { get; }
    Property Value
    Type Description
    WebViewUnitySettings

    URL

    The active URL. (read-only)

    Declaration
    public string URL { get; }
    Property Value
    Type Description
    System.String

    Methods

    AwakeInternal(Object[])

    Declaration
    protected override void AwakeInternal(object[] args)
    Parameters
    Type Name Description
    System.Object[] args

    ClearCache()

    Clears all stored cached URL responses.

    Declaration
    public void ClearCache()

    CreateInstance()

    Initializes a new instance of the MessageComposer class.

    Declaration
    public static WebView CreateInstance()
    Returns
    Type Description
    WebView

    DestroyInternal()

    Declaration
    protected override void DestroyInternal()

    GetFeatureName()

    Declaration
    protected override string GetFeatureName()
    Returns
    Type Description
    System.String

    Hide()

    Hides the web view.

    Declaration
    public void Hide()

    IsAvailable()

    Declaration
    public override bool IsAvailable()
    Returns
    Type Description
    System.Boolean

    LoadData(Byte[], String, String, Nullable<URLString>)

    Declaration
    public void LoadData(byte[] data, string mimeType, string textEncodingName, URLString? baseURL = default(URLString? ))
    Parameters
    Type Name Description
    System.Byte[] data
    System.String mimeType
    System.String textEncodingName
    System.Nullable<URLString> baseURL

    LoadHtmlString(String, Nullable<URLString>)

    Loads the webpage contents.

    Declaration
    public void LoadHtmlString(string htmlString, URLString? baseURL = default(URLString? ))
    Parameters
    Type Name Description
    System.String htmlString

    The contents of the webpage.

    System.Nullable<URLString> baseURL

    The base URL for the content.

    LoadURL(URLString)

    Connects to a given URL and asynchronously loads the content.

    Declaration
    public void LoadURL(URLString url)
    Parameters
    Type Name Description
    URLString url

    A URL identifying the location of the content to load.

    Remarks

    \note Don’t use this method to load local HTML files, instead use .

    Reload()

    Reloads the current page.

    Declaration
    public void Reload()

    RunJavaScript(String, EventCallback<WebViewRunJavaScriptResult>)

    Executes a JavaScript string.

    Declaration
    public void RunJavaScript(string script, EventCallback<WebViewRunJavaScriptResult> callback)
    Parameters
    Type Name Description
    System.String script

    The JavaScript string to evaluate.

    EventCallback<WebViewRunJavaScriptResult> callback

    Callback method that will be invoked after operation is completed.

    Show()

    Displays the webview on the top of Unity view.

    Declaration
    public void Show()

    StartInternal()

    Declaration
    protected override void StartInternal()

    StopLoading()

    Stops loading the current page contents.

    Declaration
    public void StopLoading()

    Events

    OnHide

    Event that will be called when webview is dismissed.

    Declaration
    public static event Callback<WebView> OnHide
    Event Type
    Type Description
    Callback<WebView>

    OnLoadFinish

    Event that will be called when web view has finished loading.

    Declaration
    public static event EventCallback<WebView> OnLoadFinish
    Event Type
    Type Description
    EventCallback<WebView>

    OnLoadStart

    Event that will be called when web view begins load request.

    Declaration
    public static event Callback<WebView> OnLoadStart
    Event Type
    Type Description
    Callback<WebView>

    OnShow

    Event that will be called when webview is first displayed.

    Declaration
    public static event Callback<WebView> OnShow
    Event Type
    Type Description
    Callback<WebView>
    Back to top Cross Platform Native Plugins 2.0 : Essential Kit from Voxel Busters