Giter VIP home page Giter VIP logo

garlicwebview-unity's Introduction

GarlicWebview

A simple webview plugin for unity3d engine.

Supports both Android and iOS.

Install

Download GarlicWebview-Unity.unitypackage file and import, then enjoy!

Android


dependencies {
    ...
    
    implementation 'com.android.support.constraint:constraint-layout:1.1.3'
    
    ...
}

iOS

  • Requires iOS version >= 9.0
  • This plugin uses WKWebView and built using Swift 5.

How to use

Callback Receiver

If you want to receive callbacks from webview, implement IGarlicWebviewCallback interface.


private class GarlicWebviewCallbackReceiver : IGarlicWebviewCallback
{
    public void onClose()
    {
        Debug.Log("GarlicWebview: onClose");
    }

    public void onPageFinished(string url)
    {
        Debug.Log("GarlicWebview: onPageFinished [" + url + "]");
    }

    public void onPageStarted(string url)
    {
        Debug.Log("GarlicWebview: onPageStarted [" + url + "]");
    }

    public void onReceivedError(string errorMessage)
    {
        Debug.Log("GarlicWebview: onReceivedError [" + errorMessage + "]");
    }

    public void onShow()
    {
        Debug.Log("GarlicWebview: onShow");
    }
}

Then, you can register your interface instance with GarlicWebview.Instance.SetCallbackInterface() method.


//Instantiate your callback receiver.
var callbackReceiver = new GarlicWebviewCallbackReceiver();
//...Then set receiver with SetCallbackInterface().
//Note : Initialization method will be automatically called when accesing GarlicWebview.Instance
GarlicWebview.Instance.SetCallbackInterface(callbackReceiver);

Webview Options

Functions below are used to set options for webview. You should call those functions after initialize webview, and before showing webview.

SetMargins(int left, int right, int top, int bottom)

Sets margins around webview. Units are in px. Example :


int marginPx = (int)GarlicUtils.DPToPx (30f);
GarlicWebview.Instance.SetMargins(marginPx, marginPx, marginPx, marginPx);

SetFixedRatio(int width, int height)

Webview will be shown in Fixed Ratio(Width:Height). Margins will also still be applied.

UnsetFixedRatio()

Call this function if you want to unset fixed ratio options.

Show Webview

Simply call GarlicWebview.Instance.Show().



using Garlic.Plugins.Webview;

...

void Start()
{
    var callbackReceiver = new GarlicWebviewCallbackReceiver();
    //Initialization method will be automatically called when accesing GarlicWebview.Instance
    GarlicWebview.Instance.SetCallbackInterface(callbackReceiver);
    GarlicWebview.Instance.Show("Your URL Here");
}

...

See GarlicWebviewSample project to learn more about this plugin. Tested on Samsung Galaxy s8, sample project built with Unity2017.4.26f1 LTS.

garlicwebview-unity's People

Contributors

garlicdipping avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.