I’m wanting to invoke the method “invokeMyMethod” which is defined and loaded by the html from somedomain.com
How would I call this method?
I’ve got a jslib like so:
Assets/Plugins/WebGL/applixir.jslib
mergeInto(LibraryManager.library, {
MyFunction: function () {
var options = {
x: 1,
y: 1,
z: 3,
};
invokeMyMethod(options); // hoping magic would make this find the correct method to call.
},
});
And then I include that the standard way:
public class TestButton : MonoBehaviour
{
[DllImport("__Internal")]
private static extern void PlayVideo();
public void onClick()
{
PlayVideo();
}
}
But obviously this is not compiling since there are undefined references in the jslib…
I think I’ve actually got a little further today. What I have:
JSLIB:
var MyPlugin = {
$impl: {},
statusCallback: function (status) {
console.log('status:', status);
var iresult = 0;
Runtime.dynCall('vi', window.unityMethodCallback, [iresult]);
console.log('status done:', status);
},
ShowVideo__deps: [
'$impl',
'statusCallback'
],
ShowVideo: function (devId, callback) {
var local_options = {
devId: devId,
adStatusCb: statusCallback /* 3rd party will invoke this callback */
};
console.log(local_options);
// Save the Unity method callback reference as a global to use in statusCallback when invked by 3rd party
window.unityMethodCallback = callback;
//
// I have tried simply invoking this here to test
//
//Runtime.dynCall('vi', window.unityMethodCallback, [88]);
//
// Invoke the third party, shows an iframe over ours and then calls back to callback passed in options.
//
invokeThirdPartyScriptThatWillCallMeBackLater(local_options);
}
};
autoAddDeps(MyPlugin, '$impl');
mergeInto(LibraryManager.library, MyPlugin);
I expect I don’t need the manually added __deps since I’m auto adding underneath, but it’s where I’m at with trying things.
This builds and my calls make it through to ShowVideo in jslib, but trying to reference statusCallback from ShowVideo always gives me an undefined reference error (eg: ReferenceError: statusCallback is not defined at _ShowVideo)
Any ideas?
Edit: I just noticed that ShowVideo becomes _ShowVideo. I’m now building trying the same but referencing _statusCallback - building now … … …
@larku I know this is about 8 months old, but I was wondering if you could clarify a bit what you actually did to get things working. I am having the exact same problem you describe, and I’m at the point where I get the “ReferenceError: method is not defined” error message. Where exactly did you place an underscore, and how did you find ShowVideo becoming _ShowVideo?
There are a few other places I’ve found online, namely this post, which also hint at needing to prefix your calls to methods defined elsewhere in the jslib with an underscore. But, to use your above code as an example, if I change line 22 to be: adStatusCb: _statusCallback then I still get “_statusCallback is not defined”.
Were you able to remove the explicit __deps declaration with autoAddDeps at the bottom?