编辑器脚本
使用方法
- 注册至菜单栏
- 将脚本放入
Scripts/_Editor文件夹中 - 在脚本中导出
menuPath字符串,字符串值即为菜单栏中显示的名称,可用/分隔层级 - 如果需要给注册到菜单栏中的脚本加上图标,则需要先将图片导入编辑器转为
.tex格式,再将其放入Scripts/_Editor/Icons文件夹中,并将其命名为脚本中menuPath字符串值
- 将脚本放入
提示
注册的菜单栏项目需重启编辑器生效。
钩子
编辑器共提供了 13 个钩子,参见 BST/_Typings/editorApi/exportFuncs.d.ts。
使用 素材面板底部的 清除缓存 重新注册事件。
menuPath
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。