示例#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);
    }
    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);
        };
    }
    // 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);
    }