Example #1
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);
        }