Example #1
0
        // Reproduce un sonido en forma Loop
        public AudioSource PlayLoop(SoundDefinitions soundDef)
        {
            if (IsPlayingSoundDefinition(soundDef))
            {
                StopSound(soundDef);
            }

            GameObject soundLoc = CreateSoundLocation("Loop_" + soundDef.ToString());
            //Create the source
            AudioSource source = soundLoc.AddComponent <AudioSource>();


            GameSound gs = GetTheSoundClip(soundDef);

            gs.SetMainClip();
            SetSource(ref source, soundDef, gs.TheSound, gs.Volume);
            source.loop = true;
            source.Play();

            //Set the source as active
            mActiveAudio.Add(new ClipInfo {
                Source = source, OriginalVolume = gs.Volume, currentVolume = gs.Volume * masterVolume, Definition = soundDef
            });
            return(source);
        }
Example #2
0
        // Reproduce un sonido
        public AudioSource Play(SoundDefinitions soundDef)
        {
            //Create an empty game object
            GameObject soundLoc = CreateSoundLocation("Sound_" + soundDef);
            //Create the Audio source
            AudioSource source = soundLoc != null?soundLoc.AddComponent <AudioSource>() : null;


            if (source != null)
            {
                //Configure the GameSound
                GameSound gs = GetTheSoundClip(soundDef);
                //Sets the main clip
                gs.SetMainClip();
                //Si no hay asignado un audioclip, hay que evitar que pete y avisamos por la consola
                if (gs.TheSound != null)
                {
                    //Configure the AudioSource
                    SetSource(ref source, soundDef, gs.TheSound, gs.Volume);
                    if (source != null && source.clip != null)
                    {
                        //Play it
                        source.Play();
                        //Drstroy it when stop
                        Destroy(soundLoc, gs.TheSound.length);
                    }
                    //Set the source as active
                    if (mActiveAudio != null && GameSounds != null && GameSounds.Count >= (int)soundDef)
                    {
                        mActiveAudio.Add(new ClipInfo {
                            Source = source, OriginalVolume = gs.Volume, currentVolume = gs.Volume * masterVolume, Definition = soundDef
                        });
                    }
                }
                                #if UNITY_EDITOR
                else
                {
                    Debug.Log(string.Format("No hay un Clip de audio asignado al GameSound definido como: {0}.\n" +
                                            "Revisa el listado de definiciones en el prefab '", soundDef));
                }
                                #endif
            }
            return(source);
        }
Example #3
0
        public AudioSource CustomPlay(SoundDefinitions soundDef, float volume, float pitch)
        {
            //Create an empty game object
            GameObject soundLoc = CreateSoundLocation("Sound_" + soundDef);
            //Create the Audio source
            AudioSource source = soundLoc.AddComponent <AudioSource>();
            //source.volume *= masterVolume;

            //Configure the GameSound
            GameSound gs = GetTheSoundClip(soundDef);

            //Sets the main clip
            gs.SetMainClip();
            //Si no hay asignado un audioclip, hay que evitar que pete y avisamos por la consola
            if (gs.TheSound == null)
            {
                //Configure the AudioSource
                SetSource(ref source, soundDef, gs.TheSound, gs.Volume);
                source.pitch  = (pitch < 0) ? 1 : pitch;
                source.volume = (volume < 0) ? gs.Volume : volume;
                //Play it
                source.Play();
                //Drstroy it when stop
                Destroy(soundLoc, gs.TheSound.length);
                //Set the source as active
                mActiveAudio.Add(new ClipInfo {
                    Source = source, OriginalVolume = gs.Volume, currentVolume = gs.Volume * masterVolume, Definition = soundDef
                });
            }
                        #if UNITY_EDITOR
            else
            {
                Debug.Log(string.Format("No hay un Clip de audio asignado al GameSound definido como: {0}.\n" +
                                        "Revisa el listado de definiciones en el prefab '", soundDef));
            }
                        #endif
            return(source);
        }