From 626381f061cde0c78564f6336e3131835cf20a5b Mon Sep 17 00:00:00 2001 From: chai <215380520@qq.com> Date: Sun, 26 Nov 2023 23:52:30 +0800 Subject: * move --- Assembly_CSharp/UI/AudioPoolSource.cs | 40 +++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 Assembly_CSharp/UI/AudioPoolSource.cs (limited to 'Assembly_CSharp/UI/AudioPoolSource.cs') diff --git a/Assembly_CSharp/UI/AudioPoolSource.cs b/Assembly_CSharp/UI/AudioPoolSource.cs new file mode 100644 index 0000000..883151d --- /dev/null +++ b/Assembly_CSharp/UI/AudioPoolSource.cs @@ -0,0 +1,40 @@ +using UnityEngine; + +public class AudioPoolSource : MonoBehaviour +{ + [SerializeField] + private AudioSource audioS; + + private float timer = -1f; + + private bool active; + + public void PlayClip(AudioClip clip, float volume, float pitchVariance) + { + audioS.Stop(); + audioS.clip = clip; + audioS.pitch = 1f + Random.Range(0f - pitchVariance, pitchVariance); + audioS.volume = volume; + timer = clip.length + 0.1f; + active = true; + audioS.Play(); + } + + private void Update() + { + if (!active) + { + return; + } + timer -= Time.deltaTime; + if (timer <= 0f) + { + active = false; + if (base.transform.parent != null) + { + base.transform.parent = null; + } + SFXManager.instance.sources.Add(this); + } + } +} -- cgit v1.1-26-g67d0