- Home /
Question by
Erethan · Jan 26, 2017 at 05:27 PM ·
c#javascriptplugincallback
Calling C# methods from jslib
The function below was written in a .jslib file using a Cross Domain Storage solution. It loads a string from a remote localStorage. The problem with that function is that it writes in the buffer before the callback function(data)
is fired so the return value is an empty string. How can I pass the information from data.value
to Unity? Is there a way to do a "inverse" external call to C#?
Load : function()
{
var returnStr = '';
xdLocalStorage.getItem("CardGameSave", function (data)
{
returnStr = data.value;
console.log('Data loaded: ' + data.value);
});
var buffer = _malloc(lengthBytesUTF8(returnStr) + 1);
writeStringToMemory(returnStr, buffer);
return buffer;
}
Comment