menu
版本
2017.2.10.6745
2024.1.4.8780
2023.1.12.8706
2022.1.18.8567
2021.1.14.8108
2019.2.15.7667
2019.1.11.7296
2018.1.11.6987
2017.2.10.6745
2017.1.9.6501
2016.2.6.6153
2015.1.9.5624
2024.1.4.8780
2023.1.12.8706
2022.1.18.8567
2021.1.14.8108
2019.2.15.7667
2019.1.11.7296
2018.1.11.6987
2017.2.10.6745
2017.1.9.6501
2016.2.6.6153
2015.1.9.5624
该集成提供了一些组件,这些组件可以直接满足最常见的应用场景下的使用需求,而不需要编程。
isDefaultListener
determines whether the game object will be considered a default listener - a listener that automatically listens to all game objects that do not have listeners attached to their AkGameObjListenerList's. isDefaultListener
determines whether the game object will be considered a default listener - a listener that automatically listens to all game objects that do not have listeners attached to their AkGameObjListenerList's. AkSoundEngine.SetState()
whenever the selected Unity event is triggered. For example this component could be set on a Unity collider to trigger when an object enters it. AkSoundEngine.SetSwitch()
whenever the selected Unity event is triggered. For example this component could be set on a Unity collider to trigger when an object enters it. 这个集成还提供了一些类,适用于常见场景以外的大多数应用场景,需要极少量的编程:
共有四种方法可以将声音添加到您的游戏中:
AK.Wwise.Event.Post()。
AkSoundEngine.PostEvent()。
AkSoundEngine.PostEvent
之后,播放的所有声音的衰减范围。在 Unity 的 Timeline 中,可使用自定义 Wwise Track 来触发 Wwise 事件,并设置 Wwise RTPC 值。
在 Wwise 中,Reverb Zone(混响区域)被称为 Environment(环境)或者
Auxiliary
Sends(辅助发送)。Reverb
Zone 并不局限于混响效果,而且它是在 Wwise 工程中定义的。
AkEnvironment 组件包含一个非常简单的环境区域。您可以在任何类型的碰撞体上附加一个 AkEnvironment。如果想将一个 AkEnvironment 添加到您的场景:
AkSoundEngine.SetGameObjectAuxSendValues()。
我们还有一些门户(portal)可以用来合并两个环境的影响。这两个环境中每个环境对效果的贡献都是和它们与游戏对象间距离相关的。
如果游戏对象站在两个房间之间,或者站在连接两个环境的隧道中,那么这种功能是很有用的。
如果想使用环境和环境门户,您需要一个游戏对象和能觉察到环境的(environment aware) AkGameObj 组件。
AkEnvironmentPortal 会自动探测到和它重叠的 AkEnvironment 对象。重叠的环境将出现在门户 inspector 的两个选择列表中。如果有太多的环境与门户重叠, 您则可以选择让门户和哪些环境混合在一起。
在 Wwise 中,只有 4 个环境可以同时处于活跃状态。这样 4 个环境按照如下方式选择:
大多数 Wwise SDK 函数可以通过 AkSoundEngine
类在 Unity 中使用。将它想象为 C++ 命名空间 AK::SoundEngine、
SDK 相比,API 绑定中所做的更改,请参考 API 变化和限制。 对于更复杂的情况,您需要从代码中调用 Wwise 函数。在 API 中,所有函数中的 AK::MusicEngine
等等的替代。想了解与原始GameObjectID
被Unity 风格的 GameObject 所替代。在运行时,这个 GameObject 中将自动添加一个 AkGameObj 组件,除非您之前已经手动添加过了。
原生 Wwise API 使用字符串或 ID 来触发 Wwise 工程中的事件和其它有名字的对象。您仍然可以在 C# 环境下这样做,方法是将文件 Wwise_IDs.h
转码为 Wwise_IDs.cs。点击
Assets > Wwise > Convert Wwise SoundBank IDs。为了完成上述操作,您需要安装 Python。
如需将 MIDI 发送到 Wwise,可为 AkMIDIPostArray
类的 AkMIDIPost
成员赋值,并调用以下任一方法:
AkMIDIPostArray.PostOnEvent()
AkSoundEngine.PostMIDIOnEvent()
AK.Wwise.Event.PostMIDI()
以下是一个将 MIDI 消息发送到声音引擎的简单脚本:
public class MyMIDIBehaviour : UnityEngine.MonoBehaviour { public AK.Wwise.Event SynthEvent; private void Start() { AkMIDIPostArray MIDIPostArrayBuffer = new AkMIDIPostArray(6); AkMIDIPost midiEvent = new AkMIDIPost(); midiEvent.byType = AkMIDIEventTypes.NOTE_ON; midiEvent.byChan = 0; midiEvent.byOnOffNote = 56; midiEvent.byVelocity = 127; midiEvent.uOffset = 0; MIDIPostArrayBuffer[0] = midiEvent; midiEvent.byOnOffNote = 60; MIDIPostArrayBuffer[1] = midiEvent; midiEvent.byOnOffNote = 64; MIDIPostArrayBuffer[2] = midiEvent; midiEvent.byType = AkMIDIEventTypes.NOTE_OFF; midiEvent.byOnOffNote = 56; midiEvent.byVelocity = 0; midiEvent.uOffset = 48000 * 8; MIDIPostArrayBuffer[3] = midiEvent; midiEvent.byOnOffNote = 60; MIDIPostArrayBuffer[4] = midiEvent; midiEvent.byOnOffNote = 64; MIDIPostArrayBuffer[5] = midiEvent; SynthEvent.PostMIDI(gameObject, MIDIPostArrayBuffer); } }
您可以通过 C# 脚本来调用 Audio Input 源插件。请参阅 Audio Input Source Plug-in from the Wwise SDK documentation.
以下是一个将测试音发送到 Audio Input 源插件的简单脚本:
public class MyAudioInputBehaviour : UnityEngine.MonoBehaviour { public AK.Wwise.Event AudioInputEvent; public uint SampleRate = 48000; public uint NumberOfChannels = 1; public uint SampleIndex = 0; public uint Frequency = 880; private bool IsPlaying = true; // 通过该回调填充音频采样 – 此函数会在每一帧针对各声道调用。 bool AudioSamplesDelegate(uint playingID, uint channelIndex, float[] samples) { for (uint i = 0; i < samples.Length; ++i) samples[i] = UnityEngine.Mathf.Sin(Frequency * 2 * UnityEngine.Mathf.PI * (i + SampleIndex) / SampleRate); if (channelIndex == NumberOfChannels - 1) SampleIndex = (uint)(SampleIndex + samples.Length) % SampleRate; // 返回 false 表示已无更多数据可提供。与此同时,会停止关联事件。 return IsPlaying; } // 通过该回调设置音频格式 - 在请求提供样本之前会调用此函数一次。 void AudioFormatDelegate(uint playingID, AkAudioFormat audioFormat) { // Channel configuration and sample rate are the main parameters that need to be set. audioFormat.channelConfig.uNumChannels = NumberOfChannels; audioFormat.uSampleRate = SampleRate; } private void Start() { // The AudioInputEvent event, that is setup within Wwise to use the Audio Input plug-in, is posted on gameObject. // 调用 AudioFormatDelegate 一次,并在每一帧调用 AudioSamplesDelegate 一次,直到返回 false。 AkAudioInputManager.PostAudioInputEvent(AudioInputEvent, gameObject, AudioSamplesDelegate, AudioFormatDelegate); } // 可通过其他脚本调用此方法以停止回调 public void StopSound() { IsPlaying = false; } private void OnDestroy() { AudioInputEvent.Stop(gameObject); } }
在默认情况下,会将 AkGameObj
组件关联到特定的 Unity gameObject
,并使用其变换功能(可选偏置)进行全面定位。这对很多游戏(如第一人称射击游戏)来说基本上就够了。不过,对于采用自定义镜头角度的游戏(如各种第三人称游戏)来说,假如只是简单地将音频听者关联到单个游戏对象(如 Unity 中的主镜头),定位的距离衰减和空间化这两个方面可能会不好协调。其他游戏可能还要给玩家提供别的自定义定位体验。
为此,AkGameObj
组件类允许用户重写定位。通过 GetPosition()、
GetForward()
和 GetUpward()
这三种虚方法,用户可选择继承 AkGameObj
的子类,并使用这些子类组件来灵活地自定义任意数量 Unity gameObject
的定位。
这里有一个简单的示例,展示了如何使用自定义组件来重写默认的 AkAudioListener
行为。对这个整合了 Wwise 的第三人称游戏项目,可移除现有的 AkAudioListener
及其关联的 AkGameObj
。然后,将以下脚本关联到 MainCamera 对象,并关联 AkAudioListener
。最后,指定音频听者位置所要跟随的目标 gameObject
(如玩家角色)。如此一来,所有发声体的距离衰减都会将所选目标 Unity gameObject
的位置作为听者位置(画面内的距离听者),而所有发声体的朝向仍会将主镜头朝向作为听者朝向(画面外的朝向听者)。
#if !(UNITY_DASHBOARD_WIDGET || UNITY_WEBPLAYER || UNITY_WII || UNITY_WIIU || UNITY_NACL || UNITY_FLASH || UNITY_BLACKBERRY) // Disable under unsupported platforms. // // Copyright (c) 2017 Audiokinetic Inc. / All Rights Reserved // using UnityEngine; using System; using System.Collections.Generic; [AddComponentMenu ("Wwise/AkGameObj3rdPersonCam")] [ExecuteInEditMode] // 需要通过 ExecuteInEditMode 来正确维护 isStaticObject 的状态。 public class AkGameObj3rdPersonCam : AkGameObj { public Transform target; // 指定此镜头所要跟随的位置。用户可在 Inspector 中将其指定为玩家角色的 Unity gameObject。 // 将镜头位置设为玩家位置,据此处理距离衰减。 public override Vector3 GetPosition () { return target.GetComponent<AkGameObj> ().GetPosition (); } } #endif // #if !(UNITY_DASHBOARD_WIDGET || UNITY_WEBPLAYER || UNITY_WII || UNITY_WIIU || UNITY_NACL || UNITY_FLASH || UNITY_BLACKBERRY) // Disable under unsupported platforms.