From 27f679ab94734d7cd444e64d0d08eaaec49da4b6 Mon Sep 17 00:00:00 2001 From: Koji Nakamaru Date: Wed, 26 Aug 2020 13:49:25 +0900 Subject: [PATCH] modified SampleWebView.cs to define Unity.call() in CallOnLoaded(). --- sample/Assets/Scripts/SampleWebView.cs | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/sample/Assets/Scripts/SampleWebView.cs b/sample/Assets/Scripts/SampleWebView.cs index 1380fe8f..d9d9e29f 100644 --- a/sample/Assets/Scripts/SampleWebView.cs +++ b/sample/Assets/Scripts/SampleWebView.cs @@ -58,7 +58,7 @@ IEnumerator Start() ld: (msg) => { Debug.Log(string.Format("CallOnLoaded[{0}]", msg)); -#if UNITY_EDITOR_OSX || !UNITY_ANDROID +#if UNITY_EDITOR_OSX || (!UNITY_ANDROID && !UNITY_WEBPLAYER && !UNITY_WEBGL) // NOTE: depending on the situation, you might prefer // the 'iframe' approach. // cf. https://github.com/gree/unity-webview/issues/189 @@ -99,6 +99,13 @@ IEnumerator Start() } "); #endif +#elif UNITY_WEBPLAYER || UNITY_WEBGL + webViewObject.EvaluateJS( + "window.Unity = {" + + " call:function(msg) {" + + " parent.unityWebView.sendMessage('WebViewObject', msg)" + + " }" + + "};"); #endif webViewObject.EvaluateJS(@"Unity.call('ua=' + navigator.userAgent)"); }, @@ -166,14 +173,6 @@ IEnumerator Start() } else { webViewObject.LoadURL("StreamingAssets/" + Url.Replace(" ", "%20")); } - webViewObject.EvaluateJS( - "parent.$(function() {" + - " window.Unity = {" + - " call:function(msg) {" + - " parent.unityWebView.sendMessage('WebViewObject', msg)" + - " }" + - " };" + - "});"); #endif yield break; }