48 lines
1.2 KiB
C#
48 lines
1.2 KiB
C#
using UnityEngine;
|
|
using asap.core.common;
|
|
|
|
namespace asap.core
|
|
{
|
|
public class Sound : MonoBehaviour, IPoolableObject
|
|
{
|
|
public AudioSource audioSource;
|
|
public SoundMainType soundMainType;
|
|
public void OnSpawn()
|
|
{
|
|
soundMainType = SoundMainType.None;
|
|
audioSource.volume = 1f;
|
|
}
|
|
|
|
public void OnDespawn()
|
|
{
|
|
soundMainType = SoundMainType.None;
|
|
audioSource.Stop();
|
|
audioSource.volume = 1f;
|
|
audioSource.priority = 128;
|
|
audioSource.loop = false;
|
|
audioSource.playOnAwake = false;
|
|
audioSource.clip = null;
|
|
audioSource.time = 0f;
|
|
audioSource.outputAudioMixerGroup = null;
|
|
}
|
|
|
|
private IObjectPool pool;
|
|
public void OnPoolCreate(IObjectPool objectPool)
|
|
{
|
|
pool = objectPool;
|
|
if (audioSource == null && this != null)
|
|
audioSource = GetComponent<AudioSource>();
|
|
}
|
|
|
|
public void OnPoolDestroy()
|
|
{
|
|
pool = null;
|
|
}
|
|
|
|
public void ReturnPool()
|
|
{
|
|
pool?.DespawnObject(this);
|
|
}
|
|
}
|
|
}
|