Beispiel #1
0
    public bool PlayMusic(SoundID soundID)
    {
        // Stop current music
        if (musicSource != null)
        {
            // Stop music
            musicSource.Stop();

            // Set disabled
            musicSource.enabled = false;
        }

        // Set music source
        musicSource = musicLookup[soundID];

        if (musicSource != null)
        {
#if EDIT_MODE
            musicSource.Copy(prefabMusicLookup[soundID]);
#endif

            // Set enabled
            musicSource.enabled = true;

            // Play music
            musicSource.Play();

            return(true);
        }

        return(false);
    }
Beispiel #2
0
 public AudioSource SetAudioSource(AudioSource audioSource, AudioInfo audioInfo, params AudioOption[] audioOptions)
 {
     audioSource.Copy(audioInfo.Source);
     audioInfo.ApplyAudioOptions(audioSource, audioOptions);
     audioSource.volume += Random.Range(-audioInfo.randomVolume, audioInfo.randomVolume);
     audioSource.pitch  += Random.Range(-audioInfo.randomPitch, audioInfo.randomPitch);
     return(audioSource);
 }
Beispiel #3
0
    void AddSound(SoundID soundID, AudioSource audioSource)
    {
        AudioSource source = gameObject.AddComponent <AudioSource>();

        source.Copy(audioSource);
        source.enabled = false;

        soundLookup.Add(soundID, source);

#if EDIT_MODE
        prefabSoundLookup.Add(soundID, audioSource);
#endif
    }
        public static AudioSource PlayOnListener(this AudioSource audioSource)
        {
            if (audioSource == null || audioSource.clip == null)
            {
                return(null);
            }

            AudioSource source = audioSource.clip.PlayOnListener();

            source.Copy(audioSource);
            source.Play();

            return(source);
        }
Beispiel #5
0
    public bool PlaySound(SoundID soundID, SoundType type = SoundType.Replace, float delay = 0f)
    {
        if (!isSoundEnabled)
        {
            return(false);
        }

        // Get audio source
        AudioSource audioSource = soundLookup[soundID];

        if (audioSource != null)
        {
#if EDIT_MODE
            audioSource.Copy(prefabSoundLookup[soundID]);
#endif

            // Set enabled
            audioSource.enabled = true;

            if (type == SoundType.Loop)
            {
                audioSource.loop = true;

                if (!audioSource.isPlaying)
                {
                    if (delay > 0)
                    {
                        audioSource.PlayDelayed(delay);
                    }
                    else
                    {
                        audioSource.Play();
                    }
                }
            }
            else
            {
                audioSource.loop = false;

                if (type == SoundType.Replace)
                {
                    if (delay > 0)
                    {
                        audioSource.PlayDelayed(delay);
                    }
                    else
                    {
                        audioSource.Play();
                    }
                }
                else if (type == SoundType.New)
                {
                    audioSource.PlayOneShot(audioSource.clip);
                }
                else if (type == SoundType.Only)
                {
                    if (!audioSource.isPlaying)
                    {
                        if (delay > 0)
                        {
                            audioSource.PlayDelayed(delay);
                        }
                        else
                        {
                            audioSource.Play();
                        }
                    }
                }
            }

            return(true);
        }

        return(false);
    }