public void StartLoop(GameObject obj, int sfxId, AudioClip clip, float volume = 1.0f)
        {
            int id    = obj.GetInstanceID();
            int count = m_handles.Count;             // ???

            for (int i = 0; i < count; ++i)
            {
                if (m_handles[i].instanceId == id &&
                    m_handles[i].effect == sfxId &&
                    m_handles[i].source.loop == true &&
                    m_handles[i].isFree)
                {
                    if (m_handles[i].source.isPlaying == false)
                    {
                        m_handles[i].source.Play();
                    }
                    return;
                }
            }

            Transform   target = obj.transform;
            SoundHandle handle = GetFreeHandle();

            handle.effect        = sfxId;
            handle.instanceId    = id;
            handle.position      = target.position;
            handle.source.loop   = true;
            handle.source.volume = m_baseVolume * volume;
            handle.state         = SoundHandle.State.Dynamic;
            handle.target        = target;

            handle.source.clip = clip;
            handle.source.Play();
        }
        public void Play(AudioClip clip, float volume = 1.0f)
        {
            SoundHandle handle = GetFreeHandle();

            handle.source.loop   = false;
            handle.source.volume = this.volume * volume;
            handle.state         = SoundHandle.State.Local;
            handle.target        = null;

            handle.source.clip = clip;
            handle.source.Play();
        }
 void Awake()
 {
     m_handles = new List <SoundHandle>(m_numAudioSources);
     for (int i = 0; i < m_numAudioSources; ++i)
     {
         SoundHandle handle = CreateHandle();
         #if UNITY_EDITOR
         handle.entity.SetActive(false);
         #endif
         m_handles.Add(handle);
     }
 }
        public void Play(Transform target, AudioClip clip, float volume = 1.0f)
        {
            SoundHandle handle = GetFreeHandle();

            handle.position      = target.position;
            handle.source.loop   = false;
            handle.source.volume = this.volume * volume;
            handle.state         = SoundHandle.State.Dynamic;
            handle.target        = target;

            handle.source.clip = clip;
            handle.source.Play();
        }
        private SoundHandle GetFreeHandle()
        {
            int count = m_handles.Count;

            for (int i = 0; i < count; ++i)
            {
                if (m_handles[i].isFree)
                {
                #if UNITY_EDITOR
                    m_handles[i].entity.SetActive(true);
                #endif
                    return(m_handles[i]);
                }
            }
            SoundHandle newHandle = CreateHandle();
            m_handles.Add(newHandle);
                #if UNITY_EDITOR
            Log.Warning("Created new sound handle {0}", m_handles.Count);
                #endif
            return(newHandle);
        }