备份CatanBuilding瘦身独立工程
This commit is contained in:
47
Assets/Scripts/Sound/Sound.cs
Normal file
47
Assets/Scripts/Sound/Sound.cs
Normal file
@@ -0,0 +1,47 @@
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user