Class AircraftSoundComponentBehaviour
Base class for all vehicle SoundComponents. Inserts a layer above Unity's AudioSource(s) which insures that the values are set properly, master volume is used, etc. Supports multiple AudioSources/AudioClips per one SoundComponent for random clip switching.
Inheritance
Namespace: NWH.Aerodynamics.AircraftController.Sound
Assembly: NWH.Aerodynamics.dll
Syntax
[Serializable]
public abstract class AircraftSoundComponentBehaviour : MonoBehaviour
Fields
| Edit this page View SourceaircraftController
Declaration
protected AircraftController aircraftController
Field Value
| Type | Description |
|---|---|
| AircraftController |
audioMixerGroup
AudioMixerGroup that this SoundComponent belongs to.
Declaration
[Tooltip("AudioMixerGroup that this SoundComponent belongs to.")]
public AudioMixerGroup audioMixerGroup
Field Value
| Type | Description |
|---|---|
| AudioMixerGroup |
basePitch
Base pitch of the sound component.
Declaration
[FormerlySerializedAs("pitch")]
[Range(0, 2)]
[Tooltip("Base pitch of the sound component.")]
public float basePitch
Field Value
| Type | Description |
|---|---|
| float |
baseVolume
Base volume of the sound component.
Declaration
[FormerlySerializedAs("volume")]
[Range(0, 1)]
[Tooltip("Base volume of the sound component.")]
public float baseVolume
Field Value
| Type | Description |
|---|---|
| float |
clips
List of audio clips this component can use. Some components can use multiple clips in which case they will be chosen at random, and some components can use only one in which case only the first clip will be selected. Check manual for more details.
Declaration
[Tooltip("List of audio clips this component can use. Some components can use multiple clips in which case they will be chosen at random, and some components can use only one in which case only the first clip will be selected. Check manual for more details.")]
public List<AudioClip> clips
Field Value
| Type | Description |
|---|---|
| List<AudioClip> |
container
Container to which this SoundComponent belongs to. All AudioSources will be attached to this object.
Declaration
[Tooltip("Container to which this SoundComponent belongs to. All AudioSources will be attached to this object.")]
public GameObject container
Field Value
| Type | Description |
|---|---|
| GameObject |
mixer
Declaration
protected AudioMixer mixer
Field Value
| Type | Description |
|---|---|
| AudioMixer |
sources
Declaration
[NonSerialized]
protected List<AudioSource> sources
Field Value
| Type | Description |
|---|---|
| List<AudioSource> |
Properties
| Edit this page View SourceClip
Gets or sets the first clip in the clips list.
Declaration
public AudioClip Clip { get; set; }
Property Value
| Type | Description |
|---|---|
| AudioClip |
Clips
Gets or sets the whole clip list.
Declaration
public List<AudioClip> Clips { get; set; }
Property Value
| Type | Description |
|---|---|
| List<AudioClip> |
RandomClip
Gets a random clip from clips list.
Declaration
public AudioClip RandomClip { get; }
Property Value
| Type | Description |
|---|---|
| AudioClip |
Source
Gets or sets the first audio source in the sources list.
Declaration
public AudioSource Source { get; set; }
Property Value
| Type | Description |
|---|---|
| AudioSource |
Sources
AudioSources belonging to this SoundComponent.
Declaration
public List<AudioSource> Sources { get; set; }
Property Value
| Type | Description |
|---|---|
| List<AudioSource> |
Methods
| Edit this page View SourceAddSourcesToMixer()
Adds outputs of sources to the mixer.
Declaration
public void AddSourcesToMixer()
Awake()
Declaration
public virtual void Awake()
Disable()
Disables all the AudioSources belonging to this SoundComponent. Will call Stop() as well as disable the source.
Declaration
public void Disable()
Enable()
Enables all the AudioSources belonging to this SoundComponent. Calls Play() on all the looping sources.
Declaration
public void Enable()
GetDefaultClipName()
Declaration
public virtual string GetDefaultClipName()
Returns
| Type | Description |
|---|---|
| string |
GetMixerGroupName()
Declaration
public virtual string GetMixerGroupName()
Returns
| Type | Description |
|---|---|
| string |
GetPitch()
Gets pitch of the Source. Equal to Source.pitch.
Declaration
public float GetPitch()
Returns
| Type | Description |
|---|---|
| float |
GetVolume()
Gets volume of the Source. Equal to Source.volume.
Declaration
public float GetVolume()
Returns
| Type | Description |
|---|---|
| float |
Initialize(bool, bool)
Initializes the sound component by creating and configuring the audio source.
Declaration
public virtual void Initialize(bool play, bool loop)
Parameters
| Type | Name | Description |
|---|---|---|
| bool | play | Whether to start playing immediately. |
| bool | loop | Whether the audio should loop. |
LoadDefaultAudioMixer()
Declaration
public static AudioMixer LoadDefaultAudioMixer()
Returns
| Type | Description |
|---|---|
| AudioMixer |
LoopOnAwake()
Declaration
public virtual bool LoopOnAwake()
Returns
| Type | Description |
|---|---|
| bool |
Play()
Plays the source if it is not already playing.
Declaration
public void Play()
Play(int)
Plays the source at index if not already playing.
Declaration
public void Play(int index)
Parameters
| Type | Name | Description |
|---|---|---|
| int | index | Index of the source to play. |
PlayOnAwake()
Declaration
public virtual bool PlayOnAwake()
Returns
| Type | Description |
|---|---|
| bool |
Reset()
Declaration
public virtual void Reset()
SetAudioSourceDefaults(AudioSource, bool, bool, float, AudioClip)
Initializes audio source to it's starting values.
Declaration
public void SetAudioSourceDefaults(AudioSource audioSource, bool play = false, bool loop = false, float volume = 0, AudioClip clip = null)
Parameters
| Type | Name | Description |
|---|---|---|
| AudioSource | audioSource | AudioSource in question. |
| bool | play | Play on awake? |
| bool | loop | Should clip be looped? |
| float | volume | Volume of the audio source. |
| AudioClip | clip | Clip that will be set at the start. |
SetPitch(float)
Sets pitch for the first source in sources list.
Declaration
public void SetPitch(float pitch)
Parameters
| Type | Name | Description |
|---|---|---|
| float | pitch | Pitch to set. |
SetPitch(float, int)
Sets pitch for the [id]th source in sources list.
Declaration
public void SetPitch(float pitch, int index)
Parameters
| Type | Name | Description |
|---|---|---|
| float | pitch | Pitch to set. |
| int | index | Index of the source. |
SetVolume(float)
Sets volume for the first source in sources list. Use instead of directly changing source volume as this takes master volume into account.
Declaration
public void SetVolume(float volume)
Parameters
| Type | Name | Description |
|---|---|---|
| float | volume | Volume to set. |
SetVolume(float, int)
Sets volume for the [id]th source in sources list. Use instead of directly changing source volume as this takes master volume into account.
Declaration
public void SetVolume(float volume, int index)
Parameters
| Type | Name | Description |
|---|---|---|
| float | volume | Volume to set. |
| int | index | Index of the target source. |
SetVolume(float, AudioSource)
Sets the volume of AudioSource. Takes master volume into account.
Declaration
public void SetVolume(float volume, AudioSource source)
Parameters
| Type | Name | Description |
|---|---|---|
| float | volume | Volume to set. |
| AudioSource | source | Target AudioSource. |
Stop()
Stops the AudioSource if already playing.
Declaration
public void Stop()
Stop(int)
Stops the AudioSource at index if already playing.
Declaration
public void Stop(int index)
Parameters
| Type | Name | Description |
|---|---|---|
| int | index | Target AudioSource index. |