Embed js lib

Hello,

I have test how to create a js file and call function from C#. Ok good. (Unity - Manual: Interaction with browser scripting)

Now I have a complete js lib to import in unity. I want to use function in it.

Then I have test by adding this js file and create a wrapper .jslib . But does not seems to be the good option.

How to add a js lib and use its function from unity?

If i add .js in Assets folder unity complain. If I do not add it my wrapper .jslib cannot compile.

I need it for a 3rd party lib write in JS because their unity C# SDK use Thread.

I have try with Application.ExternalCall that call their function but no return possible. And what if I add SendMessage in their 3rd party lib which return js functions ?

Hello TobyKaos.

If you want to embed pure JavaScript into your WebGL application, use the .jspre file extension for it (and not the .js which is already reserved for UnityScript). All the .jspre code is added to the JavaScript build and can be called from a .jslib plugin.

Alternatively you can load the 3rd party JavaScript directly from the index.html (i.e. create your own WebGL template with a added before the %UNITY_WEBGL_LOADER_GLUE%)

1 Like

Thank you alexsuvorov I have make a WebGl teamplate and all is ok now. This is really great :slight_smile: