Skip to content

Commit

Permalink
modified SampleWebView.cs to define Unity.call() in CallOnLoaded().
Browse files Browse the repository at this point in the history
  • Loading branch information
KojiNakamaru committed Aug 26, 2020
1 parent be56bcd commit 27f679a
Showing 1 changed file with 8 additions and 9 deletions.
17 changes: 8 additions & 9 deletions sample/Assets/Scripts/SampleWebView.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)");
},
Expand Down Expand Up @@ -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;
}
Expand Down

0 comments on commit 27f679a

Please sign in to comment.