ialex32x / unity-jsb

It brings Javascript runtime capability to Unity3D by integrating QuickJS.
MIT License
337 stars 41 forks source link

打包 PC 版本报错 can not resolve file path: example_main #24

Closed WanderWang closed 3 years ago

WanderWang commented 3 years ago

重现步骤:

  1. git clone & 打开项目
  2. 直接运行,加载 example_main 正常
  3. 执行 build -> PC -> build and run
  4. 上一步会生成 exe 文件并自动运行,运行过程正确,加载 example_main 正常
  5. 打开资源管理器,手动点击生成的 unity-jsb.exe,报错 can not resolve file path: example_main
ialex32x commented 3 years ago

这个是相对路径的问题,因为最终环境一般都是自己实现对应的 FileSystem 逻辑,所以 example 只提供了一些基本的示意,并没有考虑太多环境因素。

针对目前的 example,一个方法是你可以通过在根目录执行 gulp(也是一个示例),该脚本会将脚本编译为 js 并自动复制到 Resources,然后 example 改用 Resources FileSystem 进行加载,就可以屏蔽相对路径问题。

稍后我也会修复此问题(将上层目录添加到 SearchPath 即可)。

ialex32x commented 3 years ago

已经修改路径解析逻辑。

注意: 如果使用了 node_modules,则也需要将此目录复制或引入搜索路径中。但这种情况下,还是建议使用 gulp、webpack 等对脚本打包,以便移除对 node_modules 目录的直接依赖。