示例#1
0
    public void PlaySound(string soundName)
    {
        PlaySoundSettings settings = new PlaySoundSettings();

        settings.Init();
        settings.name = soundName;
        soundController.Play(settings);
    }
    public void PlaySFXCue()
    {
        PlaySoundSettings settings = new PlaySoundSettings();

        settings.Init();

        settings.names = new[] { "Coins", "Whosh", "CrackingIce" };
        sfxCue         = soundController.Play(settings);
    }
    public void PlayCrackingIce()
    {
        PlaySoundSettings settings = new PlaySoundSettings();

        settings.Init();

        settings.name = "CrackingIce";
        crackingIce   = soundController.Play(settings);
    }
    public void PlayCoins()
    {
        //You should send this struct to soundController in order to play something.
        PlaySoundSettings settings = new PlaySoundSettings();

        settings.Init();

        settings.name = "Coins";
        //SoundController returns a SoundCueProxy, that can be reused or subscribe to one of it's events.
        coins = soundController.Play(settings);
    }
    public void PlayMusicWithTag()
    {
        PlaySoundSettings settings = new PlaySoundSettings();

        settings.Init();

        settings.name     = "Ballade";
        settings.tagName  = "classical";
        settings.isLooped = true;
        musicWithTag      = soundController.Play(settings);
    }
    public void PlayMusic()
    {
        PlaySoundSettings settings = new PlaySoundSettings();

        settings.Init();

        settings.name         = "Ballade";
        settings.fadeInTime   = 1f;
        settings.fadeOutTime  = 2f;
        settings.categoryName = "Music";   // search only in that category
        settings.parent       = transform; // Use this parent to put the AudioSource's position here.
        settings.isLooped     = true;
        music = soundController.Play(settings);
    }
    public void PlaySFXCueLooped()
    {
        PlaySoundSettings settings = new PlaySoundSettings();

        settings.Init();

        settings.names    = new[] { "Coins", "Whosh", "CrackingIce" };
        settings.isLooped = true;
        sfxCueLoop        = soundController.Play(settings);

        //You can also check when any cue finished playing
        sfxCueLoop.OnPlayCueEnded += (cue) =>
        {
            Debug.LogFormat("Cue with ID {0} finished playing", cue.ID);
        };

        sfxCueLoop.OnPlayEnded += (name) => Debug.LogFormat("Sound \"{0}\" finished playing", name);
    }
示例#8
0
        void PlaySound(PlaySoundSettings _Set, AudioSource _CustomSource)
        {
            if (_Set.Clip)
            {
                if (DIRECT_SOUND)
                {
                    if (_CustomSource != null)
                    {
                        _Set.Source.volume = _Set.Loudness.DbToVolume();
                        _Set.Source.PlayOneShot(_Set.Clip);
                    }
                    else
                    {
                        MainSource.volume = _Set.Loudness.DbToVolume();
                        MainSource.PlayOneShot(_Set.Clip);
                    }
                }
                else if (_Set.Mixer != null)
                {
                    if (_CustomSource != null)
                    {
                        _Set.Source.volume = _Set.Loudness.DbToVolume();
                        _Set.Source.outputAudioMixerGroup = _Set.Mixer;
                        _Set.Source.PlayOneShot(_Set.Clip);
                    }
                    else
                    {
                        MainSource.volume = _Set.Loudness.DbToVolume();
                        MainSource.outputAudioMixerGroup = _Set.Mixer;
                        MainSource.PlayOneShot(_Set.Clip);
                    }
                }
                else
                {
                    Debug.LogError("Error: (" + this.ToString() + ")  Clip: " + _Set.Clip.name + " is set on Directsound = (" + DIRECT_SOUND + ") but there is no mixer chosen!");
                }

                if (_Set.OnlyOnce)//if the sound should only be played once disable the sound
                {
                    _Set.Play = false;
                }
            }
        }
    public void PlayWhosh()
    {
        PlaySoundSettings settings = new PlaySoundSettings();

        settings.Init();

        settings.name         = "Whosh";
        whosh                 = soundController.Play(settings);
        whosh.OnPlayCueEnded += (Cue) =>
        {
            settings = new PlaySoundSettings();
            settings.Init();
            //It is a good practice to reuse the cue you already played.
            //Because soundCueProxy caches all the data and SoundController
            //will not have to go through finding it again.
            settings.soundCueProxy = whosh;
            soundController.Play(settings);
        };
    }
示例#10
0
    // Start is called before the first frame update
    void Start()
    {
        if (SceneManager.GetActiveScene().name == "MenuScene")
        {
            soundController.SetMute("Effects", false);
            soundController.SetMute("Music", false);
        }

        effectsToggle.SetIsOnWithoutNotify(soundController.IsMute("Effects"));
        musicToggle.SetIsOnWithoutNotify(soundController.IsMute("Music"));

        PlaySoundSettings settings = new PlaySoundSettings();

        settings.Init();
        settings.name     = "Music";
        settings.isLooped = true;
        //settings.fadeInTime = 3f;
        //settings.fadeOutTime = 3f;
        soundController.Play(settings);
    }