gree / unity-webview

zlib License
2.29k stars 691 forks source link

Call Unity Method from javascript or vice-versa #412

Open MuhammadFaizanKhan opened 5 years ago

MuhammadFaizanKhan commented 5 years ago

This is not an issue it just a question. I am confuse about unity webview plugin that why should we use it? Just for opening a site in unity android application? Actually I am looking for a way to open my andriod app from a javascript(a seprate web) then i call javascript method or javascript call my app(unity apk) method from there.

KojiNakamaru commented 5 years ago

Just for opening a site in unity android application?

Basically yes.

a way to open my andriod app from a javascript(a seprate web)

This can be done by custom URL schemes, etc. cf. https://medium.com/@ageitgey/everything-you-need-to-know-about-implementing-ios-and-android-mobile-deep-linking-f4348b265b49

i call javascript method or javascript call my app(unity apk) method from there.

If you mean the target is the original separate web browser, I guess it is difficult. The WKWebView/UIWebView/WebView opened by this plugin can communicate with the unity side through EvaluateJS() (unity -> javascript) and Unity.call() (javascript -> unity).

MuhammadFaizanKhan commented 5 years ago

I mean that suppose you have a url xyz.com where a JavaScript file that have a method

function JSMethodSample(){
}

That method you want to call in your Unity Application?

Or suppose you have a unity application (APK) and it has class xyz where a method is

public void UnityAPKFunc(){
}

and you want to call it from a website js.

KojiNakamaru commented 5 years ago

Could you please check the sample app in the repository, then you can understand what I described above.