Unity UniWebViewのインラインWebプラグイン、Webページのズーム



Inline Web Plugin Unity Uniwebview



https://mp.weixin.qq.com/s/cesU-Jlxf_a_lGxIv6q_yQ

開発者クラブを転載し、改訂



https://docs.uniwebview.com/api/

プラグインのドキュメント、百度翻訳を使用して表示できます



using System.Collections using System.Collections.Generic using UnityEngine public class TestWebView : MonoBehaviour { private UniWebView uniWebView public RectTransform viewImage public UniWebView GetUniWebView { get { if (uniWebView == null) { uniWebView = GameObject.FindObjectOfType() if (uniWebView == null) { GameObject webViewGameObject = GameObject.Find('UniWebView') if (webViewGameObject == null) webViewGameObject = new GameObject('UniWebView') uniWebView = webViewGameObject.AddComponent() uniWebView.ReferenceRectTransform = viewImage / / Set whether the web view supports zoom permissions to change the content size. Zoom is not supported by default uniWebView.SetZoomEnabled(true) } uniWebView.OnMessageReceived += OnMessageReceived uniWebView.OnPageStarted += OnPageStarted uniWebView.OnPageFinished += OnPageFinished uniWebView.OnKeyCodeReceived += OnKeyCodeReceived uniWebView.OnPageErrorReceived += OnPageErrorReceived uniWebView.OnShouldClose += OnShouldClose uniWebView.SetBackButtonEnabled(false)// Back button Physical button } 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) } private void OnMessageReceived(UniWebView webView, UniWebViewMessage message) { Debug.Log('OnMessageReceived :' + message.RawMessage) if (message.Path.Equals('game')) { var score = message.Args['score'] var name = message.Args['name'] Debug.Log('Your final score is: ' + score + 'name :' + name) 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.baidu.com' private void OnGUI() { url = GUILayout.TextField(url, GUILayout.Width(250), GUILayout.Height(80)) if (GUILayout.Button('Load', GUILayout.Height(80))) { OnLoaded() } //button one refreshes the webpage if (GUILayout.Button('ReLoad', GUILayout.Height(80))) { OnReLoaded() } // button two 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) } 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) } }) } } }