跳转到内容

编辑器脚本 ​

使用方法 ​

  1. 参考 模板 和 示例 的书写方式编写好脚本
  2. 将脚本 导入 编辑器
  3. 选中需要执行的脚本,在 检视器 中点击 执行 按钮
  • 注册至菜单栏
    1. 将脚本放入 Scripts/_Editor 文件夹中
    2. 在脚本中导出 menuPath 字符串,字符串值即为菜单栏中显示的名称,可用 / 分隔层级
    3. 如果需要给注册到菜单栏中的脚本加上图标,则需要先将图片导入编辑器转为 .tex 格式,再将其放入 Scripts/_Editor/Icons 文件夹中,并将其命名为脚本中 menuPath 字符串值

提示

注册的菜单栏项目需重启编辑器生效。

钩子 ​

编辑器共提供了 13 个钩子,参见 BST/_Typings/editorApi/exportFuncs.d.ts。

使用 素材面板底部的 清除缓存 重新注册事件。

ts
export const menuPath: string

用于将脚本注册至菜单栏。

execute ​

ts
export const execute: () => void

点击执行按钮时执行。

onTick ​

ts
export const onTick: () => void

每隔 1s 执行一次。

onBeforeTestMap ​

ts
export const onBeforeTestMap: () => void

在测试地图前执行。

onAfterTestMap ​

ts
export const onAfterTestMap: () => void

在测试地图后执行。

onBeforeExportMap ​

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

在导出地图前执行。

  • filePath:导出地图的系统路径

onAfterExportMap ​

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

在导出地图后执行。

  • filePath:导出地图的系统路径

onBeforeOpenScene ​

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

在打开场景前执行。

  • scenePath:场景的 BME 路径

onAfterOpenScene ​

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

在打开场景后执行。

  • scenePath:场景的 BME 路径

onBeforeSaveScene ​

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

在保存场景前执行。

  • scenePath:场景的 BME 路径

onAfterSaveScene ​

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

在保存场景后执行。

  • scenePath:场景的 BME 路径

onBeforeImportAsset ​

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

在导入资源前执行。

  • filePath:资源的系统路径
  • assetPath:资源的 BME 路径

onAfterImportAsset ​

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

在导入资源后执行。

  • filePath:资源的系统路径
  • assetPath:资源的 BME 路径

模块 ​

编辑器共提供了以下 6 个模块:

具体参见 BST/_Typings/editorApi/modules。

使用如下语法导入模块:

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

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

提示

如需导入工程内的自制模块,请使用 BME 的资源路径,如:

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

注意

  • 只能导入 _Editor 文件夹中的模块(不包括 其中的子目录)。
  • 此处的 .js 后缀 可以 被省略。

模板 ​

参见 BST/Templates/editorTemplate.js。

示例 ​

参见 BST/Samples/editorSamples。

基于 MIT 许可发布