#Importing JavaScript Libraries into Unity as a plugin

1 messages · Page 1 of 1 (latest)

sharp folio
#

Hello! I was reading over some documentation on using JavaScript libraries on the Web platform and was wondering what the process is to convert the existing files into the .jslib and .jspre files that Unity will be able to utilize.

steel lagoon
#

The process of creating a .jspre file should be just renaming the JS library file to have that extension

#

.jslib is then used as an interface to the library as per the manual

sharp folio
#

So then just change the extension for the existing library, and create a .jslib that calls the functions in the library?

How would you link the two, just have an import statement at the top of the .jslib?

steel lagoon
#

You can't use modules in plugins. They're limited to ES5

#

If you need ES6 you can include the libraries in the HTML template normally with <script> tags

sharp folio
#

So, if I have a function Foo in the existing library, how do I call it from the .jslib interface? Is it automatically added to the DOM (if that is the right term I am still new to web stuff)?

steel lagoon
#
mergeInto(LibraryManager.library, { Foo });
#

(Automatically added to the global scope, not DOM, but I get what you meant)

sharp folio
#

Got it, so just rename the file extension on the existing library, and then create an interface in the .jslib file calling the functions I want to use in the existing library.

That about cover it?

steel lagoon
#

That should be it