日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

UniWebView 3 使用心得

發布時間:2023/12/9 编程问答 40 豆豆
生活随笔 收集整理的這篇文章主要介紹了 UniWebView 3 使用心得 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

基于 UniWebView 3

官網教程 點擊打開鏈接

最新版 插件下載鏈接

using System.Collections; using System.Collections.Generic; using UnityEngine;public class WebViewController : MonoBehaviour {private UniWebView uniWebView;public RectTransform viewImage;public UniWebView GetUniWebView{get{if (uniWebView == null){uniWebView = GameObject.FindObjectOfType<UniWebView>();if (uniWebView == null){GameObject webViewGameObject = GameObject.Find("UniWebView");if (webViewGameObject == null)webViewGameObject = new GameObject("UniWebView");uniWebView = webViewGameObject.AddComponent<UniWebView>();uniWebView.ReferenceRectTransform = viewImage;}uniWebView.OnMessageReceived += OnMessageReceived;uniWebView.OnPageStarted += OnPageStarted;uniWebView.OnPageFinished += OnPageFinished;uniWebView.OnKeyCodeReceived += OnKeyCodeReceived;uniWebView.OnPageErrorReceived += OnPageErrorReceived;uniWebView.OnShouldClose += OnShouldClose;uniWebView.SetBackButtonEnabled(false);// 回退鈕 物理按鍵}return uniWebView;}}private void OnPageErrorReceived(UniWebView webView, int errorCode, string errorMessage){Debug.Log("OnPageErrorReceived :" + string.Format("errorCode:{0},errorMessage{1}", errorCode, errorMessage));}private void OnKeyCodeReceived(UniWebView webView, int keyCode){Debug.Log("OnKeyCodeReceived keycode:" + keyCode);}private void OnPageFinished(UniWebView webView, int statusCode, string url){Debug.Log("OnPageFinished statusCode:" + string.Format("statusCode:{0},url{1}", statusCode, url));}private void OnPageStarted(UniWebView webView, string url){Debug.Log("OnPageStarted " + url);}///JS 調用 untiy3Dprivate void OnMessageReceived(UniWebView webView, UniWebViewMessage message){Debug.Log("OnMessageReceived :" + message.RawMessage);// if (message.Path.Equals("game-over")) {// var score = message.Args["score"];// Debug.Log("Your final score is: " + score);//// // Restart the game after 3 second// Invoke("OnReLoaded", 3.0f);// }if (message.Path.Equals("game")){var score = message.Args["score"];var name = message.Args["name"];Debug.Log("Your final score is: " + score + "name :" + name);// Restart the game after 3 second//Invoke("OnReLoaded", 3.0f);if (GetUniWebView.isActiveAndEnabled){string content = string.Format("openParamOne({0});", int.Parse(score) * 2 + int.Parse(name) * 1);GetUniWebView.EvaluateJavaScript(content, (payload) => {if (payload.resultCode.Equals("0")){Debug.Log("Game Started!=========>");}else{Debug.Log("Something goes wrong: " + payload.data);}});}}}private bool OnShouldClose(UniWebView webView){webView.CleanCache();webView = null;return true;}private string url = "http://www.0000.com/TWeb.aspx";private void OnGUI(){url = GUILayout.TextField(url, GUILayout.Width(250), GUILayout.Height(80));if (GUILayout.Button("Load", GUILayout.Height(80))){OnLoaded();}if (GUILayout.Button("ReLoad", GUILayout.Height(80))){OnReLoaded();}if (GUILayout.Button("Close", GUILayout.Height(80))){OnClose();}if (GUILayout.Button("Call JS", GUILayout.Height(80))){OnCallJavaScript();}if (GUILayout.Button("GoBack", GUILayout.Height(80))){if (GetUniWebView.CanGoBack){GetUniWebView.GoBack();} }if (GUILayout.Button("GoForward", GUILayout.Height(80))){if (GetUniWebView.CanGoForward){GetUniWebView.GoForward();}}}private void OnLoaded(){GetUniWebView.Load(url);GetUniWebView.Show();}private void OnReLoaded(){if (GetUniWebView.isActiveAndEnabled){GetUniWebView.Reload();}}private void OnClose(){GetUniWebView.Hide();Destroy(GetUniWebView.gameObject);}///調用 JS 代碼private void OnCallJavaScript(){if (GetUniWebView.isActiveAndEnabled){GetUniWebView.EvaluateJavaScript("openParam();", (payload) => {if (payload.resultCode.Equals("0")){Debug.Log("Game Started!");}else{Debug.Log("Something goes wrong: " + payload.data);}});}// if (GetUniWebView.isActiveAndEnabled) // {// string content = string.Format ("openParam({0});", int.Parse(score) * 2 + int.Parse(name) * 1);// GetUniWebView.EvaluateJavaScript(content, (payload)=>{// if (payload.resultCode.Equals("0")) {// Debug.Log("Game Started!");// } else {// Debug.Log("Something goes wrong: " + payload.data);// }// });// }}}

插件下載鏈接

?

?

關于 JS 調用 Unity3D? 詳細:https://docs.uniwebview.com/guide/working-with-code.html

?

總結

以上是生活随笔為你收集整理的UniWebView 3 使用心得的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。