Skip to content

Commit

Permalink
[v0.0.13] Some proxies
Browse files Browse the repository at this point in the history
  • Loading branch information
g0dzZz-coder committed May 1, 2024
1 parent c12d0e4 commit b1c4e41
Show file tree
Hide file tree
Showing 6 changed files with 86 additions and 1 deletion.
39 changes: 39 additions & 0 deletions Runtime/Source/AudioSourceProxy.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
// SPDX-License-Identifier: Apache-2.0
// © 2024 Nikolay Melnikov <n.melnikov@depra.org>

using Depra.SerializeReference.Extensions;
using Depra.Sound.Clip;
using Depra.Sound.Parameter;
using UnityEngine;
using static Depra.Sound.Module;

namespace Depra.Sound.Source
{
[AddComponentMenu(MENU_PATH + nameof(AudioSourceProxy), DEFAULT_ORDER)]
public sealed class AudioSourceProxy : MonoBehaviour, IAudioSource
{
[SerializeReferenceDropdown]
[UnityEngine.SerializeReference]
private IAudioSource _audioSource;

event IAudioSource.PlayDelegate IAudioSource.Started
{
add => _audioSource.Started += value;
remove => _audioSource.Started -= value;
}

event IAudioSource.StopDelegate IAudioSource.Stopped
{
add => _audioSource.Stopped += value;
remove => _audioSource.Stopped -= value;
}

bool IAudioSource.IsPlaying => _audioSource.IsPlaying;

IAudioClipParameters IAudioSource.Parameters => _audioSource.Parameters;

void IAudioSource.Stop() => _audioSource.Stop();

void IAudioSource.Play(IAudioClip clip) => _audioSource.Play(clip);
}
}
3 changes: 3 additions & 0 deletions Runtime/Source/AudioSourceProxy.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Runtime/Source/DefaultAudioSourceFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

namespace Depra.Sound.Source
{
[Serializable]
public sealed class DefaultAudioSourceFactory : IAudioSourceFactory
{
private readonly UnityAudioSource _original;
Expand Down
39 changes: 39 additions & 0 deletions Runtime/Source/SceneAudioSourceRef.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
// SPDX-License-Identifier: Apache-2.0
// © 2024 Nikolay Melnikov <n.melnikov@depra.org>

using System;
using Depra.Sound.Clip;
using Depra.Sound.Parameter;
using UnityEngine;

namespace Depra.Sound.Source
{
[Serializable]
public sealed class SceneAudioSourceRef : IAudioSource
{
[SerializeField] private GameObject _gameObject;
private IAudioSource _audioSource;

private IAudioSource AudioSource => _audioSource ??= _gameObject.GetComponent<IAudioSource>();

event IAudioSource.PlayDelegate IAudioSource.Started
{
add => AudioSource.Started += value;
remove => AudioSource.Started -= value;
}

event IAudioSource.StopDelegate IAudioSource.Stopped
{
add => AudioSource.Stopped += value;
remove => AudioSource.Stopped -= value;
}

bool IAudioSource.IsPlaying => AudioSource.IsPlaying;

IAudioClipParameters IAudioSource.Parameters => AudioSource?.Parameters;

void IAudioSource.Stop() => AudioSource?.Stop();

void IAudioSource.Play(IAudioClip clip) => AudioSource?.Play(clip);
}
}
3 changes: 3 additions & 0 deletions Runtime/Source/SceneAudioSourceRef.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "com.depra.sound.unity",
"version": "0.0.12",
"version": "0.0.13",
"displayName": "Depra.Sound",
"description": "",
"unity": "2021.3",
Expand Down

0 comments on commit b1c4e41

Please sign in to comment.