mirror of
https://github.com/appen-isen/jeu-sans-image.git
synced 2026-03-18 21:50:42 +01:00
50 lines
1.1 KiB
C#
50 lines
1.1 KiB
C#
using NUnit.Framework;
|
|
using UnityEngine;
|
|
|
|
public abstract class ILoopableSound : MonoBehaviour
|
|
{
|
|
protected AudioSource source;
|
|
|
|
protected void CreateSource()
|
|
{
|
|
source = Instantiate(SoundManager.Instance.audioSourcePrefab).GetComponent<AudioSource>();
|
|
source.loop = true;
|
|
}
|
|
|
|
protected void DestroySource()
|
|
{
|
|
if (source != null)
|
|
{
|
|
Destroy(source.gameObject);
|
|
}
|
|
}
|
|
|
|
protected void OnDestroy()
|
|
{
|
|
DestroySource();
|
|
}
|
|
|
|
public void PlayLoopableSound(Vector3 position)
|
|
{
|
|
CreateSource();
|
|
source.transform.position = position;
|
|
PlayLoopableSound();
|
|
}
|
|
|
|
public void PlayLoopableSound(Transform parent, bool spatial)
|
|
{
|
|
CreateSource();
|
|
source.transform.SetParent(parent, false);
|
|
source.spatialBlend = spatial ? 1 : 0;
|
|
PlayLoopableSound();
|
|
}
|
|
|
|
public virtual void PlayLoopableSound() { }
|
|
|
|
public virtual void StopLoopableSound()
|
|
{
|
|
DestroySource();
|
|
}
|
|
|
|
public bool IsPlaying { get { return source != null; } }
|
|
} |