Integrating Custom Module with Unity Exporter

I’m currently working on a project where I’ve developed a custom module, let’s call it BLABLA.GUI, whith custom type extending BABYLON.GUI. This module is contained within a file named “blabla.gui.js”. I’m looking to utilize this module in conjunction with the Unity exporter. My main goal is to streamline the process without having to export all of my TypeScript classes or modify the existing code extensively with the

module XXXX {
...
    const  v = new BABYLON.Vector3(0,0,0);
...
}

pattern.

Could anyone provide guidance or suggestions on how to effectively integrate BLABLA.GUI with the Unity exporter to achieve this?

according to the documentation

Native JavaScript Libraries (renamed to .bjs) that are included anywhere in the Assets folder will be packaged up and included in your project script file

however when putting the file into a folder in the Assets and trying to reference any of the class into my typescript, this not work

const c = new BLABLA.GUI.Component(..)

Failed to find the BLABLA.

Do i need a specific tsconfig setup to generate my module to be compatible ?
Do i need to provide the d.ts types somehow ?

Thank you in advance for your assistance!

2 Likes

@mackey the daddy of the exporter might have some ideas

I have same question. Any idea?

Hi all, just following up on my previous query (along with @Lukas_Make_Games ) about the Unity Exporter project extension. Noticed it’s been a few days without a single response, even after @sebavan ping to the creator. I understand it’s not an official Babylonjs tools, but any updates would be greatly appreciated.
Thanks!

Hi, I was trying to integrate external library to the Unity-Exporter and I have to find a workaround. I let you here, in case it’s useful to you:

//otherScript.js
var MyGlobalVar = function () {
  //...isolated scope
  myVar=otherFunction(){
  //..
  return{
      myVar:myVar
}}

then in the PROJECT module, to access the isolated scoped function:

//scriptComponent.ts
//..
//@ts-ignore
let tempGlobal = MyGlobalVar();

module PROJECT{
   tempGlobal.myVar()
}

It would be easier if we could import modules…

1 Like

@MackeyK24 was not pinged cause I messed up in his pseudo on the previous message… Now he should be :slight_smile: but please bear with him as he might be focused on other things or be OOF this week :slight_smile:

You could have always done your extension under the project module scope.

module PROJECT{
class BLAHBHElement extends BABYLON.GUI.something{}
}

Hey guys… So the babylon toolkit using regular script tags. I dont really like importing modules. If you look at the exported engine.html page that is generated for you. you see all the scripts that get loaded for that project. You can customize a copy of engine.html and save it in the /Assets/[Config] folder and that custom engine.html will get used instead.

But it would be easier to just your custom class to the Unity Project. You can add .js, .ts and d.ts files to any folder in the Unity Project.

So you can generate declaration files for your component and add both the script and declaration files to your Unity Projects:

blabla.gui.js
blabla.gui.d.ts

Or you could create your custom gui component in the Unity Project like MyGuiComponent.ts like
@Pryme8 suggested:

module PROJECT {
    /**
     * Babylon TypeScript File
     * @script MyGuiComponent
     */
    export class MyGuiComponent extends BABYLON.GUI.Container {

    }
}
1 Like

Hey guys,

Thank you for taking the time to respond. I’ve already using the solutions you suggested. My question was bit different, so i assume importing module on the fly is not possible.
Thank’s again.

All the best.