"Working Dir Rework" has landed in the private repo (also submitted to the Asset Store). You are now able to keep all your scripts under `{ProjectDir}/OneJS`. And the scripts will be automatically bundled into`{persistentDataPath}/OneJS` for Standalone builds. Docs here have been updated accordingly.

New features and bug fixes will land in the private github repo before becoming available on the Asset Store. To request access, 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
  • Unity Version 2022.1 (if you need to use UI Toolkit's Vector API)

Setting up OneJS

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. The script(s) responsible for the sample scene are under Addons/Sample (under your persistentDataPath).

Remember to change the Entry Script field of the Live Reload component (on the ScriptEngine prefab) accordingly for whichever script you want to run/live-reload.

ScriptEngine

ScriptEngine uses your project's persistentDataPath folder as its working directory. The first time it runs, ScriptEngine will set up a few things automatically in this directory. 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.
  • Addons folder containing some sample code you can look at.

Now you can use VSCode to open up your project's persistentDataPath folder. You can put your own scripts anywhere really, but we recommend to keep them under the Addons folder.

VSCode

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"
}

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.

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.