Anopia Engine uses scriptable objects (called Mags) to hold reference data for your audio clips.
Each type of sound effect or music implementation has a corresponding scriptable object.
- Decide what implementation you need and find the corresponding Mag to use
- Create the scriptable object in your unity assets.
- Assign the audio clips, sound object prefabs and any other settings to the scriptable object.
- Scriptable objects must be placed in "Assets/Resources/AudioMags"
Any Audio Source Game Object that is instantiated by the system will use the anSourcerer
MonoBehaviour Class.
Some scriptable objects will require you to set up prefabs that hold the AudioSource Component. Settings will need to be adjusted on the prefab component as well. (see ClipObjectMag/ADSRMag/LayerMag below)
Manually Add anDriver
as a component to your game object.
If you are using a OneShotEvent
(see below), you will need to manually create and assign an audio source too. This Audio Source will be used to play all OneShotEvent
s assigned to the driver.
In your gameplay script, call the SetDriver(MonoBehaviour host, AudioMixerGroup output, params string[] IDs)
Function to assign the driver host, mixer output, and Load audio events using the names of the corresponding scriptable objects.
To start and stop events using the driver, simply activate anDriver.Play(string SoundID, params object[] args)
and anDriver.Stop(string SoundID)
. The SoundID will be the name of the scriptable object used to Load the event.
IanEvent
s are non MonoBehaviour classes used with the anDriver
for your convenience, but they can be used on their own as well.
- Randomly selects an audio clip, randomises the volume and plays it using the attached AudioSource. See AudioSource.PlayOneShot
Each ClipData
set has an audioClip reference with its own gain adjustment. VolumeFluctuation
controls the range of randomisation that occurs with the volume.
Use Play
to play sound. args[0]
as float is used for volume scale, gain and randomisation still applies. args[1]
as int will be used as an array key to access the audio clip.
Stop
will activate the Stop function on the audio source.
- Randomly selects an audio clip, randomises the volume and plays it with an instantiated audioSource for each transient.
- You can play sounds at any position and at any timecode.
- You also have pitch, HighPassFilter.cutoffFrequency and distortionLevel randomisation
Use Play
to play sound and PlayScheduled
to play sound at a specified timecode. See AudioSource.PlayScheduled.
args[0]
as float is used for volume scale, gain and randomisation still applies. args[1]
as Vector3 is the position where the sound object is instantiated, the position will be the host object position if unspecified.
If you are using HighPass and Distortion randomisation, you MUST add the AudioHighPassFilter and AudioDistortionFilter components to the prefab.
Inherits from anClipMag
/anClipObjectEvent
.
- This event plays the full ADSR sound envelop using audioClips for
Attack
,Sustain
andRelease
.
Start and stop playing the sound by using Play
and Stop
on the event/driver
Play
will play the Attack clip using AudioSource.PlayOneShot and play the Sustain sound by assigning it to the audio source with loop enabled.
Stop
will stop the sustain sound at the audio source and play the release sound.
- This event plays one or more audio clips sequentially.
Use Play
to play a sequence. args
as string array will be used to fetch the audio clips by name, each clip will be scheduled to exactly after the previous clip in the sequence.
Use PlayScheduled
to play a specified clip at a specified timecode, can be used from the driver. args[0]
as string is the name of the clip to be played.See AudioSource.PlayScheduled.
- For loop sounds that are meant to be played simultaneously, You can easily instantiate an array of
anSourcerer
s in runtime (you do not useanDriver
).
Add an array of anSourcerer
in your MonoBehaviour script
In the anLayerMag
Simply assign an audio clip and the audio source prefab that is used to play it.
Use anCore.SetLayers(MonoBehaviour host, string SoundID, AudioMixerGroup output)
to instantiate all the prefabs in runtime.
All runtime adjustments are done using your own gameplay scripts.
The Synchro synchronises all music beats and events to the (AudioSettings.dspTime)[https://docs.unity3d.com/ScriptReference/AudioSettings-dspTime.html]. It checks for the next beat 1 frame ahead of the current (AudioSettings.dspTime)[https://docs.unity3d.com/ScriptReference/AudioSettings-dspTime.html].
- Activating
StartSynchro
requires tempo data and can be done directly or usinganConductor
if you have music. - You can synchronize game events using the
PlayOnBeat
delegate which will activate 1 frame ahead, this can be used to synchronise sounds using (AudioSource.PlayScheduled)[https://docs.unity3d.com/ScriptReference/AudioSource.PlayScheduled.html]. - You can check the time code for the
NextBeat
andNextBar
at any time. You do not use AudioSettings.dspTime .
anConductor
handles all music functions and transitions.
This is the scriptable object that is used by the following scripts to load the AudioClip reference.
anInteractable
Implements sounds for OnPointerEnter, OnPointerDown, OnPointerUp, OnPointerExit
You are not required to assign AudioClips for all the events as there is a null check.
anSliderInteractable
Implements sounds for OnPointerEnter, OnPointerDown, Slider.onValueChanged usingInteract
clip, OnPointerUp, OnPointerExit- Inherits from
anInteractable
anClickInteractable
Implements sounds for OnPointerEnter, OnPointerClick usingInteract
clip, OnPointerExit
1 Create an anInteractableMag
scriptable object and assign the audio clips
2 Add the script to the UI object
3 Enter the name of your scriptable object into SoundID