VanillaBox Console has been released! It's a free app that lets you quickly test out Unity runtime features. Check it out here!

Also, a newly revamped website with improved docs is coming soon. Stay tuned!

New features and bug fixes will land in the private github repo before becoming available on the Asset Store. To request access to the repo, please send an email or pm Singtaa#4915 on Discord with your Github username and OneJS Order/INV number.

Requirements

  • Unity.Mathematics
  • Unity Version 2021.3+ (for stable UI Toolkit)
  • Unity Version 2022.1+ (if you need to use UI Toolkit's Vector API)

Also Live Reload requires Run in Background to be turned ON in Player settings (under Resolution and Presentation). Depending on your Unity version or platform, this may or may not be ON by default. So it never hurt to double-check.

Quick Start

After downloading and importing OneJS from the Asset Store. You can just

  • Drag and drop the ScriptEngine prefab onto a new scene.
  • Enter Play mode.

In the console, if you see [index.js]: OneJS is good to go., then OneJS is all set. Refer to the included sample scene to see how Preact and UI Toolkit work together. The script(s) responsible for the sample scene are under {ProjectDir}/OneJS/Samples.

More Info

OneJS uses {ProjectDir}/OneJS as its working directory (NOTE: {ProjectDir} is not your Assets folder; it is one level above the Assets folder). So, you can safely check the OneJS folder into Version Control. When building for standalone, the scripts from {ProjectDir}/OneJS will be automatically bundled up and be extracted to {persistentDataPath}/OneJS at runtime. Refer to the Deployment page for more details on that.

The first time ScriptEngine runs, it will set up a few things automatically under {ProjectDir}/OneJS. These are:

  • A default tsconfig.json
  • A default .vscode/settings.json
  • A default index.js script (that just logs something to the console)
  • ScriptLib folder containing all the Javascript library files (and TS definitions) that are used by OneJS.
  • Samples folder containing some sample code you can look at.

These folders and files will be auto-generated if deleted. Sometimes it maybe helpful to manually delete them when upgrading major OneJS versions.

VSCode

{ProjectDir}/OneJS is the folder to open when using VSCode. Typescript (.ts and .tsx) is the recommended language to use with OneJS. To have VSCode continuously transpile TS to JS in watch mode, use Ctrl + Shift + B or Cmd + Shift + B and choose tsc: watch - tsconfig.json.

Do make sure that you have Typescript installed on your system (i.e. via npm install -g typescript)

You can, of course, just use plain .js and .jsx files as well. But do note that by default OneJS only support CommonJS modules (i.e. require() and module.exports). So if you want to use ES modules (i.e. import/export statements), Typescript is the way to go.

The default .vscode/settings.json will enable Explorer File Nesting for you, as well as some PowerShell settings for better usage on Windows.

{ // .vscode/settings.json
    "explorer.fileNesting.enabled": true,
    "explorer.fileNesting.expand": false,
    "explorer.fileNesting.patterns": {
        "*.ts": "${capture}.js, ${capture}.d.ts",
        "*.js": "${capture}.js.map, ${capture}.min.js, ${capture}.d.ts",
        "*.jsx": "${capture}.js",
        "*.tsx": "${capture}.ts, ${capture}.js, ${capture}.d.ts",
        "tsconfig.json": "tsconfig.*.json",
        "package.json": "package-lock.json, yarn.lock"
    },
    "terminal.integrated.profiles.windows": {
        "PowerShell": {
            "source": "PowerShell",
            "icon": "terminal-powershell",
            "args": [
                "-ExecutionPolicy",
                "Bypass"
            ]
        }
    },
    "terminal.integrated.defaultProfile.windows": "PowerShell"
}