why don't fire Unity.call(method, msg) on JS?
Nobody has claimed this yet.
- Dominant language
- Objective-C++
- Stars
- 2.7k
- Forks
- 734
- Avg merge
- 11h 39m
- Merged PRs (30d)
- 1
Description
my html code
<script>Unity.call('CodeFromWeb','SOMETHING');</script>my unity C# code
public void CodeFromWeb(string msg)
{
// SOMETHING.....................
}
I need to working this code. not by CallFromJS!
CWebViewPluginInterface
public void call(final String method, final String message) {
final Activity a = UnityPlayer.currentActivity;
a.runOnUiThread(new Runnable() {public void run() {
if (mPlugin.IsInitialized()) {
UnityPlayer.UnitySendMessage(mGameObject, method, message);
}
}});
}
ps.
my webview initializing code is same to sample's one. i don't forget this.
IEnumerator Start()
{
webViewObject = gameObject.AddComponent<WebViewObject>();
webViewObject.Init(
cb: (msg) =>
{
Debug.Log(string.Format("CallFromJS[{0}]", msg));
},
err: (msg) =>
{
Debug.Log(string.Format("CallOnError[{0}]", msg));
},
started: (msg) =>
{
Debug.Log(string.Format("CallOnStarted[{0}]", msg));
StopCoroutine(UpdateSlider());
StartCoroutine(UpdateSlider());
},
ld: (msg) =>
{
Debug.Log(string.Format("CallOnLoaded[{0}]", msg));
#if !UNITY_ANDROID
// NOTE: depending on the situation, you might prefer
// the 'iframe' approach.
// cf. https://github.com/gree/unity-webview/issues/189
#if true
webViewObject.EvaluateJS(@"
if (window && window.webkit && window.webkit.messageHandlers && window.webkit.messageHandlers.unityControl) {
window.Unity = {
call: function(msg) {
window.webkit.messageHandlers.unityControl.postMessage(msg);
}
}
} else {
window.Unity = {
call: function(msg) {
window.location = 'unity:' + msg;
}
}
}
");
#else
webViewObject.EvaluateJS(@"
if (window && window.webkit && window.webkit.messageHandlers && window.webkit.messageHandlers.unityControl) {
window.Unity = {
call: function(msg) {
window.webkit.messageHandlers.unityControl.postMessage(msg);
}
}
} else {
window.Unity = {
call: function(msg) {
var iframe = document.createElement('IFRAME');
iframe.setAttribute('src', 'unity:' + msg);
document.documentElement.appendChild(iframe);
iframe.parentNode.removeChild(iframe);
iframe = null;
}
}
}
");
#endif
#endif
webViewObject.EvaluateJS(@"Unity.call('ua=' + navigator.userAgent)");
},
//ua: "custom user agent string",
enableWKWebView: true);
am i check some more?
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Read CWebViewPluginInterface.call and the shown Unity initialization, then reproduce the JavaScript call on the target platform. Trace whether Unity.call and the C# CodeFromWeb callback are reached; done means the callback receives SOMETHING without relying on CallFromJS.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- csharp, java, javascript, unity
- Domain
- mobile-dev, web-dev
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100