Exemple #1
0
        private void InsertMoodSound(MoodsSoundSource sound, TimeOfDaySound timeofDay, MoodType type)
        {
            MoodSoundKey key = new MoodSoundKey()
            {
                TimeOfDay = timeofDay, Type = type
            };
            List <IUtopiaSoundSource> soundList;

            if (this.MoodsSounds.TryGetValue(key, out soundList) == false)
            {
                soundList = new List <IUtopiaSoundSource>();
                this.MoodsSounds.Add(key, soundList);
            }
            soundList.Add(sound);
        }
Exemple #2
0
        public override void LoadContent(SharpDX.Direct3D11.DeviceContext context)
        {
            #region Load Derived classes sounds
            foreach (var data in _preLoad)
            {
                ISoundDataSource dataSource = _soundEngine.AddSoundSourceFromFile(data.Path, data.Alias, SourceCategory.FX, priority: data.Priority);
                if (dataSource != null)
                {
                    dataSource.Volume = data.Volume;
                    dataSource.Power  = data.Power;
                }
            }
            #endregion

            #region Load Steps sounds
            //Buffer cube walking sound
            foreach (var cube in _visualWorldParameters.WorldParameters.Configuration.GetAllCubesProfiles().Where(x => x.WalkingOverSound.Count > 0))
            {
                foreach (var walkingSound in cube.WalkingOverSound)
                {
                    RegisterStepSound(cube.Id, new SoundMetaData()
                    {
                        Path   = walkingSound.FilePath,
                        Alias  = walkingSound.Alias ?? Path.GetFileNameWithoutExtension(walkingSound.FilePath),
                        Volume = walkingSound.Volume,
                        Power  = walkingSound.Power
                    }
                                      );
                }
            }

            foreach (var pair in _stepsSounds)
            {
                foreach (var sound in pair.Value)
                {
                    ISoundDataSource dataSource = _soundEngine.AddSoundSourceFromFile(sound.Path, sound.Alias, SourceCategory.FX, priority: 100);
                    if (dataSource != null)
                    {
                        dataSource.Volume = sound.Volume;
                        dataSource.Power  = sound.Power;
                    }
                }
            }

            #endregion

            #region Load biome Ambiant sound

            //Prepare Sound for biomes ========================
            if (_biomesParams != null)
            {
                foreach (var biome in _biomesParams.Biomes)
                {
                    foreach (var biomeSound in biome.AmbientSound)
                    {
                        ISoundDataSource dataSource = _soundEngine.AddSoundSourceFromFile(biomeSound.FilePath, biomeSound.Alias, SourceCategory.Music, priority: biomeSound.Priority);
                        if (dataSource != null)
                        {
                            dataSource.Volume     = biomeSound.Volume;
                            dataSource.isStreamed = true;
                        }
                    }
                }
            }

            #endregion

            #region Mood Sound
            //Load and prefetch Mood sounds ========================
            foreach (var moodSoundFile in Directory.GetFiles(@"Sounds\Moods", "*_*.wma"))
            {
                TimeOfDaySound time;
                MoodType       type;
                string[]       fileMetaData = moodSoundFile.Replace(".wma", "").Split('_');
                if (fileMetaData.Length < 3)
                {
                    time = TimeOfDaySound.FullDay;
                }
                else
                {
                    switch (fileMetaData[2].ToLower())
                    {
                    case "day":
                        time = TimeOfDaySound.Day;
                        break;

                    case "night":
                        time = TimeOfDaySound.Night;
                        break;

                    default:
                        time = TimeOfDaySound.FullDay;
                        break;
                    }
                }

                switch (fileMetaData[1].ToLower())
                {
                case "fear":
                    type = MoodType.Fear;
                    break;

                case "peace":
                    type = MoodType.Peace;
                    break;

                case "dead":
                    type = MoodType.Dead;
                    break;

                default:
                    continue;
                }

                MoodsSoundSource soundSource = new MoodsSoundSource()
                {
                    Alias      = "Mood" + fileMetaData[0],
                    FilePath   = moodSoundFile,
                    Volume     = type == MoodType.Peace ? 0.1f : 0.6f,
                    isStreamed = true
                };

                if (time == TimeOfDaySound.FullDay)
                {
                    InsertMoodSound(soundSource, TimeOfDaySound.Day, type);
                    InsertMoodSound(soundSource, TimeOfDaySound.Night, type);
                }
                else
                {
                    InsertMoodSound(soundSource, time, type);
                }

                ISoundDataSource dataSource = _soundEngine.AddSoundSourceFromFile(soundSource.FilePath, soundSource.Alias, SourceCategory.Music);
                if (dataSource != null)
                {
                    dataSource.Volume = soundSource.Volume;
                    dataSource.Power  = soundSource.Power;
                }
            }
            #endregion

            base.LoadContent(context);
        }