Skip to content

Editor Script ​

Usage ​

  1. Write the script by referring to the writing style of the Template and Example.
  2. Import the script into the editor.
  3. Select the script you want to execute and click the Execute button in the Inspector.
  • Register to the menu bar
    1. Place the script in the Scripts/_Editor folder.
    2. Export a menuPath string in the script. The string value will be the name displayed in the menu bar. You can use / to separate levels.
    3. If you need to add an icon to a script registered in the menu bar, you first need to import an image into the editor to convert it to .tex format, then place it in the Scripts/_Editor/Icons folder, and name it the same as the menuPath string value in the script.

TIP

Registered menu bar items require an editor restart to take effect.

Hooks ​

The editor provides a total of 13 hooks, see BST/_Typings/editorApi/exportFuncs.d.ts.

Use Clear Cache in the Assets panel to re-register events.

ts
export const menuPath: string

Used to register the script to the menu bar.

execute ​

ts
export const execute: () => void

Executed when the execute button is clicked.

onTick ​

ts
export const onTick: () => void

Executed every 1 second.

onBeforeTestMap ​

ts
export const onBeforeTestMap: () => void

Executed before testing the map.

onAfterTestMap ​

ts
export const onAfterTestMap: () => void

Executed after testing the map.

onBeforeExportMap ​

ts
export const onBeforeExportMap: (filePath: string) => void

Executed before exporting the map.

  • filePath: The system path of the exported map.

onAfterExportMap ​

ts
export const onAfterExportMap: (filePath: string) => void

Executed after exporting the map.

  • filePath: The system path of the exported map.

onBeforeOpenScene ​

ts
export const onBeforeOpenScene: (scenePath: string) => void

Executed before opening the scene.

  • scenePath: The BME path of the scene.

onAfterOpenScene ​

ts
export const onAfterOpenScene: (scenePath: string) => void

Executed after opening the scene.

  • scenePath: The BME path of the scene.

onBeforeSaveScene ​

ts
export const onBeforeSaveScene: (scenePath: string) => void

Executed before saving the scene.

  • scenePath: The BME path of the scene.

onAfterSaveScene ​

ts
export const onAfterSaveScene: (scenePath: string) => void

Executed after saving the scene.

  • scenePath: The BME path of the scene.

onBeforeImportAsset ​

ts
export const onBeforeImportAsset: (filePath: string, assetPath: string) => void

Executed before importing the asset.

  • filePath: The system path of the asset
  • assetPath: The BME path of the asset

onAfterImportAsset ​

ts
export const onAfterImportAsset: (filePath: string, assetPath: string) => void

Executed after importing the asset.

  • filePath: The system path of the asset
  • assetPath: The BME path of the asset

Modules ​

The editor provides the following 6 modules:

For details, see BST/_Typings/editorApi/modules.

To import modules, use the following syntax:

js
import {
  // modules
  editor,
  console,
  file,
  scene,
  dialogWindowManager,
  math,

  // basic data types
  Float2,
  Float3,
  Float4,
  Bool3,
  ColorRGBA,
  Trans,
  Quaternion,
} from "editorApi"

TIP

To import custom modules from within the project, please use BME's resource path, for example:

js
import { dotProduct } from "Scripts/_Editor/MathExtension.js"

WARNING

  • Only modules in the _Editor folder can be imported (excluding subdirectories).
  • The .js suffix can be omitted.

Template ​

See BST/Templates/editorTemplate.js.

Example ​

See BST/Samples/editorSamples.

Released under the MIT License.