Unity构建过程不包括音频文件 [英] Unity build process doesn't include audio files

查看:91
本文介绍了Unity构建过程不包括音频文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我遇到一个问题,即在Unity中进行独立构建会导致音频文件无法复制(据我所知)或无法复制到"App_Data/unity默认资源"文件中.如果我手动复制将音频文件粘贴到构建资源文件夹中,则构建工作正常.我的文件是.ogg的文件,它们与所有随构建一起内置的图像一起存储在Assets/Resources文件夹中. ogg文件确实出现在Unity中,我在C#脚本中引用了它们.在Unity本身中运行时以及将音频资产复制到独立的builds目录中之后,音频才起作用.

I'm running into an issue where making a standalone build in Unity is causing the audio files to not be copied over (from what I can tell) or built into the "App_Data/unity default resources" file. If I hand copy paste the audio files into the builds resources folder, the build works fine. My files are .ogg's, they are stored in the Assets/Resources folder with all the images that are built in with the build. The ogg files do appear in Unity and I reference them in my C# script. Audio works when running in Unity itself and after copying over the audio assets into the standalone builds directory.

请注意,我希望构建过程本身可以做到这一点,而不必编写构建后脚本来复制数据.编写该脚本没问题,但是我对Unity没有自动执行感到惊讶.

Please note that I'm hoping that the build process itself can do this rather than having to write a post-build script to copy the data. Writing this script would be no problem, but I'm a bit surprised that Unity didn't do it automatically.

有人知道为什么Unity不将其复制过来吗?在我所有的搜索中仍然没有找到一个设置吗?

Does anyone know why Unity isn't copying them over? Is there a setting that with all my searching I still haven't found?

提前谢谢!

推荐答案

Unity非常擅长将您在编辑器中引用的内容包括在内.如果您没有在编辑器中引用您的ogg文件,则Unity无法序列化该引用,也无法仅仅因为您在代码中引用就可以确定您在项目中需要它.

Unity is very good at including just what you reference in the editor. If you don't reference your ogg files in the editor, Unity can't serialise the reference and won't be able to figure out that you need it in the project, just because you reference it in code.

如果编辑器中的游戏对象具有音频源,并且在其中放置了ogg文件(在声音剪辑字段中),则该音频文件将包含在项目中.任何其他类型的编辑器引用都将使Unity在项目中包含一个文件.

If you have a game object in the editor that has an audio source, and you put of of your ogg files in it (in the sound clip field), that audio file is going to get included in the project. Any other type of editor reference will make Unity include a file in the project.

如果要通过动态加载声音文件来使用声音文件,则需要将所有声音文件包括在Assets/Resources中,并使用Resources.Load()进行加载.

If you're using sound files by loading them dynamically, then you need to include all your sound files in Assets/Resources and the load them with Resources.Load().

最后,要确切检查要包含的文件,可以检查编辑器日志.如果Unity并未复制Resources文件夹中的文件,那么唯一的答案是,您可以通过Unity编辑器中的Help-> Report Bug来向他们发送错误报告.

Finally, to check exactly which files are being included, you can check the editor log. If Unity isn't copying the files in the Resources folder, then the only possible answer is that you send a bug report to them, via Help->Report a Bug in the Unity Editor.

这篇关于Unity构建过程不包括音频文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆