Skip to content

Commit

Permalink
Fix audio in webgl build
Browse files Browse the repository at this point in the history
  • Loading branch information
RimuruDev committed Aug 20, 2023
1 parent 85ec287 commit d6140b4
Show file tree
Hide file tree
Showing 63 changed files with 50 additions and 41 deletions.
10 changes: 5 additions & 5 deletions СallToDurka/Assets/Intenal/AudioDatabase/Audio Database.asset
Original file line number Diff line number Diff line change
Expand Up @@ -15,31 +15,31 @@ MonoBehaviour:
_items:
- Clip: {fileID: 8300000, guid: 26e496547fd02a544bc4fb31daeb47e1, type: 3}
Key: Deadpool
FolderPath: Intenal\[Common]\AudioClips\
FolderPath: Intenal\Common\AudioClips\
Name: Deadpool.mp3
Preload: 1
_id: 849ef66d-df74-4601-a799-def9ddf9512e
- Clip: {fileID: 8300000, guid: 147d3d66c3e21af499bdbd8e0bf85c9c, type: 3}
Key: MEOW
FolderPath: Intenal\[Common]\AudioClips\
FolderPath: Intenal\Common\AudioClips\
Name: MEOW.mp3
Preload: 1
_id: 9e12c275-ffd5-455f-a52b-cab75e1765da
- Clip: {fileID: 8300000, guid: b46f65d0753fbe44488504489d2919ef, type: 3}
Key: SHREK
FolderPath: Intenal\[Common]\AudioClips\
FolderPath: Intenal\Common\AudioClips\
Name: SHREK.mp3
Preload: 1
_id: cd894a0e-b27d-4f57-9d31-dd20deaa69a9
- Clip: {fileID: 8300000, guid: 32e94c05d622092499ec6756661af5fb, type: 3}
Key: MILOS
FolderPath: Intenal\[Common]\AudioClips\
FolderPath: Intenal\Common\AudioClips\
Name: MILOS.mp3
Preload: 1
_id: 8c2a1ef9-48bb-452e-b6f4-b99c1c1018b2
- Clip: {fileID: 8300000, guid: 11356e6c77f9cb54f8ab7cdc86c6d6d1, type: 3}
Key: Floppa
FolderPath: Intenal\[Common]\AudioClips\
FolderPath: Intenal\Common\AudioClips\
Name: FLOPPA.mp3
Preload: 1
_id: a43e6dbd-8e72-4f81-ad10-9bd33e7ebae3
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,10 @@ private void OnDisable()
audioSource.Stop();

foreach (var sourceAudio in FindObjectsOfType<SourceAudio>(true))
{
sourceAudio.Stop();
// sourceAudio._audioSource.time = 0;
}

audioComponent.SetActive(true);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,13 +49,14 @@ public void HangUpPhone()

private void OpenCallPanel(int callID)
{
currentCharacter = callID;

SetActivePanelState(isActive: true);

currentCharacter = callID;

callPanel.callCharacter.sprite = characterDatas.First(character => character.ID == currentCharacter).Sprite;
callPanel.characterName.text = characterDatas.First(character => character.ID == currentCharacter).Name;

print("Play Rington");
generalGameSettings.SourceAudio.Play(generalGameSettings.SourceAudioKey);
generalGameSettings.SourceAudio.Loop = true;
}
Expand All @@ -74,9 +75,9 @@ private void CloseCallPanel()


StopAllAudioSources();

audioComponent.SetActive(true);

YandexGame.ScriptsYG.YandexGame.FullscreenShow();

SetActivePanelState(isActive: false);
Expand All @@ -93,8 +94,11 @@ private void StopAllAudioSources()
audioSource.Stop();

foreach (var sourceAudio in FindObjectsOfType<SourceAudio>(true))
{
sourceAudio.Stop();

// sourceAudio._audioSource.time = 0;
}

audioComponent.SetActive(false);
}
}
Expand Down
File renamed without changes.
10 changes: 5 additions & 5 deletions СallToDurka/Assets/Intenal/Scenes/SampleScene.unity
Original file line number Diff line number Diff line change
Expand Up @@ -958,7 +958,7 @@ MonoBehaviour:
m_Script: {fileID: 11500000, guid: c896f32ca6a24109b8311345ab6aae6c, type: 3}
m_Name:
m_EditorClassIdentifier:
Loop: 0
Loop: 1
--- !u!82 &374964783
AudioSource:
m_ObjectHideFlags: 0
Expand Down Expand Up @@ -1581,7 +1581,7 @@ MonoBehaviour:
m_Script: {fileID: 11500000, guid: c896f32ca6a24109b8311345ab6aae6c, type: 3}
m_Name:
m_EditorClassIdentifier:
Loop: 0
Loop: 1
--- !u!82 &767374261
AudioSource:
m_ObjectHideFlags: 0
Expand Down Expand Up @@ -2226,7 +2226,7 @@ MonoBehaviour:
m_Script: {fileID: 11500000, guid: c896f32ca6a24109b8311345ab6aae6c, type: 3}
m_Name:
m_EditorClassIdentifier:
Loop: 0
Loop: 1
--- !u!82 &1239019681
AudioSource:
m_ObjectHideFlags: 0
Expand Down Expand Up @@ -2728,7 +2728,7 @@ MonoBehaviour:
m_Script: {fileID: 11500000, guid: c896f32ca6a24109b8311345ab6aae6c, type: 3}
m_Name:
m_EditorClassIdentifier:
Loop: 0
Loop: 1
--- !u!82 &1433951824
AudioSource:
m_ObjectHideFlags: 0
Expand Down Expand Up @@ -3355,7 +3355,7 @@ MonoBehaviour:
m_Script: {fileID: 11500000, guid: c896f32ca6a24109b8311345ab6aae6c, type: 3}
m_Name:
m_EditorClassIdentifier:
Loop: 0
Loop: 1
--- !u!82 &1884016727
AudioSource:
m_ObjectHideFlags: 0
Expand Down
52 changes: 27 additions & 25 deletions СallToDurka/Assets/Plugins/Audio/Core/SourceAudio.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@ namespace RimuruDev.Plugins.Audio.Core
[RequireComponent(typeof(AudioSource))]
public class SourceAudio : MonoBehaviour
{
[HideInInspector] public bool Loop;
public bool Loop;

public float Volume
{
get => _audioSource.volume;
set => _audioSource.volume = value;
}

public bool Mute
{
get => _audioSource.mute;
Expand All @@ -28,26 +28,26 @@ public float Pitch

public bool IsPlaying => _audioSource.isPlaying;

private AudioSource _audioSource
public AudioSource _audioSource
{
get
{
if (_audioSourceCech == null)
{
_audioSourceCech = GetComponent<AudioSource>();
_audioSource.clip = null;

Loop = _audioSource.loop;
_audioSource.loop = false;
}

return _audioSourceCech;
}
}

private AudioSource _audioSourceCech;
private Coroutine _playRoutine;

private string _key;
private bool _loadClip;

Expand All @@ -73,7 +73,7 @@ private void OnDisable()
public void Play(string key)
{
_audioSource.Stop();

if (string.IsNullOrEmpty(key))
{
Debug.LogError("key is empty, Source Audio PlaySound: " + gameObject.name);
Expand All @@ -84,7 +84,7 @@ public void Play(string key)
{
StopCoroutine(_playRoutine);
}

_playRoutine = StartCoroutine(PlayRoutine(key));
}

Expand All @@ -93,15 +93,16 @@ private IEnumerator PlayRoutine(string key)
_loadClip = true;
_key = key;
_clip = null;

_audioSource.Stop();
_isPlaying = false;

yield return AudioManagement.Instance.GetClip(key, audioClip => _clip = audioClip);

if (_clip == null)
{
Debug.LogError("Audio Management not found clip at key: " + key + ",\n Source Audio PlaySound: " + gameObject.name);
Debug.LogError("Audio Management not found clip at key: " + key + ",\n Source Audio PlaySound: " +
gameObject.name);
yield break;
}

Expand All @@ -111,8 +112,8 @@ private IEnumerator PlayRoutine(string key)
_lastTime = 0;

_loadClip = false;
// Debug.Log("Start play audio: " + key);

Debug.Log("Start play audio: " + key);
}

public void Play()
Expand All @@ -123,13 +124,13 @@ public void Play()
{
_audioSource.Stop();
}

_audioSource.time = 0;
_audioSource.Play();
_isPlaying = true;
_lastTime = 0;

// Debug.Log("Start play audio: " + _key);
Debug.Log("Start play audio: " + _key);
}
else
{
Expand All @@ -141,23 +142,24 @@ public void Stop()
{
_audioSource.Stop();
_isPlaying = false;
_audioSource.time = 0;
}

private void Update()
{
HandleLoop();
}

private void HandleLoop()
{
if (Loop == false || _clip == null || _loadClip)
{
return;
}

if (_audioSource.time <= 0 && _isPlaying)
{
// Debug.Log("Audio Loop: " + _key);
Debug.Log("Audio Loop: " + _key);

_audioSource.time = 0;
_audioSource.Play();
Expand All @@ -169,9 +171,9 @@ private void Focus()
if (_isFocus == false && _isPlaying && _lastTime > 0)
{
_audioSource.time = _lastTime;
// Debug.Log(_key + " Last Time: " + _lastTime);
Debug.Log(_key + " Last Time: " + _lastTime);
}

_isFocus = true;
}

Expand All @@ -180,10 +182,10 @@ private void UnFocus()
if (_isFocus && _isPlaying)
{
_lastTime = _audioSource.time;
// Debug.Log(_key + "Set Last Time: " + _lastTime);
Debug.Log(_key + "Set Last Time: " + _lastTime);
}

_isFocus = false;
}
}
}
}
2 changes: 1 addition & 1 deletion СallToDurka/ProjectSettings/ProjectSettings.asset
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ PlayerSettings:
vulkanEnableLateAcquireNextImage: 0
vulkanEnableCommandBufferRecycling: 1
loadStoreDebugModeEnabled: 0
bundleVersion: 1.0.0.2
bundleVersion: 1.0.4.20
preloadedAssets: []
metroInputSource: 0
wsaTransparentSwapchain: 0
Expand Down

0 comments on commit d6140b4

Please sign in to comment.