- Home /
How to marshal a callback?
I'm trying to call a simple function with callback from JavaScript plugin. I have the following jslib
file:
var TestTimeout = {
SetTimeout: function(callback, time) {
setTimeout(callback, time);
}
};
mergeInto(LibraryManager.library, TestTimeout);
The corresponding C# definition is
public class TestTimeout {
public delegate void CallbackDelegate();
[DllImport("__Internal")]
public static extern void SetTimeout(CallbackDelegate callback, int time);
}
That gets called like
void Start() {
CSharp.SetTimeout(Callback, 3000);
}
[MonoPInvokeCallback(typeof(CSharp.CallbackDelegate))]
private static void Callback() {
Debug.Log("Test");
}
But when I do so and build for WebGL
target and run it from a simple server in Google Chrome 44, I can't recieve log message "Test", and even can't find logging call in code.
How do I properly call a JS function with callback?
Hi $$anonymous$$, I am doing exactly the same thing in my project and looking for solution. Did you already figured it out? if yes can you please post the solution here. Thanks
Your answer
Follow this Question
Related Questions
WebGL build .jspre javascript plugin - how do I call functions from page? 1 Answer
Calling a function from another function in webgl plugin 0 Answers
MissingMethodException with jslib calling c# functions 0 Answers
Unity WebGL calling a function from a jslib file in JavaScript(Vue) 0 Answers
Using unity as a library for creating windows, mac and web application 0 Answers