Unity照片墙Pop-up Photo Wall打包成web 日期:2025-05-30 分类:1 人气:0 Unity照片墙Pop-up Photo Wall是一款付费的Unity插件,将其打包成web程序是遇到一些问题,我用的Unity版本是`Unity 6000.0.26f1c1` ### 插件不兼容 按照了GLTF插件后不兼容,这个照片墙只能展示图片,我安装了几个package用于展示gltf3d模型,在Unity Editor中调试正常,但是打包成web之后报错: ``` wasm-ld: error: Library/PackageCache/com.atteneder.draco/Runtime/Plugins/WebGL/libdracodec_unity.a(metadata.cc.o): undefined symbol: std::__2::__vector_base_common<true>::__throw_length_error() const ``` 看到有draco,问了deepseek之后,把插件卸载就可以了。 Pop-up Photo Wall我用的版本是1.6,比较老了,插件兼容性确实差了一些。 ### 音频问题 打包成功之后,浏览器运行报错: ``` The AudioContext was not allowed to start. It must be resumed (or created) after a user gesture on the page ``` 差了一下百度,意思是说浏览器要播放音频需要经过用户同意,因此果断禁用了音频。 菜单栏:Edit -> Project Setting -> Audio,勾选禁用选项  ### 文件问题 重新运行仍然报错: ``` Manual synchronization of Unity Application.persistentDataPath via JS_FileSystem_Sync() is deprecated and will be later removed in a future Unity version. The persistent data directory will be automatically synchronized instead on file modification. Pass config.autoSyncPersistentDataPath = true; to configuration in createUnityInstance() to opt in to the new behavior. ``` 更改打包之后的index.html,在创建Unity实例的时候增加一个参数,如下: ``` createUnityInstance(document.querySelector("#unity-canvas"), { arguments: [], dataUrl: "Build/Builds.data.unityweb", frameworkUrl: "Build/Builds.framework.js.unityweb", codeUrl: "Build/Builds.wasm.unityweb", streamingAssetsUrl: "StreamingAssets", companyName: "Suzhou Longday", productName: "Popup Photo", productVersion: "0.1.0", autoSyncPersistentDataPath: true, // 增加此参数 // matchWebGLToCanvasSize: false, // Uncomment this to separately control WebGL canvas render size and DOM element size. // devicePixelRatio: 1, // Uncomment this to override low DPI rendering on high DPI displays. }); ``` 此问题消失,但是仍然有问题: ``` Uncaught (in promise) TypeError: Cannot read properties of undefined (reading 'length')。at Object.hashName (b92a6f73-88cc-48d1-a9f0-2d70c64e357d:9:66466) at Object.lookupNode (b92a6f73-88cc-48d1-a9f0-2d70c64e357d:9:67096)。 ``` 这个问题就不好解决了,看提示像是js问题,找了很久都没有找到原因,忽然看到错误中有这么几个提示:  `rmdir`不是删除目录吗,这Unity想做什么要删除目录吗?这怎么能行!!于是我想到Pop-up Photo Wall这个检查中有一个地方是设置目录的。 照片墙中的照片有两种加载方式,一种是从目录中读取照片,另一个是在Inspector中通过纹理添加照片,如下图:  而我打包的这个场景选择的是从目录中读取照片,我尝试着改成把`Photo Source`改成`Source By Texture` 然后重新打包,结果打包速度飞快,运行之后错误消失了,照片墙终于出来了。 >原来根本问题是这里的选择有问题啊 ### 其他问题 虽然照片墙显示出来,不过看一下日志还是有一个问题: ``` 6WebGL: INVALID_ENUM: getInternalformatParameter: invalid internalformat ``` 这个问题我改了很久也没有解决,由于不影响功能,暂时先记一下,猜测可能是影响画面渲染,因为图片看起来有一些模糊。 ### 鸣谢 - [Maything](https://assetstore.unity.com/publishers/41445) 标签: 3d 上一篇:vscode使用Community Server Connector运行JDK1.8项目报错 下一篇:Unity 打包时停留在 Busy for 随便看看 2024-02-19 PHP7 运算符“??” 和“?:”的区别 2022-11-30 Linux 后台运行命令 2022-11-25 关于我们 2022-11-30 centos一键系统安装lnmp集成环境 2022-11-30 linux 生成 ssh 公钥 留言