Skip to content

Commit

Permalink
Version updated to 0.2.2.3.
Browse files Browse the repository at this point in the history
Resolved:
1. Now the SoundPocket class uses a new logic for receiving Audio, which has a positive effect on performance. Now Audio is received immediately when the clip starts playing, its id is used for this. In this regard, an error has also been fixed when it was impossible to manage clips that were duplicated.
2. Fixed an error when the CheckInstalledClipsAndDisableIfNotInstalled() method in the SoundPocket class had an unsupported character in its name.
3. Fixed a logical error when the GetAudio(AudioClip audioClip, in Audio.AudioType audioType) method in the EazySoundManager class returned only the first occurrence of the clip, which was misleading, now the method returns a List of all occurrences. In the ListAudio class, the IndexOf(AudioClip) method now also returns a List with indexes of all Audio files containing this clip.
4. General refactoring and optimization. Numerous overloads of the Play and Prepare methods in the EazySoundManager class have been replaced by single methods with optional arguments.
5. The EazySoundManager class has removed a function that allowed for certain groups of sounds to achieve the simultaneous existence of only one instance of the Audio class with a unique AudioClip.
5. Audio classes are now cached and reused instead of creating new ones. This made it possible to reduce garbage allocation to 0. Some garbage can still be allocated at the time of increasing arrays (dictionaries, queues, etc.) which are used in the EazySoundManager class. Also, due to the fact that a custom class is used instead of the usual queue, this allowed a slight increase in performance relative to the approach when classes were created each time.
6. Special collections have been added that represent the implementation of standard collections in c#, but do not have any checks or exception generation in case of incorrect input, which greatly improves performance (for example, StackFast outperforms Queue by about 2.5 times in terms of speed). All collections use a Generic structure, but at the moment collections can only handle reference types normally.
7. Fixed a critical bug when calling the Play() method of the Audio class did not have the proper effect, as a result of which the plugin stopped performing the necessary functions and playback of sounds became impossible.
8. The READMI has been updated.
  • Loading branch information
Linerichka committed Mar 25, 2024
1 parent 5756160 commit 846f0d3
Show file tree
Hide file tree
Showing 17 changed files with 581 additions and 908 deletions.
77 changes: 49 additions & 28 deletions Assets/Lineri/SoundSystem/Eazy Sound Manager/Scripts/Audio.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using UnityEngine;
using System;
using UnityEngine;

namespace Lineri.SoundSystem
{
Expand Down Expand Up @@ -36,7 +37,9 @@ public class Audio
/// Whether the audio is created and updated at least once.
/// </summary>
public bool Activated { get; private set; }


public bool PlayedStart { get; private set; }

public bool Deleted { get; private set; }

/// <summary>
Expand Down Expand Up @@ -208,6 +211,8 @@ public float Min3DDistance

public bool DeleteAudioSource = true;

public bool SourceTransformIsManager = true;

/// <summary>
/// Enum representing the type of audio
/// </summary>
Expand All @@ -230,8 +235,15 @@ public enum AudioType
private float _fadeInterpolater = 0f;
private float _onFadeStartVolume;

public Audio(in int audioID, in AudioType audioType, AudioClip clip, in bool loop, in bool persist, in float volume, in float fadeInValue,
in float fadeOutValue, Transform sourceTransform, AudioSource audioSource, in bool overrideAudioSourceSettings = true)
public Audio()
{
}

/// <summary>
/// Sets the values for the class. Do not call this method manually!
/// </summary>
public void Init(ref int audioID, ref AudioType audioType, AudioClip clip, ref bool loop, ref bool persist, ref float volume, ref float fadeInValue,
ref float fadeOutValue, Transform sourceTransform, AudioSource audioSource, ref bool sourceTransformIsManager, bool overrideAudioSourceSettings = true)
{
// Set unique audio ID
AudioID = audioID;
Expand All @@ -247,46 +259,49 @@ public Audio(in int audioID, in AudioType audioType, AudioClip clip, in bool loo
this.FadeInSeconds = fadeInValue;
this.FadeOutSeconds = fadeOutValue;
this.DeleteAudioSource = overrideAudioSourceSettings;
this.SourceTransformIsManager = sourceTransformIsManager;
this._targetVolume = volume;
this._initTargetVolume = volume;

// Initliaze states
IsPlaying = false;
Paused = false;
Activated = false;
Deleted = false;

// Set important values
audioSource.clip = _clip;
audioSource.volume = Volume;
}

/// <summary>
/// Initializes the audiosource component with the appropriate values
/// </summary>
private void SetValueAudioSource()
{
AudioSource audioSource = AudioSource;

if (DeleteAudioSource)
{
AudioSource.clip = _clip;
AudioSource.loop = Loop;
AudioSource.mute = Mute;
AudioSource.volume = Volume;
AudioSource.priority = 128;
AudioSource.pitch = Pitch;
AudioSource.panStereo = 0;
AudioSource.reverbZoneMix = 1;
AudioSource.dopplerLevel = 1;
AudioSource.spatialBlend = 1;
AudioSource.spread = 0;
AudioSource.rolloffMode = AudioRolloffMode.Logarithmic;
AudioSource.minDistance = 1;
AudioSource.maxDistance = 500;
audioSource.loop = Loop;
audioSource.mute = Mute;
audioSource.priority = 128;
audioSource.pitch = Pitch;
audioSource.panStereo = 0;
audioSource.reverbZoneMix = 1;
audioSource.dopplerLevel = 1;
audioSource.spatialBlend = 1;
audioSource.spread = 0;
audioSource.rolloffMode = AudioRolloffMode.Logarithmic;
audioSource.minDistance = 1;
audioSource.maxDistance = 500;
}
//uses the current audio source settings, except for some of them
else
{
AudioSource.clip = _clip;
AudioSource.loop = Loop;
AudioSource.volume = Volume;
AudioSource.pitch = Pitch;
Mute = AudioSource.mute;
audioSource.loop = Loop;
audioSource.pitch = Pitch;
Mute = audioSource.mute;
}
}

Expand All @@ -297,9 +312,9 @@ public void Update()
{
if (!Activated)
{
_fadeInterpolater = -Time.unscaledDeltaTime;
SetValueAudioSource();
Activated = true;
_fadeInterpolater = -Time.unscaledDeltaTime;
}

// Increase/decrease volume to reach the current target
Expand Down Expand Up @@ -355,9 +370,8 @@ public void Update()
IsPlaying = false;
Paused = false;
}

// Update playing status
if (AudioSource.isPlaying != IsPlaying && Application.isFocused)
else if (Application.isFocused)
{
IsPlaying = AudioSource.isPlaying;
}
Expand All @@ -377,6 +391,7 @@ public void Play()
/// <param name="volume">The target volume</param>
public void Play(float volume)
{
PlayedStart = true;
IsPlaying = true;
AudioSource.Play();
SetVolume(volume);
Expand Down Expand Up @@ -477,12 +492,18 @@ public void Set3DDistances(float min, float max)

public void Delete()
{
AudioSource.Stop();
if (IsPlaying)
{
AudioSource.Stop();
}

Stopping = false;
IsPlaying = false;
Paused = false;
AudioSource = null;
Deleted = true;
Activated = false;
PlayedStart = false;
}
}
}
Loading

0 comments on commit 846f0d3

Please sign in to comment.