Class SoundEffect
A script for playing sound effects, with extra options such as clip, pitch, and volume mutation. Also allows configuring sound effects' volume.
Namespace: OmiyaGames.Audio
Assembly: cs.temp.dll.dll
Syntax
public class SoundEffect : MonoBehaviour
Remarks
Copyright (c) 2014-2018 Omiya Games Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
Revision | Description | ||
---|---|---|---|
Date: 8/18/2015 Author: Taro Omiya |
Version: 0.1.0-exp.1 Date: 2/18/2022 Author: Taro Omiya | Initial verison. | Moved to new package. |
Fields
MAX_LAYERS
Declaration
public const int MAX_LAYERS = 10
Field Value
Type | Description |
---|---|
Int32 |
MAX_PITCH
Declaration
public const float MAX_PITCH = 3F
Field Value
Type | Description |
---|---|
Single |
MAX_VOLUME
Declaration
public const float MAX_VOLUME = 1F
Field Value
Type | Description |
---|---|
Single |
MIN_LAYERS
Declaration
public const int MIN_LAYERS = 1
Field Value
Type | Description |
---|---|
Int32 |
MIN_PITCH
Declaration
public const float MIN_PITCH = -3F
Field Value
Type | Description |
---|---|
Single |
MIN_VOLUME
Declaration
public const float MIN_VOLUME = 0F
Field Value
Type | Description |
---|---|
Single |
Properties
AllAudioLayers
All attached audio sources, sorted with oldest source that played a SFX as first node.
Declaration
protected LinkedList<AudioSource> AllAudioLayers { get; }
Property Value
Type | Description |
---|---|
LinkedList<AudioSource> |
Remarks
This is a write-able
AllAudios
All attached audio sources, sorted with oldest source that played a SFX as first node.
Declaration
public IReadOnlyCollection<AudioSource> AllAudios { get; }
Property Value
Type | Description |
---|---|
IReadOnlyCollection<AudioSource> |
AttachedSource
Declaration
protected AudioSource AttachedSource { get; }
Property Value
Type | Description |
---|---|
AudioSource |
ClipVariations
A series of clips to play at random
Declaration
public RandomList<AudioClip> ClipVariations { get; }
Property Value
Type | Description |
---|---|
RandomList<AudioClip> |
IsMutatingPitch
Whether this sound effect's pitch should be mutated
Declaration
public bool IsMutatingPitch { get; set; }
Property Value
Type | Description |
---|---|
Boolean |
IsMutatingVolume
Whether this sound effect's volume should be mutated
Declaration
public bool IsMutatingVolume { get; set; }
Property Value
Type | Description |
---|---|
Boolean |
IsPausedOnTimeStop
Gets or sets whether this sound effect
should pause when
Declaration
public bool IsPausedOnTimeStop { get; set; }
Property Value
Type | Description |
---|---|
Boolean |
LatestAudio
The attached audio source that played the latest SFX.
Declaration
public AudioSource LatestAudio { get; }
Property Value
Type | Description |
---|---|
AudioSource |
NumberOfLayers
The number of one-shot sounds this component will allow to overlap.
Declaration
public int NumberOfLayers { get; set; }
Property Value
Type | Description |
---|---|
Int32 |
OriginalPitch
The original audio source's pitch, before mutation was applied.
Declaration
public float OriginalPitch { get; }
Property Value
Type | Description |
---|---|
Single |
OriginalVolume
The original audio source's volume, before mutation was applied.
Declaration
public float OriginalVolume { get; }
Property Value
Type | Description |
---|---|
Single |
PitchMutationRange
The allowed range the pitch can mutate from the center pitch
Declaration
public Vector2 PitchMutationRange { get; set; }
Property Value
Type | Description |
---|---|
Vector2 |
VolumeMutationRange
The allowed range the volume can mutate from the center pitch
Declaration
public Vector2 VolumeMutationRange { get; set; }
Property Value
Type | Description |
---|---|
Vector2 |
Methods
Pause(SoundEffect.Layer)
Pauses the audio, which can be resumed later.
Declaration
public void Pause(SoundEffect.Layer layerToPause = SoundEffect.Layer.All)
Parameters
Type | Name | Description |
---|---|---|
SoundEffect.Layer | layerToPause |
See Also
Play()
Plays an audio on the latest layer, based on whether
LatestAudio's true
.
Note: this method does not resume a previously paused sound effect.
Declaration
public void Play()
Remarks
If LatestAudio's true
, then this method checks to see the audio's state.
If stopped, a random clip will play on loop, with mutation applied to
pitch and volume if flagged to do so.
If paused, it resumes the paused clip, with pitch and volume unchanged.
Otherwise, this method does nothing.
If LatestAudio's true
, then this method acts like
See Also
Resume(SoundEffect.Layer)
Resumes the audio if it was paused earlier.
Declaration
public void Resume(SoundEffect.Layer layerToResume = SoundEffect.Layer.All)
Parameters
Type | Name | Description |
---|---|---|
SoundEffect.Layer | layerToResume |
Remarks
This method is an alias to UnPause(SoundEffect.Layer).
See Also
Stop(SoundEffect.Layer)
Stops the audio, and rewind to the beginning.
Declaration
public void Stop(SoundEffect.Layer layerToStop = SoundEffect.Layer.All)
Parameters
Type | Name | Description |
---|---|---|
SoundEffect.Layer | layerToStop | Which layer(s) to stop. |
See Also
UnPause(SoundEffect.Layer)
Resumes the audio if it was paused earlier.
Declaration
public void UnPause(SoundEffect.Layer layerToUnPause = SoundEffect.Layer.All)
Parameters
Type | Name | Description |
---|---|---|
SoundEffect.Layer | layerToUnPause |