Пример #1
0
        private void AddSoundToManager(Cv_SoundInstanceData soundToAdd)
        {
            LinkedList <Cv_SoundInstanceData> soundInstances;

            if (m_SoundInstances.TryGetValue(soundToAdd.Resource, out soundInstances))
            {
                if (soundInstances.Count >= MAX_INSTANCES_PER_SOUND)
                {
                    StopSound(soundInstances.First.Value);
                }

                soundInstances.AddLast(soundToAdd);
            }
            else
            {
                var soundList = new LinkedList <Cv_SoundInstanceData>();
                soundList.AddLast(soundToAdd);
                m_SoundInstances.Add(soundToAdd.Resource, soundList);
            }

            if (m_EntityToInstancesMap.TryGetValue(soundToAdd.EntityId, out soundInstances))
            {
                soundInstances.AddLast(soundToAdd);
            }
            else
            {
                var soundList = new LinkedList <Cv_SoundInstanceData>();
                soundList.AddLast(soundToAdd);
                m_EntityToInstancesMap.Add(soundToAdd.EntityId, soundList);
            }

            soundToAdd.ListNode = m_SoundInstancesList.AddLast(soundToAdd);
            m_SoundToDataMap.Add(soundToAdd.Instance, soundToAdd);
        }
Пример #2
0
 private void FadeSound(Cv_SoundInstanceData soundToFade, float volume, float interval)
 {
     soundToFade.FadeRemainingTime = interval;
     soundToFade.FinalVolume       = volume;
     soundToFade.Paused            = false;
     soundToFade.Fading            = true;
 }
Пример #3
0
 private void StopSound(Cv_SoundInstanceData soundToStop)
 {
     soundToStop.Instance.Stop(true);
     m_SoundToDataMap.Remove(soundToStop.Instance);
     m_SoundInstancesList.Remove(soundToStop.ListNode);
     m_EntityToInstancesMap[soundToStop.EntityId].Remove(soundToStop);
     m_SoundInstances[soundToStop.Resource].Remove(soundToStop);
     soundToStop.Instance.Dispose();
 }
Пример #4
0
        public void StopSound(Cv_SoundInstanceData instance, bool immediate = false)
        {
            if (instance == null)
            {
                Cv_Debug.Error("Error - No sound defined when trying to stop sound.");
                return;
            }

            if (m_SoundToDataMap.ContainsKey(instance.Instance))
            {
                StopSound(instance);
            }
        }
Пример #5
0
        public void FadeOutSound(Cv_SoundInstanceData instance, float interval)
        {
            if (instance == null)
            {
                Cv_Debug.Error("Error - No sound defined when trying to stop sound.");
                return;
            }

            if (m_SoundToDataMap.ContainsKey(instance.Instance))
            {
                FadeSound(instance, 0, interval);
            }
        }
Пример #6
0
        public void ResumeSound(Cv_SoundInstanceData instance)
        {
            if (instance == null)
            {
                Cv_Debug.Error("Error - No sound defined when trying to resume sound.");
                return;
            }

            if (m_SoundToDataMap.ContainsKey(instance.Instance))
            {
                instance.Instance.Resume();
                instance.Paused = false;
            }
        }
Пример #7
0
        public void ResumeSound(string soundResource, Cv_Entity entity = null)
        {
            if (soundResource == null || soundResource == "")
            {
                Cv_Debug.Error("Error - No sound defined when trying to resume sound.");
                return;
            }

            if (entity != null) //If an entity is specified resumes the first instance of that sound belonging to the entity
            {
                if (!m_EntityToInstancesMap.ContainsKey(entity.ID))
                {
                    return;
                }

                var instances = m_EntityToInstancesMap[entity.ID];

                Cv_SoundInstanceData soundToResume = null;
                foreach (var s in instances)
                {
                    if (s.Resource == soundResource)
                    {
                        soundToResume = s;
                        break;
                    }
                }

                if (soundToResume != null)
                {
                    soundToResume.Instance.Resume();
                    soundToResume.Paused = false;
                }
            }
            else //Resumes all instances of that sound
            {
                if (!m_SoundInstances.ContainsKey(soundResource))
                {
                    return;
                }

                foreach (var s in m_SoundInstances[soundResource])
                {
                    s.Instance.Resume();
                    s.Paused = false;
                }
            }
        }
Пример #8
0
        public void StopSound(string soundResource, Cv_Entity entity = null, bool immediate = false)
        {
            if (soundResource == null || soundResource == "")
            {
                Cv_Debug.Error("Error - No sound defined when trying to stop sound.");
                return;
            }

            if (entity != null) //If an entity is specified removes the first instance of that sound belonging to the entity
            {
                if (!m_EntityToInstancesMap.ContainsKey(entity.ID))
                {
                    return;
                }

                var instances = m_EntityToInstancesMap[entity.ID];

                Cv_SoundInstanceData soundToStop = null;
                foreach (var s in instances)
                {
                    if (s.Resource == soundResource)
                    {
                        soundToStop = s;
                        break;
                    }
                }

                if (soundToStop != null)
                {
                    StopSound(soundToStop);
                }
            }
            else //Removes all instances of that sound
            {
                if (!m_SoundInstances.ContainsKey(soundResource))
                {
                    return;
                }

                m_SoundInstancesListCopy.Clear();
                m_SoundInstancesListCopy.AddRange(m_SoundInstances[soundResource]);
                foreach (var soundToStop in m_SoundInstancesListCopy)
                {
                    StopSound(soundToStop);
                }
            }
        }
Пример #9
0
        public void FadeOutSound(string soundResource, float interval, Cv_Entity entity = null)
        {
            if (soundResource == null || soundResource == "")
            {
                Cv_Debug.Error("Error - No sound defined when trying to stop sound.");
                return;
            }

            if (entity != null) //If an entity is specified fades the first instance of that sound belonging to the entity
            {
                if (!m_EntityToInstancesMap.ContainsKey(entity.ID))
                {
                    return;
                }

                var instances = m_EntityToInstancesMap[entity.ID];

                Cv_SoundInstanceData soundToFade = null;
                foreach (var s in instances)
                {
                    if (s.Resource == soundResource)
                    {
                        soundToFade = s;
                        break;
                    }
                }

                if (soundToFade != null)
                {
                    FadeSound(soundToFade, 0, interval);
                }
            }
            else //Fades all instances of that sound
            {
                if (!m_SoundInstances.ContainsKey(soundResource))
                {
                    return;
                }

                var instances = m_SoundInstances[soundResource];
                foreach (var s in instances)
                {
                    FadeSound(s, 0, interval);
                }
            }
        }
Пример #10
0
        private Cv_SoundInstanceData GetNewSoundInstance(string soundResource, Cv_Entity entity, float volume, float pan, float pitch, bool looping)
        {
            Cv_SoundResource sound = Cv_ResourceManager.Instance.GetResource <Cv_SoundResource>(soundResource, entity.ResourceBundle);

            var soundData     = sound.GetSoundData();
            var soundInstance = soundData.Sound.CreateInstance();

            var playSoundData = new Cv_SoundInstanceData();

            playSoundData.Resource          = soundResource;
            playSoundData.FadeRemainingTime = 0;
            playSoundData.FinalVolume       = volume;
            playSoundData.Paused            = false;
            playSoundData.Instance          = soundInstance;
            playSoundData.Fading            = false;
            playSoundData.EntityId          = entity.ID;

            soundInstance.Volume   = volume * GlobalSoundVolume;
            soundInstance.Pan      = pan;
            soundInstance.Pitch    = pitch;
            soundInstance.IsLooped = looping;

            return(playSoundData);
        }
Пример #11
0
 public bool SoundIsPlaying(Cv_SoundInstanceData instanceData)
 {
     return(m_SoundToDataMap.ContainsKey(instanceData.Instance) && instanceData.Instance.State == SoundState.Playing);
 }