Wwise Unity Integrationの使用
このインテグレーションによって、良くあるシナリオ用にコードなしで直接使えるコンポーネントがいくつか提供されます:
- AkAmbient
Use this component to attach a Wwise Event to any object in a scene. The sound can be started at various moments, dependent on the selected Unity trigger. This component is more useful for ambient sounds (sounds related to scene-bound objects) but could also be used for other purposes. Since AkAmbient has AkEvent as its base class, it features the play/stop, play multiple, stop multiple and stop all buttons for previewing the associated Wwise event. . AkAmbientをInspectorで使うには を参照してください。
- AkAudioListener
Add this script on the game object that represent a listener. This is normally added to the Camera object or the Player object, but can be added to any game object when implementing 3D busses.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.
- AkBank
Loads and unloads a SoundBank at a specified moment. Vorbis sounds can be decompressed at a specified moment using the decode compressed data option. In that case, the SoundBank will be prepared.
- AkEmitterObstructionOcclusion
Obstructs/Occludes the emitter of the current game object from its listeners if at least one object is between them. - AkEnvironment
Use this component to define a reverb zone. This needs to be added to a collider object to work properly. AkEvironmentやAkEvironmentPortalをInspectorと共に使うには (Reverb Zones).
- AkEnvironmentPortal
Use this component to define an area that straddles two different AkEnvironments zones and allow mixing between both zones. AkEvironmentやAkEvironmentPortalをInspectorと共に使うには (Reverb Zones).
- AkEvent
Wwise Eventのことや、それをいつUnityでトリガーするのかを知っているHelperクラス。AkAmbientをInspectorで使うには を参照してください。
- AkGameObj
This component represents a sound object in your scene tracking its position and other game syncs such as Switches, RTPC and environment values. You can add this to any object that will emit sound, and it will be added to any object that an AkAudioListener is attached to. Note that if it is not present, Wwise will add it automatically, with the default values, to any Unity Game Object that is passed to Wwise.
- AkRoom
An AkRoom is an enclosed environment that can only communicate to the outside/other rooms with AkRoomPortals.
- AkRoomPortal
An AkRoomPortal can connect two AkRoom components together.
- AkRoomPortalObstruction
Obstructs/Occludes the spatial audio portal of the current game object from the spatial audio listener if at least one object is between them.
- AkSpatialAudioEmitter
Add this script on the GameObject which represents an emitter that uses the Spatial Audio API.
- AkSpatialAudioListener
Add this script on the game object that represent a listener. This is normally added to the Camera object or the Player object, but can be added to any game object when implementing 3D busses.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.
- AkState
This will callAkSoundEngine.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.
- AkSurfaceReflector
This component will convert the triangles of the GameObject's geometry into sound reflective surfaces.
- AkSwitch
This will callAkSoundEngine.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.
- 参照:
- Wwise Picker
またこのインテグレーションには、最小限のコードで、これ以外の利用シナリオの大部分に対応できるクラスが、いくつか提供されています:
- AK.Wwise.AuxBus
This type represents an auxiliary send in the Master-Mixer Hierarchy.
- AK.Wwise.Bank
This type can be used to load/unload SoundBanks.
- AK.Wwise.CallbackFlags
This type represents the values of the flags used when posting an Event with a callback.
- AK.Wwise.Event
This type can be used to post Events to the sound engine.
- AK.Wwise.RTPC
This type can be used to set game parameter values to the sound engine.
- AK.Wwise.State
This type can be used to set Wwise States.
- AK.Wwise.Switch
This type can be used to set Switch values on gameobjects.
- AK.Wwise.Trigger
This type can be used to post triggers to the sound engine.
- 参照:
- Wwise Types
Wwiseサウンドをゲームオブジェクトに追加するには
サウンドをゲームに追加する方法は、3通りあります:
- Wwise Pickerを使う。 最も簡単にサウンドをオブジェクトに追加できます。EventをWwise PickerウィンドウからUnity ViewerまたはInspectorにあるオブジェクトまでドラッグします。これで自動的にAkAmbientコンポーネントが対象Game Objectに作成されます。
- Add Componentメニューを使う。 AkAmbientコンポーネントやAkEventコンポーネントを、どのUnity Game Objectにも追加できます。
- Wwise Types を使う。 いつでも
AK.Wwise.Event.Post()
をC#スクリプトからコールできます。 - スクリプトを使う。 いつでもAKSoundEngine::SetGameObjectAuxSendValues()をC#スクリプトからコールできます。
AkAmbientをInspectorで使うには
- AkAmbient:
- Trigger On:
Provides a list of Unity events that can trigger your event. これ以外のイベントでも可能です。いつでもコードのどこからでも、AkSoundEngine.PostEventをコールしてイベントをトリガーできます。またトリガーのコードを自分で書いて、リストで同僚が見れるようにできます。Adding New Triggers for Wwise Events を参照してください。 - Event Name:
Specifies the name of the current event. イベントを選択するには、現在のイベント名をクリックしてイベントピッカーウィンドウを開きます。次にイベントをクリックしてOkボタンをクリックするか、イベントをダブルクリックして、それを選択します。また、イベントを Wwise Pickerからドラッグして現在のイベント名にドロップすることで、新しいものを選択することもできます。
- Action On Event:
Enables users to override some event parameters defined in Wwise directly from Unity. これで既存のイベントを再利用できるので、新しいものを作成せずに済みます。
- Action On Event Type:
Overrides the event type. - Curve Interpolation:
Overrides the interpolation curve. - Fade Time:
Overrides the sound's fade time.
- Action On Event Type:
- Use Callback:
Provides an easy way to make a game object react to an event callback.- Game Object:
The game object that will receive the callback. ゲームオブジェクトを選択するには、階層からドラッグしてゲームオブジェクトフィールドにドロップします。 - Callback Function:
This is the function that will get called by Game Object when the callback happens. ファンクションを選択するには、ファンクション名をCallback Functionテキストフィールドに入力します。
For this to work, Game Object must define Callback Function in one of its components.
The function's definition must be void FunctionName(AkEventCallbackMsg in_info). - Callback Flags:
Select a flag which specifies when Callback Function will be called. 同時に複数のフラグを選択できます。各フラグの詳しい情報については、Wwise ドキュメンテーション のAkCallbackType一覧表を参照してください。
- Game Object:
- Play / Stop:
Can be used to preview the Wwise Event when in Edit mode. - Stop All:
Stops all currently playing Wwise events. - Position Type:
Defines the way the event's position will be sent to the audio engine.- Simple_Mode:
The event's position will be the same as the game object to which it's attached. - Large_Mode:
The event can have multiple positions that are defined by a set of points. ポイントを追加するには、AkAmbient Tool BarのAddボタンをクリックします。各ポイントの位置は、ポイントをドラッグして変えられます。このモードは、あるサウンドが同時に複数のポジションから同時にくる場合などに便利です。海の中にいる時の水のサウンドなどは、良い例です。 - MultiPosition_Mode:
This mode enables us to have only one instance of a sound for all instances of AkAmbient using the same event in order to save memory.
All AkAmbient instances that are using this mode and that have the same event will automatically get detected and the same sound instance will be used for all of them insted of loading the same sound multiple times.
Note that all AkAmbient instances in this mode and with the same event will have the same trigger (see Trigger On in AkEvent). つまり1つのAkAmbientのトリガーを変更すると、ほかもイベントが同じであれば全て、トリガーが自動的に変更されます。 - Show Attenuation Sphere:
Shows a sphere that defines the space where the sound played by an event can be heard.
For this to work you need to enable Max Attenuation in the SoundBank settings in your Wwise project (Project->Project Settings->Soundbanks->Max attenuation)
- Dont_Show:
No attenuation sphere is shown. - Current_Event_Only:
Shows the attenuation spheres for all the sounds that would be played after a call toAkSoundEngine.PostEvent
while in the current mode.
If in Simple_Mode, then only the attenuation sphere of the sound coming from the game object is shown.
if in Large_Mode, then an attenuation sphere is shown for each point.
If in MultiPosition_Mode, then an attenuation sphere is shown for every other AkAmbient in MultiPosition_Mode with the same event. - All_Events:
Shows the attenuation sphere of all AkAmbient instances in the scene.
- Dont_Show:
- Simple_Mode:
- Trigger On:
Using Wwise with Unity Timeline
For Unity's Timeline feature, there are custom Wwise tracks for triggering Wwise events and setting Wwise RTPC values.
AkEvironmentやAkEvironmentPortalをInspectorと共に使うには (Reverb Zones)
WwiseでReverb Zoneのことを Environment
または Auxiliary
Sends
と呼びます。リバーブゾーンはリバーブエフェクトだけに制限されず、Wwiseプロジェクトで定義されます。
AkEnvironmentコンポーネントは非常に単純な環境ゾーンを表します。AkEnvironmentは、あらゆる種類のColliderに添付できます。To add an AkEnvironment to your scene:
- Using the Wwise Picker. This is the simplest way to add an AkEnvironment. AuxBusをWwise PickerウィンドウからUnity ViewerまたはInspectorにあるオブジェクトまでドラッグします。これで自動的にAkAmbientコンポーネントが対象Game Objectに作成されます。
- "Add Component"メニューを使う。 AkEnvironmentコンポーネントを、どのUnity Game Objectにも追加できます。使いたい環境をInspectorのセレクタで選択します。
- Using scripts. You can call
AkSoundEngine.SetGameObjectAuxSendValues()
at any time from a C# script.
また、2つの環境のエフェクトを統合するためのポータルもあります。両者の環境が貢献するレベルは、ゲームオブジェクトからそれぞれの環境への距離に応じます。
This is useful if a game object is standing between two rooms or in a tunnel connecting two environments.
- To add an environment portal to your project, go to GameObject->Wwise->Environment Portal in Unity's menu bar.
環境や環境ポータルを利用するには、環境を意識できるAkGameObjコンポーネントを有するゲームオブジェクトが必要です。
AkEnvironmentPortal objects will automatically detect AkEnvironment objects that overlap it. 重複する環境はポータルのInspectorにある2つの選択リストに表示されます。ポータルに重複する環境が多すぎる場合は、ポータルでミックスすべき環境を選択できます。
Wwiseでは、同時にアクティブにできる環境数は最大4つです。Those 4 environments are selected as follows:
- The environments that are connected to a portal and that have the highest priority are selected until we reach 4 environments or until there are no more environments connected to a portal.
- If we still don't have 4 selected environments, we select the environments that are not connected to a portal as follows:
- Environments with the highest priority will be selected until we reach 4 environments (if the Default and Exclude Others flags are not set).
- Default環境は、他の環境が一切選択されていない場合に限り、選択されます。
- ゲームオブジェクトがExclude Othersフラグの立っている環境の中にある場合はその環境が選択されて、他の環境は全て棄却されます。
- AkEnvironment component:
Only 4 environments can be active at the same time.- Priority:
Defines the priority of an environment.
A smaller number has a higher priority.
If a game object is inside more than 4 environments, only the 4 environments with the highest priority will be active (if the Default and Exclude Others flags are not set). - Default:
A default environment will be active only if it's the only environment containing your game object.
If your game object is inside more than one default environment, then only the one with the highest priority will be active. - Exclude Others:
An environment with this flag can't be overlapped by other environments.
If your game object is inside an environment with the Exclude Others flag, then all other environments will get discarded.
If your game object is inside more than one environment with the Exclude Others flag, only the one with the highest priority will be active. - AuxBus Name:
Specifies the name of the current AuxBus. AuxBusを選択するには、現在のAuxBus名をクリックしてAuxBusピッカーウィンドウを開きます。次にAuxBusをクリックしてOkボタンをクリックするか、AuxBusをダブルクリックして、それを選択します。また、AuxBusを Wwise Pickerからドラッグして現在のAuxBus名にドロップすることで、新しいものを選択できます。
- Priority:
- AkEnvironmentPortal component:
You can create an environment portal in Unity by going to GameObject->Wwise->Environment Portal.
You can place an environment portal between two environments to combine their effects while your game object is inside the portal. これが機能するには、両者の環境とポータルが交差する必要があります。
両者の環境が貢献するレベルは、ゲームオブジェクトからそれぞれの環境への距離に応じます。The closer the game object is from an environment, the more that environment will contribute towards the final effect.
- Environment #1:
The portal will automatically detect all environments that intersect the portal. これらの環境のうち、ポータルの負の側に位置する環境(つまり選択された軸と反対方向にある環境)がドロップダウンメニューに表示されます。 このように環境をソートしておくのは、ランタイムに環境ごとの貢献レベルを判断するための演算量を削減するためです。 - Environment #2:
The portal will automatically detect all environments that intersect the portal. これらの環境のうち、ポータルの正の側に位置する環境(つまり選択された軸と同一方向にある環境)がメニューに表示されます。 このように環境をソートしておくのは、ランタイムに環境ごとの貢献レベルを判断するための演算量を削減するためです。 - Axis:
The axis is used to find the contribution of each environment.
For example, if the z axis is chosen, then moving along the x axis won't have any effect on the contribution of each environment. Z軸方向の移動のみが貢献レベルを左右します。
Note that the axis is in object space. So, rotating the portal will also rotate the axis.
- Environment #1:
- 参照:
Using C# code to control the sound engine
Most Wwise SDK functions are available in Unity through the AkSoundEngine
class. C++ ネームスペースの AK::SoundEngine
や AK::MusicEngineなどの代わりとしてとらえることができます。元のSDKと比較してAPIバインディングにどのような変更があったかは、
pg_limitationsを参照してください。 複雑な状況の場合は、コードでWwiseファンクションをコールする必要があります。APIで、全てのファンクションの GameObjectID
がGameObjectのUnityフレーバーに置き換えられます。AkGameObjコンポーネントを既にマニュアル操作で追加してない限り、ランタイムにこのGameObjectに自動的に追加されます。
EventやBankの文字列の代わりに数値IDを使う。
ネーティブWwise APIで、文字列やIDを使ってWwiseプロジェクト内のイベントやその他の名前の付いたオブジェクトをトリガーできます。C#の世界でも、Wwise_IDs.h
ファイルを Wwise_IDs.cs
に変換することで、同様にできます。Assets > Wwise > Convert Wwise SoundBank IDsをクリックする。これが機能するには、Pythonをインストールしておく必要があります。
Sending MIDI to Wwise.
MIDI can be sent to Wwise by filling the AkMIDIPost
members of AkMIDIPostArray
class and calling any of the following methods:
AkMIDIPostArray.PostOnEvent()
AkSoundEngine.PostMIDIOnEvent()
AK.Wwise.Event.PostMIDI()
The following is a basic script that sends MIDI messages to the sound engine:
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); } }
Using the Audio Input Source Plug-in in Unity.
The audio input source plug-in can be used via C# scripting. See Audio Input Source Plug-in from the Wwise SDK documentation.
The following is a basic script that sends a test tone to the audio input source plug-in:
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; // Return false to indicate that there is no more data to provide. This will also stop the associated event. return IsPlaying; } void AudioFormatDelegate(uint playingID, AkAudioFormat audioFormat) { audioFormat.channelConfig.uNumChannels = NumberOfChannels; audioFormat.uSampleRate = SampleRate; } private void Start() { AkAudioInputManager.PostAudioInputEvent(AudioInputEvent, gameObject, AudioSamplesDelegate, AudioFormatDelegate); } // This method can be called by other scripts to stop the callback public void StopSound() { IsPlaying = false; } private void OnDestroy() { AudioInputEvent.Stop(gameObject); } }
Apply Custom Positioning in Unity
By default, the AkGameObj
component is attached to a specific Unity gameObject
and uses its transform (with an optional offset) for full positioning. This is usually adequate for many games, such as first-person shooters. However, games with custom camera angles, such as many third-person games, may find it difficult to accommodate the two aspects of positioning (distance attenuation and spatialization) by simply attaching the audio listener to one game object, such as the main camera in Unity. Other games may want players to experience other custom positioning.
To this end, the AkGameObj
component class provides overridable positioning to Unity users. Through the three virtual methods GetPosition()
, GetForward()
, and GetUpward()
, users can derive a subclass from AkGameObj
and use that subclass component to customize any number of Unity gameObjects'
positioning.
Here is a simple example of how to use a custom component to override the default AkAudioListener
behavior. With a third-person project integrated with Wwise, remove the existing AkAudioListener
and its associated AkGameObj
. Then attach the following script to the MainCamera object, attach AkAudioListener
, and finally specify the target Unity gameObject
(such as the player avatar) that the audio listener's position will follow. After this, the distance attenuation of all the emitters will rely on the selected target Unity gameObject's
position as the listener position (an on-screen distance listener), while the orientation of all the emitters is still based on the main camera orientation as the listener orientation (an off-screen orientation listener).
#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 necessary to maintain proper state of isStaticObject. public class AkGameObj3rdPersonCam : AkGameObj { public Transform target; // The position that this camera will be following. User can specify this to the player character's Unity gameObject in the Inspector. // Sets the camera position to the player's position to handle distance attenuation. 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.
Wwise Unity Integrationに対してMon Jan 8 10:46:17 2018に生成されました。
