Example #1
0
        public SoundEffectGame(AudioListener listener, SoundManager sm, ConfigurationSection sect)
        {
            this.contentManager = sm.Content;
            this.listener       = listener;


            string[] control = sect.GetStringArray("Control");
            for (int i = 0; i < control.Length; i++)
            {
                control[i] = control[i].ToLowerInvariant();
                switch (control[i])
                {
                case "loop":
                    Control |= SoundControl.Loop;
                    break;

                case "random":
                    Control |= SoundControl.Random;
                    break;

                case "ambient":
                    Control |= SoundControl.Ambient;
                    break;
                }
            }
            Probability = sect.GetSingle("Probability", 1);
            Volume      = sect.GetSingle("Volume", 1);
            Type        = (SoundType)Enum.Parse(typeof(SoundType), sect.GetString("Type", SoundType.Normal.ToString()), true);
            //this.soundEffect = contentManager.Load<SoundEffect>(sect.Name);
            soundEffects = new SoundEffect[3][];

            if ((Control & SoundControl.Loop) == SoundControl.Loop)
            {
                string[] fadein = sect.GetStringArray("Fadein");
                soundEffects[(int)SoundEffectPart.Fadein] = new SoundEffect[fadein.Length];
                for (int index = 0; index < fadein.Length; index++)
                {
                    soundEffects[(int)SoundEffectPart.Fadein][0] = contentManager.Load <SoundEffect>(fadein[index]);
                }

                string[] mediumstring = sect.GetStringArray("Medium");
                soundEffects[(int)SoundEffectPart.Medium] = new SoundEffect[mediumstring.Length];
                for (int index = 0; index < mediumstring.Length; index++)
                {
                    soundEffects[(int)SoundEffectPart.Medium][index] = contentManager.Load <SoundEffect>(mediumstring[index]);
                }

                string[] fadeout = sect.GetStringArray("Fadeout");
                soundEffects[(int)SoundEffectPart.Fadeout] = new SoundEffect[fadeout.Length];
                for (int index = 0; index < fadein.Length; index++)
                {
                    soundEffects[(int)SoundEffectPart.Fadeout][0] = contentManager.Load <SoundEffect>(fadeout[index]);
                }
            }
            else
            {
                string[] sounds = sect.GetStringArray("Sounds");
                soundEffects[(int)SoundEffectPart.Fadein] = new SoundEffect[sounds.Length];
                for (int i = 0; i < sounds.Length; i++)
                {
                    soundEffects[0][i] = contentManager.Load <SoundEffect>(sounds[i]);
                }
                soundEffects[1] = soundEffects[0];
                soundEffects[2] = soundEffects[0];
            }
        }
Example #2
0
        public SoundEffectGame(AudioListener listener, SoundManager sm, ConfigurationSection sect)
        {
            this.contentManager = sm.Content;
            this.listener = listener;


            string[] control = sect.GetStringArray("Control");
            for (int i = 0; i < control.Length; i++)
            {
                control[i] = control[i].ToLowerInvariant();
                switch (control[i])
                {
                    case "loop":
                        Control |= SoundControl.Loop;
                        break;
                    case "random":
                        Control |= SoundControl.Random;
                        break;
                    case "ambient":
                        Control |= SoundControl.Ambient;
                        break;
                }
            }
            Probability = sect.GetSingle("Probability", 1);
            Volume = sect.GetSingle("Volume", 1);
            Type = (SoundType)Enum.Parse(typeof(SoundType), sect.GetString("Type", SoundType.Normal.ToString()), true);
            //this.soundEffect = contentManager.Load<SoundEffect>(sect.Name);
            soundEffects = new SoundEffect[3][];

            if ((Control & SoundControl.Loop) == SoundControl.Loop)
            {
                string[] fadein = sect.GetStringArray("Fadein");
                soundEffects[(int)SoundEffectPart.Fadein] = new SoundEffect[fadein.Length];
                for (int index = 0; index < fadein.Length; index++)
                {
                    soundEffects[(int)SoundEffectPart.Fadein][0] = contentManager.Load<SoundEffect>(fadein[index]);
                }

                string[] mediumstring = sect.GetStringArray("Medium");
                soundEffects[(int)SoundEffectPart.Medium] = new SoundEffect[mediumstring.Length];
                for (int index = 0; index < mediumstring.Length; index++)
                {
                    soundEffects[(int)SoundEffectPart.Medium][index] = contentManager.Load<SoundEffect>(mediumstring[index]);
                }

                string[] fadeout = sect.GetStringArray("Fadeout");
                soundEffects[(int)SoundEffectPart.Fadeout] = new SoundEffect[fadeout.Length];
                for (int index = 0; index < fadein.Length; index++)
                {
                    soundEffects[(int)SoundEffectPart.Fadeout][0] = contentManager.Load<SoundEffect>(fadeout[index]);
                }
            }
            else
            {
                string[] sounds = sect.GetStringArray("Sounds");
                soundEffects[(int)SoundEffectPart.Fadein] = new SoundEffect[sounds.Length];
                for (int i = 0; i < sounds.Length; i++)
                {
                    soundEffects[0][i] = contentManager.Load<SoundEffect>(sounds[i]);
                }
                soundEffects[1] = soundEffects[0];
                soundEffects[2] = soundEffects[0];
            }
        }