Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to embed the web page plug-in UniWebView in Unity

2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/01 Report--

This article is about how to embed the web plug-in UniWebView in Unity. The editor thinks it is very practical, so share it with you as a reference and follow the editor to have a look.

1. Common implementation methods of embedded web pages in Unity:

1. UnityWebCore only supports windows.

2. Unity-Webview supports Android,IOS.

3. UniWebView supports mac os,Android,IOS,WP8 (after 2.0)

Second, UniWebView calls the corresponding WebView components to display web pages according to the mobile platform, which supports interaction with javascript, but does not support display on windows and editor.

1. Download and import unitypackage

Http://uniwebview.onevcat.com/

2. Set up Webview, load and display web pages

/ / Find the UniWebView component on the gameObject.// It is supposed you have already dragged this script to the same gameObject which UniWebView on.// Or you will get a null exception: (_ webView = GetComponent (); / / Listen to some event of UniWebView_webView.OnLoadComplete + = OnLoadComplete;_webView.OnReceivedMessage + = OnReceivedMessage;_webView.OnEvalJavaScriptFinished + = OnEvalJavaScriptFinished;// Almost full screen but 5 points gap in each edge._webView.insets = new UniWebViewEdgeInsets / / Set a url string to load_webView.url = "http://uniwebview.onevcat.com/demo/index.html";// Tell the web view begin to load the url just set._webView.Load (); / / Then wait for the OnLoadComplete event /... / / The listening method of OnLoadComplete method.void OnLoadComplete (UniWebView webView, bool success, string errorMessage) {if (success) {/ / Great, everything goes well. Show the web view now. WebView.Show ();} else {/ / Oops, something wrong. Debug.LogError ("Something wrong in web view loading:" + errorMessage);}}

3. Web address resolution

Uniwebview://move?direction=up&distance=1 will be parsed into

Path = "move" args = {direction = "up", distance = "1"}

4. Monitor messages

Void OnReceivedMessage (UniWebView webView, UniWebViewMessage message) {Debug.Log (message.rawMessage); if (string.Equals (message.path, "move") {/ / It is time to move! / / In this example: / / message.args ["direction"] = "up" / / message.args ["distance"] = "1"}} Thank you for reading! This is the end of the article on "how to embed the web plug-in UniWebView in Unity". I hope the above content can be of some help to you, so that you can learn more knowledge. if you think the article is good, you can share it out for more people to see!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report