Beispiel #1
0
 public void PlanetEarthPlay()
 {
     Debug.Log("Play the game!");
     menu_theme[1].Play();
     StartCoroutine(FadeAudioSource.StartFade(menu_theme[0], 2f, 0f));
     Invoke("PlanetEarth", 2f);
 }
    //
    // public void playWheel2() {
    //  if (!source2.isPlaying) {
    //      source2.pitch = trainSpeed*0.55f;
    //      source2.volume = trainSpeed*0.75f;
    //      //set maximum values on the pitch and volume
    //      if (source2.pitch >= 1.4f) {
    //          source2.pitch = 1.4f;
    //      }
    //      if (source2.pitch <= 0.6f) {
    //          source2.pitch = 0.6f;
    //      }
    //
    //      // if (source2.volume <= 0.5f) {
    //      //  source2.volume = 0.5f;
    //      // }
    //
    //      source2.Play();
    //  }
    // }

    // public void playWheel1(float inputVolume) {
    //  if (!source1.isPlaying) {
    //      source1.pitch = trainSpeed*0.55f;
    //      source1.volume = inputVolume;
    //      //set maximum values on the pitch and volume
    //      if (source1.pitch >= 1.4f) {
    //          source1.pitch = 1.4f;
    //      }
    //      if (source1.pitch <= 0.6f) {
    //          source1.pitch = 0.6f;
    //      }
    //
    //      // if (source1.volume <= 0.5f) {
    //      //  source1.volume = 0.5f;
    //      // }
    //
    //      source1.Play();
    //  }
    // }



    public void fade(string name, int number, float durationToFade)
    {
        if (name == "pressure")
        {
            AudioSource[] pressureSources = this.transform.Find("aPressureManager").GetComponents <AudioSource>();
            StartCoroutine(FadeAudioSource.StartFade(pressureSources[number], durationToFade, 0));
        }
        else if (name == "train")
        {
            AudioSource[] trainSources = this.transform.Find("aTrainManager").GetComponents <AudioSource>();
            StartCoroutine(FadeAudioSource.StartFade(trainSources[number], durationToFade, 0));
        }
        else if (name == "ambient")
        {
            AudioSource[] ambientSources = this.transform.Find("aAmbientManager").GetComponents <AudioSource>();
            StartCoroutine(FadeAudioSource.StartFade(ambientSources[number], durationToFade, 0));
        }
        else if (name == "player")
        {
            AudioSource[] playerSources = this.transform.Find("aPlayerManager").GetComponents <AudioSource>();
            StartCoroutine(FadeAudioSource.StartFade(playerSources[number], durationToFade, 0));
        }
        else
        {
            // Debug.Log("Something happened in fade() of AudioManager2");
        }
    }
    void PlayMusic(Music type)
    {
        if (type == currentType)
        {
            return;
        }

        previousType = currentType;
        currentType  = type;

        previousSource = currentSource;
        currentSource  = GetAudioSourceForMusicType(currentType);

        if (previousType != Music.None)
        {
            // Cross fade.
            StartCoroutine(FadeAudioSource.StartFade(previousSource, crossFadeDurationSec, 0));
            StartCoroutine(FadeAudioSource.StartFade(currentSource, crossFadeDurationSec, 1));
        }
        else
        {
            // Start immediately.
            StartCoroutine(FadeAudioSource.StartFade(currentSource, 0.01f, 1));
        }
    }
Beispiel #4
0
 void Awake()
 {
     sound  = soundManager.GetComponent <SoundManager>();
     dialog = dialogBox.GetComponent <DialogBox>();
     music  = Music.GetComponent <FadeAudioSource>();
     fade.canvasRenderer.SetAlpha(1.0f);
     fadeIn();
 }
Beispiel #5
0
 private void Update()
 {
     if (bActive)
     {
         StartCoroutine(FadeAudioSource.StartFade(GetComponent <AudioSource>(), 0.8f, 0.0f));
         animator.SetBool("Active", true);
     }
 }
Beispiel #6
0
 public void changeTrack(string trackName, bool doloop)
 {
     targTrack = trackName;
     loop      = doloop;
     //turn off current audio
     StartCoroutine(FadeAudioSource.StartFade(playing, fadeTime, 0f));
     // no race condition today
     Invoke("playTargTrack", fadeTime + 0.2f);
 }
        /// <summary>
        /// Cross fades to a new clip.
        /// </summary>
        /// <param name="clip">The new clip to be played.</param>
        /// <param name="delay"></param>
        /// <param name="targetVolume"></param>
        /// <param name="startTime">The time marker where to start the clip.</param>
        /// <param name="fadeDuration">The time it take to get to target volume.</param>
        public void CrossFadeToNewClip(AudioClip clip, int delay = 0, float targetVolume = 1f, float startTime = 0f,
                                       float fadeDuration        = 5f)
        {
            AudioSource fadeFrom = Next();

            StartCoroutine(FadeAudioSource.StartFadeOut(fadeFrom, fadeDuration));
            Next();
            FadeIn(clip, delay: delay, duration: fadeDuration, startTime: startTime, targetVolume: targetVolume);
        }
Beispiel #8
0
    public void LevelEnd()
    {
        if (SceneManager.GetActiveScene().name == "10_Epilogue")
        {
            return;
        }

        StartCoroutine(FadeAudioSource.StartFade(musicSource, 3f, 0f));
        aC.FadeRainSources(0f, 3f);
    }
Beispiel #9
0
 public void FadeToLevel(int levelIndex)
 {
     if (audioSource != null)
     {
         StartCoroutine(FadeAudioSource.StartFade(audioSource, audioSource1, 1f, 0f));
         // audioSource=null;
     }
     levelToLoad = levelIndex;
     animator.SetTrigger("FadeOut");
 }
Beispiel #10
0
    public void BossSpawned()
    {
        var bossPos = new Vector3(boss.transform.position.x, Random.Range(-ScreenBounds.yPlayerBound, ScreenBounds.yPlayerBound), boss.transform.position.z);

        bossOn = true;
        Instantiate(boss, bossPos, boss.transform.rotation);
        StopAllCoroutines();
        CancelInvoke();
        StartCoroutine(FadeAudioSource.StartFade(audioSource, 3, 0));
    }
Beispiel #11
0
    public void BossDestroyed()
    {
        Instantiate(extraLife);
        InvokeRepeating("SpawnHordes", 5, timeToSpawnHordes);
        InvokeRepeating("SpawnNormalPowerUps", 1, timeToSpawnNormalCasePowerUps);
        InvokeRepeating("SpawnEpicPowerUps", 2, timeToSpawnEpicCasePowerUps);
        InvokeRepeating("SpawnDangerPowerUps", 5, timeToSpawnDangerCasePowerUps);

        StartCoroutine(FadeAudioSource.StartFade(audioSource, 20, 0.25f));
    }
Beispiel #12
0
 // Start is called before the first frame update
 void Start()
 {
     spriteRenderer  = GetComponent <SpriteRenderer>();
     bossAudioSource = GetComponent <AudioSource>();
     bossAnim        = GetComponent <Animator>();
     InvokeRepeating("FireSting", 2, timeToShotStings);
     InvokeRepeating("FireBubble", 2, timeToShotBubbles);
     gameManager = GameObject.Find("GameManager").GetComponent <GameManager>();
     StartCoroutine(FadeAudioSource.StartFade(bossAudioSource, 10, 0.25f));
     StartCoroutine(BossLimitBounds());
 }
Beispiel #13
0
 void Awake()
 {
     dialogBox    = GameObject.Find("DialogBox");
     dialog       = dialogBox.GetComponent <DialogBox>();
     soundManager = GameObject.Find("SoundManager");
     sound        = soundManager.GetComponent <SoundManager>();
     screenImage  = GameObject.Find("/HP&Score/BlackScreen");
     screen       = screenImage.GetComponent <BlackScreen>();
     MusicManager = GameObject.Find("Music");
     music        = MusicManager.GetComponent <FadeAudioSource>();
 }
Beispiel #14
0
    /// <summary>
    /// Show the question, answers and duration on the screen.
    /// Only shows the question and plays audio - needs to be called AFTER having shown the relevant media clip if it exists.
    /// Called by QuizManager.
    /// </summary>
    /// <param name="q"></param>
    public void ShowQuestion(QuizQuestion q)
    {
        Clear();
        questionComponent.text = q.Question;
        for (int i = 0; i < q.Answers.Count; i++)
        {
            answerComponents[i].text = String.Format("{0}: {1}", GetAnswerLetterByIndex(i), q.Answers[i]);
        }

        PlayAudioFromResources(String.Format($"Quiz/Audio/{q.DetermineAudioName()}"));
        StartCoroutine(FadeAudioSource.StartFade(ambientSource, 1.0f, 1.0f));
    }
Beispiel #15
0
    public void PauseWithFadeOut(string sound, float time)
    {
        Sound s = Array.Find(sounds, item => item.name == sound);

        if (s == null)
        {
            Debug.LogWarning("Sound: " + name + " not found!");
            return;
        }
        StartCoroutine(FadeAudioSource.StartFade(s.source, time, 0));
        StartCoroutine(PauseSound(s, time));
    }
Beispiel #16
0
    /// <summary>
    /// Show the current question as confirming, indicating an answer has been submitted and is about to be validated.
    /// </summary>
    /// <param name="answerIndex"></param>
    public void ShowConfirming(int answerIndex)
    {
        selectedAnswer = answerIndex;

        questionComponent.text = "Het antwoord is...";

        string answer = answerComponents[selectedAnswer].text;

        answerComponents[selectedAnswer].text = String.Format($"[ {answer} ]");

        StopAudioFromResources();
        StartCoroutine(FadeAudioSource.StartFade(ambientSource, 1.0f, 0.5f));
    }
Beispiel #17
0
    /// <summary>
    /// Fade out an specific sound.
    /// Do not call other function of the sound manager that requires a callback function before the first
    /// one finishes and call the callback.
    /// </summary>
    /// <param name="channelIdx"></param>
    /// <param name="fncb"></param>
    public static void FadeOutSound(int channelIdx, float inSecs, SoundManagerCallback cbfn)
    {
        FadeAudioSource fas = new FadeAudioSource();

        fas.initialTime   = Time.realtimeSinceStartup;
        fas.accumTime     = 0;
        fas.initialVolume = fx[channelIdx].volume;
        fas.targetVolume  = 0;
        fas.audioSrc      = fx[channelIdx];
        fas.fadeInSecs    = inSecs;
        fas.fnCb         += cbfn;

        asFades.Add(fas);
    }
Beispiel #18
0
 public void ToggleMusic()
 {
     if (utopianPlaying)
     {
         StartCoroutine(FadeAudioSource.StartFade(utopianSource, 1, 0.0f));
         StartCoroutine(FadeAudioSource.StartFade(distopianSource, 1, 1.0f));
         utopianPlaying = false;
     }
     else
     {
         StartCoroutine(FadeAudioSource.StartFade(utopianSource, 1, 1.0f));
         StartCoroutine(FadeAudioSource.StartFade(distopianSource, 1, 0.0f));
         utopianPlaying = true;
     }
 }
Beispiel #19
0
 void playerLost()
 {
     StartCoroutine(FadeAudioSource.StartFade(SoundSource, 0.5f, 0.0f));
     deathTimer2  = 0;
     clearEnemies = 0;
     massDestroy  = true;
     playerIsDead = true;
     PlayerSprite.GetComponentInChildren <SpriteRenderer>().enabled = false;
     player.GetComponentInParent <PlayerMovement>().enabled         = false;
     MassKillEnemies.GetComponent <BoxCollider2D>().enabled         = true;
     healthText.text    = "HEALTH: " + Health;
     healthSlider.value = Health;
     Instantiate(deathParticle, player.transform.position, player.transform.rotation);
     Instantiate(playerDeathSound, player.transform.position, player.transform.rotation);
 }
        /// <summary>
        /// Fades in the new clip.
        /// </summary>
        public void FadeIn(AudioClip clip, int rollOffMaxDistance = 5, float delay = 0f, float duration = 5f,
                           float targetVolume = 1f, float startTime = 0f)
        {
            Current().loop          = IsLoop;
            Current().rolloffMode   = AudioRolloffMode.Linear;
            Current().maxDistance   = rollOffMaxDistance;
            Current().spatialBlend  = 1f;
            Current().reverbZoneMix = ReverbZoneMix;

            if (Current().outputAudioMixerGroup == null)
            {
                Current().outputAudioMixerGroup = MixerGroup;
            }

            StartCoroutine(FadeAudioSource.StartFadeIn(Current(), duration, clip, targetVolume, startTime, delay));
        }
Beispiel #21
0
    // Start is called before the first frame update
    void Start()
    {
        _fadeAudioSource = GetComponentInChildren <FadeAudioSource>();
        _health          = 1f;
        _canFade         = false;
        _mMeshRenderer   = GetComponent <MeshRenderer>();

        m_ShaderProperty = Shader.PropertyToID("_cutoff");
        m_Renderer       = GetComponentInChildren <Renderer>();

        ps = GetComponentInChildren <ParticleSystem>();

        var main = ps.main;

        main.duration = spawnEffectTime;
    }
Beispiel #22
0
    public void FadeInMusic(int sndId, float inSecs, SoundManagerCallback cbfn)
    {
        if (!SoundConfigParams.useGameMusic)
        {
            return;
        }

        SoundProp sp = GetSoundProp(sndId);

        if (sp != null)
        {
            currentMusicSndProp = sp;

            // Set the position of the current camera in order to play the sound balanced
            if (Camera.main != null)
            {
                music.transform.position = Camera.main.transform.position;
            }

            music.clip   = sp.audioClip;
            music.loop   = sp.loop;
            music.volume = 0;
            music.Play();

            FadeAudioSource fas = new FadeAudioSource();

            fas.initialTime   = Time.realtimeSinceStartup;
            fas.accumTime     = 0;
            fas.initialVolume = 0;
            fas.targetVolume  = MusicVolume * MasterVolume * (sp.volume / 100.0f);
            fas.audioSrc      = music;
            fas.fadeInSecs    = inSecs;



            if (cbfn != null)
            {
                fas.fnCb += cbfn;
            }
            else
            {
                fas.fnCb = null;
            }

            asFades.Add(fas);
        }
    }
Beispiel #23
0
    private void ForcePlayBackgroundNoise(BackgroundNoise type)
    {
        currentType = type;

        previousSource = currentSource;
        currentSource  = GetAudioSource(currentType);

        if (previousSource != null)
        {
            StartCoroutine(FadeAudioSource.StartFade(previousSource, crossFadeDurationSec, 0));
        }

        if (currentSource != null)
        {
            StartCoroutine(FadeAudioSource.StartFade(currentSource, crossFadeDurationSec, volume));
        }
    }
Beispiel #24
0
    public void StartGame(int difficulty)
    {
        isActive              = true;
        gameOver              = false;
        timeToSpawnHordes    /= difficulty;
        EnemyShoot.fireStart /= difficulty;
        EnemyShoot.fireRate  /= difficulty;
        levelSelect           = difficulty;
        titleScreen.SetActive(false);
        StartCoroutine(FadeAudioSource.StartFade(audioSource, 10, 0.25f));
        audioSource.Play();
        InvokeRepeating("SpawnHordes", 2, timeToSpawnHordes);
        SpawnPowerUps();

        //when Mobile add the buttons firebutton and joystick in prefabs into the canvas
        scoreAndButtons.SetActive(true);
    }
Beispiel #25
0
    public void FadeInSound(int sndId, float inSecs, SoundManagerCallback cbfn)
    {
        //if (!ConfigParams.useGameMusic) return;
        SoundProp sp = GetSoundProp(sndId);

        if (sp != null)
        {
            int channeldIdx = getChannelIdx(sp);

            if (channeldIdx != -1)
            {
                // Set the position of the current camera in order to play the sound balanced
                if (Camera.main != null)
                {
                    fx[channeldIdx].transform.position = Camera.main.transform.position;
                }

                fx[channeldIdx].clip   = sp.audioClip;
                fx[channeldIdx].loop   = sp.loop;
                fx[channeldIdx].volume = 0;
                fx[channeldIdx].Play();

                FadeAudioSource fas = new FadeAudioSource();

                fas.initialTime   = Time.realtimeSinceStartup;
                fas.accumTime     = 0;
                fas.initialVolume = 0;
                fas.targetVolume  = FxVolume * MasterVolume * (sp.volume / 100.0f);
                fas.audioSrc      = fx[channeldIdx];
                fas.fadeInSecs    = inSecs;

                if (cbfn != null)
                {
                    fas.fnCb += cbfn;
                }
                else
                {
                    fas.fnCb = null;
                }

                asFades.Add(fas);
            }
        }
    }
Beispiel #26
0
    public void PlayWithFadeIn(string sound, float time)
    {
        Sound s = Array.Find(sounds, item => item.name == sound);

        if (s == null)
        {
            Debug.LogWarning("Sound: " + name + " not found!");
            return;
        }

        s.source.volume = 0;
        StartCoroutine(FadeAudioSource.StartFade(s.source, time, s.volume * (1f + UnityEngine.Random.Range(-s.volumeVariance / 2f, s.volumeVariance / 2f))));
        s.source.pitch = s.pitch * (1f + UnityEngine.Random.Range(-s.pitchVariance / 2f, s.pitchVariance / 2f));

        if (!s.source.isPlaying)
        {
            s.source.Play();
        }
    }
Beispiel #27
0
 private void RespondToThrustInput()
 {
     if (Input.GetKey(KeyCode.Space))
     {
         ApplyThrust();
     }
     if (Input.GetKeyDown(KeyCode.Space))
     {
         audioSource.volume = 1f;
         audioSource.clip   = GemTrekRocketEngine;
         audioSource.Play();
         audioSource.loop = true;
     }
     else if (Input.GetKeyUp(KeyCode.Space))
     {
         StartCoroutine(FadeAudioSource.StartFade(audioSource, 0.01f, 0f));
         exhaustParticles.Stop();
         audioSource.loop = false;
     }
 }
Beispiel #28
0
    private void Update()
    {
        if (counter >= 3)
        {
            bReady = true;

            StartCoroutine(FadeMixerGroup.StartFade(audioMixer_Music, "MusicMasterVolume", 1.0f, 0.0f));
            GetComponent<AudioSource>().minDistance = 30.0f;
            GetComponent<AudioSource>().maxDistance = 130.0f;
        }

        DisplayCounters();

        if (bActive)
        {
            StartCoroutine(FadeAudioSource.StartFade(GetComponent<AudioSource>(), 0.2f, 0.0f));
            animator.SetBool("Active", true);
            StartCoroutine(EndScreenCoroutine());
        }
    }
Beispiel #29
0
    /// <summary>
    /// Show that the quiz has ended and reveal the final score.
    /// </summary>
    /// <param name="victory">Whether the player won (no questions left) or lost (too many incorrect answers).</param>
    public void ShowGameEnded(bool victory, int score)
    {
        Clear();
        scoreComponent.text = "";

        StartCoroutine(FadeAudioSource.StartFade(ambientSource, 3.0f, 0.0f));

        questionComponent.text     = String.Format($"Score: {score}");
        questionComponent.fontSize = 128;
        if (victory)
        {
            questionComponent.color = correctColor;
            notificationSource.PlayOneShot(victorySound);
        }
        else
        {
            questionComponent.color = incorrectColor;
            notificationSource.PlayOneShot(gameOverSound);
            StartCoroutine(GameOverSequence());
        }
    }
Beispiel #30
0
    public void FadeOutMusic(float inSecs, SoundManagerCallback cbfn)
    {
        FadeAudioSource fas = new FadeAudioSource();

        fas.initialTime = Time.realtimeSinceStartup;
        fas.accumTime   = 0;

        if (playingIntro)
        {
            fas.initialVolume = musicIntro.volume;
            fas.audioSrc      = musicIntro;
        }
        else
        {
            fas.initialVolume = music.volume;
            fas.audioSrc      = music;
        }

        fas.fadeInSecs   = inSecs;
        fas.targetVolume = 0;
        fas.fnCb        += cbfn;

        asFades.Add(fas);
    }