public void Dispose() { if (element != null) { element.Stop(); element = null; } }
private void Play() { Debug.Assert(clip != null); element = AudioSystem.Play(clip); element.source.loop = true; element.source.volume = 0.0f; }
public void RecycleOnClipComplete(AudioPoolElement element) { if (element == null) { return; } recycleQueue.Add(element); }
public void Recycle(AudioPoolElement element) { element.Recycle(); // Element could be waiting to be disposed in the recycle queue. // Calling Recycle() directly is treated as "instantly stop this sound and recycle it." // Need to remove from the recycle queue to support this behavior. int indexRecycleQueue = recycleQueue.IndexOf(element); if (indexRecycleQueue >= 0) { recycleQueue.RemoveAt(indexRecycleQueue); } int index = pool.IndexOf(element); Debug.Assert(index >= 0 && index < pool.Count); --nextFree; pool[index] = pool[nextFree]; pool[nextFree] = element; }
private void EnsureCapacityAudioVolume(int capacity, Unity.Collections.Allocator allocator) { Debug.Assert(capacity > 0); if (audioVolume != null && audioVolume.Length > capacity) { return; } // Need to preserve any prexisting values, so that we don't cut out / restart audio on reallocs. AudioPoolElement[] audioPoolElementsNext = new AudioPoolElement[capacity]; if (audioVolume != null) { for (int i = 0; i < audioVolumeCount; ++i) { audioPoolElementsNext[i] = audioPoolElements[i]; } DisposeAudioVolume(); } audioVolume = new NativeArray <float2>(capacity, allocator); audioPoolElements = audioPoolElementsNext; }