internal void Stop(SoundObject soundObject) { int index = m_Playing.IndexOf(soundObject); m_Playing[index] = null; Return(soundObject); }
void Return(SoundObject obj) { if (m_Stack.Count < MaxPoolCount) { m_Stack.Push(obj); } else { obj.Destroy(); } }
public void ReservePool(int count = -1) { if (count < 0) { count = MaxPoolCount; } for (int i = m_TotalCount; i < count; i++) { m_Stack.Push(SoundObject.Create(this, m_Root)); m_TotalCount++; } }
SoundObject Borrow(bool force) { if (m_Stack.Count > 0) { return(m_Stack.Pop()); } else if (m_TotalCount < MaxPoolCount) { m_TotalCount++; return(SoundObject.Create(this, m_Root)); } else if (force) { return(SoundObject.Create(this, m_Root)); } return(null); }
public static SoundObject Create(PlayingList playingList, Transform parent) { SoundObject ret = new SoundObject(); var obj = new GameObject(nameof(SoundObject)); obj.hideFlags = parent.hideFlags; obj.transform.SetParent(parent); var source = obj.AddComponent <AudioSource>(); source.playOnAwake = false; ret.m_PlayingList = playingList; ret.m_Object = obj; ret.m_Source = source; ret.m_TransformCache = source.transform; obj.SetActive(false); return(ret); }