-
Notifications
You must be signed in to change notification settings - Fork 93
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #5950 from decentraland/fix/emote-volume
hotfix: 2023-11-17
- Loading branch information
Showing
14 changed files
with
91 additions
and
53 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
5 changes: 4 additions & 1 deletion
5
unity-renderer/Assets/DCLServices/EmotesService/EmoteAnimationLoaderFactory.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,21 @@ | ||
using AvatarSystem; | ||
using DCL.Providers; | ||
using DCLServices.EmotesService; | ||
|
||
namespace DCL.Emotes | ||
{ | ||
public class EmoteAnimationLoaderFactory | ||
{ | ||
private readonly AddressableResourceProvider resourceProvider; | ||
private readonly EmoteVolumeHandler emoteVolumeHandler; | ||
|
||
public EmoteAnimationLoaderFactory(AddressableResourceProvider resourceProvider) | ||
{ | ||
this.resourceProvider = resourceProvider; | ||
emoteVolumeHandler = new EmoteVolumeHandler(); | ||
} | ||
|
||
public virtual IEmoteAnimationLoader Get() => | ||
new EmoteAnimationLoader(new WearableRetriever(), resourceProvider); | ||
new EmoteAnimationLoader(new WearableRetriever(), resourceProvider, emoteVolumeHandler); | ||
} | ||
} |
50 changes: 50 additions & 0 deletions
50
unity-renderer/Assets/DCLServices/EmotesService/EmoteVolumeHandler.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
using DCL.Helpers; | ||
using DCL.SettingsCommon; | ||
using System.Collections.Generic; | ||
using UnityEngine; | ||
using AudioSettings = DCL.SettingsCommon.AudioSettings; | ||
|
||
namespace DCLServices.EmotesService | ||
{ | ||
public class EmoteVolumeHandler | ||
{ | ||
private const float BASE_VOLUME = 0.2f; | ||
|
||
private readonly List<AudioSource> audioSources = new (); | ||
private readonly ISettingsRepository<AudioSettings> audioSettings; | ||
|
||
public EmoteVolumeHandler() | ||
{ | ||
audioSettings = Settings.i.audioSettings; | ||
audioSettings.OnChanged += OnVolumeChanged; | ||
OnVolumeChanged(audioSettings.Data); | ||
} | ||
|
||
public void AddAudioSource(AudioSource audioSource) | ||
{ | ||
audioSources.Add(audioSource); | ||
SetVolume(audioSource, GetVolume(audioSettings.Data)); | ||
} | ||
|
||
public void RemoveAudioSource(AudioSource audioSource) | ||
{ | ||
audioSources.Remove(audioSource); | ||
} | ||
|
||
private void SetVolume(AudioSource audioSource, float volume) | ||
{ | ||
audioSource.volume = volume; | ||
} | ||
|
||
private void OnVolumeChanged(AudioSettings settings) | ||
{ | ||
float targetVolume = GetVolume(settings); | ||
|
||
foreach (AudioSource audioSource in audioSources) | ||
SetVolume(audioSource, targetVolume); | ||
} | ||
|
||
private static float GetVolume(AudioSettings audioSettings) => | ||
BASE_VOLUME * Utils.ToVolumeCurve(audioSettings.avatarSFXVolume * audioSettings.masterVolume); | ||
} | ||
} |
3 changes: 3 additions & 0 deletions
3
unity-renderer/Assets/DCLServices/EmotesService/EmoteVolumeHandler.cs.meta
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters