From e0d6e1645e4a0a13f1a82a5a3eab580c1d5da01e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Leslie=20Leigh=20=28=E6=9D=8E=E7=9A=84=E5=BA=8F=29?= Date: Wed, 30 Mar 2022 10:23:25 +0800 Subject: [PATCH] =?UTF-8?q?=20[Bug]=20=E6=94=AF=E6=8C=81=E5=9C=A8=E5=9C=BA?= =?UTF-8?q?=E6=99=AF=E8=84=9A=E6=9C=AC=E4=B8=AD=E5=AF=BC=E5=85=A5=E9=A1=B9?= =?UTF-8?q?=E7=9B=AE=E6=A8=A1=E5=9D=97=20(#38)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * 支持在场景脚本中导入项目模块 * 修复 setTimeout 应该从 node 里面导入的问题 --- .../programming/source/packer-driver/packer-driver.ts | 1 + app/builtin/scene/source/script/3d/manager/scripts.ts | 9 ++++++++- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/app/builtin/programming/source/packer-driver/packer-driver.ts b/app/builtin/programming/source/packer-driver/packer-driver.ts index 0beb8e45e77..516e4a256f3 100644 --- a/app/builtin/programming/source/packer-driver/packer-driver.ts +++ b/app/builtin/programming/source/packer-driver/packer-driver.ts @@ -23,6 +23,7 @@ import { ModLoOptions, ImportMap, } from '@cocos/creator-programming-mod-lo/lib/mod-lo'; +import { setTimeout } from 'timers'; const VERSION = '18'; diff --git a/app/builtin/scene/source/script/3d/manager/scripts.ts b/app/builtin/scene/source/script/3d/manager/scripts.ts index 09826f0d02c..d2e0644f5ab 100644 --- a/app/builtin/scene/source/script/3d/manager/scripts.ts +++ b/app/builtin/scene/source/script/3d/manager/scripts.ts @@ -12,6 +12,7 @@ import ps from 'path'; import { SourceMapSupport } from '@editor/lib-programming/dist/source-map-support'; import { QuickPackLoaderContext } from '@cocos/creator-programming-quick-pack/lib/loader'; import { sortPluginScripts, getPluginScriptDependencies } from '@editor/lib-programming/dist/executor/sort-plugin-scripts'; +import { pathToFileURL } from 'url'; /** * 异步迭代。有以下特点: @@ -129,7 +130,13 @@ class ScriptManager extends EventEmitter { await this._asyncIteration.nextIteration(); Editor.Module.setImportProjectModuleDelegate(async (url: string) => { - throw new Error(`Not supported`); + const filePath = await Editor.Message.request('asset-db', 'query-path', url) as string; + if (!filePath) { + throw new Error(`${url} is not a valid database URL.`); + } + + const fileURL = pathToFileURL(filePath); + return await this._executor.import(fileURL.href); }); }