OneJS for Editor UI is still a work in progress, but we’re pretty excited about its potential. The idea of a full JS workflow inside the Unity Editor opens up a lot of cool possibilities. Right now, the most useful thing we’ve got is the scratchpad()
utility.
You can also build custom Editor Windows and Inspectors with OneJS. We’re still figuring out the best way to handle those, so if you’ve got any feedback or ideas, hit us up on Discord!
Setup
Setting up OneJS for Editor UI is pretty straightforward, very similar to setting up ScriptEngine
the first time.
You can have multiple
EditorScriptEngine
ScriptableObjects in your project. Just make sure they have different folder names (default is “Editor”).
- Create an
EditorScriptEngine
ScriptableObject via the Project Create menuOneJS > EditorScriptEngine
. - Click on the
Initialize
button. - Click on
Open VSCode
. - In VSCode terminal, run
npm run setup
And there you go! Now you can ctrl+shift+b
to start all VSCode tasks like normal and your Javascript will be LiveReloaded in the Unity Editor everytime you make a change.
Example Usage
For example, change your index.tsx
to this:
import { Application, DeviceType, Rendering, RuntimePlatform, Screen, SystemInfo, SystemLanguage } from "UnityEngine"
function logSystemInfo() {
console.log(`Unity Version: ${Application.unityVersion}`)
console.log(`Platform: ${RuntimePlatform[Application.platform]}`)
console.log(`Language: ${SystemLanguage[Application.systemLanguage]}`)
console.log(`Operating System: ${SystemInfo.operatingSystem}`)
console.log(`Device Model: ${SystemInfo.deviceModel}`)
console.log(`Device Type: ${DeviceType[SystemInfo.deviceType]}`)
console.log(`Processor: ${SystemInfo.processorType} ({SystemInfo.processorCount} cores)`)
console.log(`RAM: ${SystemInfo.systemMemorySize} MB`)
console.log(`GPU: ${SystemInfo.graphicsDeviceName}`)
console.log(`GPU Memory: ${SystemInfo.graphicsMemorySize} MB`)
console.log(`Graphics API: ${Rendering.GraphicsDeviceType[SystemInfo.graphicsDeviceType]}`)
console.log(`Screen: ${Screen.currentResolution.width}x${Screen.currentResolution.height} @ ${Screen.currentResolution.refreshRateRatio}Hz`)
console.log(`DPI: ${Screen.dpi}`)
}
logSystemInfo()
As you can see, you can use this to test Unity/C# code on the fly in the Editor using JavaScript. It’s a super handy way to try out Unity APIs and see how they work without having to compile and domain reload a C# script.
Next up, we’ll introduce the scratchpad
utility, which allows you to quickly load any JSX element in a Unity Tab/Window.