您好,登錄后才能下訂單哦!
這篇文章給大家分享的是有關(guān)Unity中如何內(nèi)嵌網(wǎng)頁(yè)插件UniWebView的內(nèi)容。小編覺(jué)得挺實(shí)用的,因此分享給大家做個(gè)參考,一起跟隨小編過(guò)來(lái)看看吧。
一、常見(jiàn)Unity中內(nèi)嵌網(wǎng)頁(yè)實(shí)現(xiàn)方式:
1、UnityWebCore只支持windows
2、Unity-Webview支持Android,IOS
3、UniWebView支持mac os,Android,IOS,WP8(2.0以后)
二、UniWebView 根據(jù)手機(jī)平臺(tái)調(diào)用相應(yīng)的WebView組件來(lái)顯示網(wǎng)頁(yè),支持和javascript的交互,不支持windows和editor上顯示。
1、下載并導(dǎo)入unitypackage
http://uniwebview.onevcat.com/
2、設(shè)置Webview,加載并顯示網(wǎng)頁(yè)
// 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<UniWebView>(); // 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(5,5,5,5); // 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、網(wǎng)址解析
uniwebview://move?direction=up&distance=1會(huì)解析成
path = "move" args = { direction = "up", distance = "1" }
4、監(jiān)聽(tīng)消息
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" } }
感謝各位的閱讀!關(guān)于“Unity中如何內(nèi)嵌網(wǎng)頁(yè)插件UniWebView”這篇文章就分享到這里了,希望以上內(nèi)容可以對(duì)大家有一定的幫助,讓大家可以學(xué)到更多知識(shí),如果覺(jué)得文章不錯(cuò),可以把它分享出去讓更多的人看到吧!
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。