1.简介
Fmod是一种跨平台的音频引擎。采用Fmod作为音频引擎的游戏包括Far Cry(孤岛惊魂), Tom Clancy‘s Ghost Recon(幽灵行动),著名的World Of Warcraft(魔兽争霸)。
Fmod官网是https://www.fmod.com/。

2.下载
需下载FmodStudio,打开官网后需要注册后登陆才能下载
下载Studio

下载UnityPackage

在将UnityPackage导入Unity后,可以在Unity的菜单栏中找到Fmod选项。
3.FomdStudio介绍
打开fmod studio后,看到的大体界面是这样的。

其中,左侧有Events, Banks,Assets三个列。在fmod中,声音的素材放在Assets中,编辑好的声音事件Event在Events里,Banks里面存放bank文件,声音事件Event只有先Assign to bank后,在执行build操作,才能在Unity中的菜单栏Fmod选项里的Event Browser中可以显示出来。
最大的Editor部分则为声音文件的操作区。
在Events,Banksia,Assets中都可以创建文件夹进行方便管理。



在Events中鼠标右击在弹出的选择框中选择new event即可新建一个声音事件Event,将Assets中的音乐素材拖入到Editor区域中,在点播放按钮,就能够听到素材的声音了。

在编辑区域内右击,可以在弹出的选择框内看到多种选项,有设置循环播放区域,添加标记,设置判定区域等。对声音编辑感兴趣的可以深入学习。
4在Unity中的使用
在studio中新建一个Event,在Assets中导入素材后,在Event添加声音后,执行assign to bank,在执行Build操作后进行保存,就可以在Unity中进行调用并播放了。
打开unity,首先确保已经导入fmod的UnityPackage包,然后点击在unity的菜单栏中的Fmod选项的Edit Setting,在下面的面板中在文件夹中选选中Fmod项目。

在Fmod选项里选中Event Browser在弹出的面板中就能看到fmod项目的event和bank。

接下来就是在代码里调用了。

添加using FMODUnity,定义一个fmod的EventInstance,使用[FMODUnity.EventRef]就能够在文件夹中选择event的路径,而不需要手动的写事件在文件夹中的路径

调用fmod中的RuntimeManager类中创建event的方法,就能够根据事件在fmod项目中的路径创建出EventInstance,在调用event的start方法就能够播放这个事件。将脚本挂在场景中的空物体下,在运行场景,就能听见声音了。

在fmod中可以创建3D声音事件或者是2D声音事件,如果是3D声音事件,在监听脚本处于声音事件的播放范围内及能够听到声音,反之,如果监听脚本处于声音事件的播放范围,则听不到声音。
在场景中有个球体和正方体,如下图,其中球体外的白色线圈为3D声音的播放范围。

在球体上添加脚本FmodStudioEventEmitter,如下图,

在Evnet中选中fmod项目的3D事件,ovrride attenuatio勾选上则是设置声音的播放范围。在Play Event中设置object start则这个事件在unity运行的时候就会播放,不过只在设置的播放方位内播放。这时候在unity运行的时候,是听不到声音的,因为没有添加监听脚本。在正方体下添加FmodStudioListener脚本,然后移动正方体到球体的播放范围内,这时候就能听到声音了,将正方体移出白色线圈外,这时候就听不到声音了。
5.联调
fmod中的联调能够在unity运行的时候去调节事件中的参数,是声音达到音乐制作者想要的效果。
在unity菜单栏中的Edit选项下的Project Settings中的Player Settings里。如下图,

将Run In BAckground勾选上 ,这样子在切换应用的时候unity还是能够保持运行,这时候打开unity中应用到的fmod项目,

点击最下方的Live Update Off,这时候按钮变绿且变成Live Update On,表示已经进入联调模式。

网友评论