Inheritance: MonoBehaviour
Ejemplo n.º 1
0
    // Begin playing the current Level
    public void StartNewLevel()
    {
        currentStage = GameStage.LevelPlaying;

        if (BackgroundMenuMusic.isPlaying)
        {
            StartCoroutine(AudioFader.FadeOut(BackgroundMenuMusic, 0.5f));
        }
        backgroundMusicManager.StartBackgroundMusic();

        if (LevelStartEvent != null)
            LevelStartEvent();

        LevelSetupUI.SetActive(false);
        HUD.SetActive(true);
        LevelEndUI.SetActive(false);

        if (levelEnd != null)
        {
            Destroy(levelEnd);
        }

        Player.transform.position = Vector3.zero;
        GameEndSound.Stop();
    }
Ejemplo n.º 2
0
 void OnDestroy()
 {
     if (_instance == this)
     {
         _instance = null;
     }
 }
        private IEnumerator LoadScene()
        {
            LevelSelectController.Instance.PreLoadLevel();

            // Load the new scene asynchronously and wait until it completes.
            AsyncOperation asyncOperation = SceneManager.LoadSceneAsync(data.SceneName);

            asyncOperation.allowSceneActivation = false;

            while (asyncOperation.progress < 0.9f)
            {
                yield return(null);
            }

            AudioFader fader = FadeMusic();

            if (fader != null)
            {
                while (fader.IsFading)
                {
                    yield return(null);
                }
            }

            asyncOperation.allowSceneActivation = true;
            yield return(asyncOperation);

            Camera     levelSelectCamera = LevelSelectController.Instance.LevelSelectCamera;
            ScreenFade screenFade        = levelSelectCamera.GetComponent <ScreenFade>();

            screenFade.FadeToClear();

            // Force garbage collection to happen before we fade
            // the new scene in to prevent frame drops and make sure the
            // fade in animation is smooth.
            screenFade.AllowFade = false;
            yield return(null);

            GC.Collect();
            yield return(null);

            screenFade.AllowFade = true;

            LevelSelectController.Instance.PostLoadLevel();

            bool wasEnabled = levelSelectCamera.enabled;

            levelSelectCamera.enabled = true;

            CreateLevelSelectResponder();

            while (screenFade.Color.a > 0.0f)
            {
                yield return(null);
            }

            levelSelectCamera.enabled = wasEnabled;

            LevelSelectController.Instance.PostFadeToLevel();
        }
Ejemplo n.º 4
0
    protected virtual void Start()
    {
        fader = gameObject.AddComponent <AudioFader>() as AudioFader;
        if (audioClips.Length == 0 || fader == null)
        {
            Debug.Log("no audio clips or fader found");
        }
        // Saves the original fade time.
        originalFadeTime = fadeTime;
        // Clamps the volume between 0 and 1, in case it was wrongly input.
        // Can be taken out later.
        stemVolume         = Mathf.Clamp(stemVolume, 0.0f, 1.0f);
        originalStemVolume = stemVolume;
        // The volume control of this stem's mixer group.
        mixerControl = GetComponent <MixerGroupVolumeControl>();

        // Creates new audio sources and assigns audio clips to them.
        audioPlayers = new AudioSource[audioClips.Length];
        for (int i = 0; i < audioPlayers.Length; i++)
        {
            audioPlayers[i]      = gameObject.AddComponent <AudioSource>() as AudioSource;
            audioPlayers[i].clip = audioClips[i];
        }

        // Load the default values
        ResetValues();
        // Stem player is ready to be used
        stemPlayerReady = true;
    }
Ejemplo n.º 5
0
    private IEnumerator CrossFadeAudio(int nextLevel)
    {
        yield return(StartCoroutine(AudioFader.FadeOut(BackgroundAudioSource, 0.5f)));

        currentLevel = nextLevel;
        BackgroundAudioSource.clip = collection[selectedCollection].BackgroundMusic[currentLevel];
        yield return(StartCoroutine(AudioFader.FadeIn(BackgroundAudioSource, 0.5f)));
    }
Ejemplo n.º 6
0
    IEnumerator LoadScene(string sceneName)
    {
        StartCoroutine(AudioFader.FadeOut(GameObject.Find("Main Camera").GetComponent <AudioSource>(), transitionTime));
        transitionAnim.SetTrigger(triggerName);
        yield return(new WaitForSeconds(transitionTime));

        SceneManager.LoadScene(sceneName, LoadSceneMode.Single);
    }
Ejemplo n.º 7
0
    // Initializes the MusicController.
    void Start()
    {
        // Creates a fader.
        fader    = gameObject.AddComponent <AudioFader>() as AudioFader;
        isFading = false;

        // This coroutine will be sure all players are initialized before making the MusicController ready.
        StartCoroutine(InitializePlayers_());
    }
Ejemplo n.º 8
0
    void Awake()
    {
        if (!instance)
        {
            instance = this;
        }

        FadeIn();
    }
Ejemplo n.º 9
0
        void Awake()
        {
            sound = GetComponent <GvrAudioSource>();
            if (sound != null)
            {
                initialVolume = sound.volume;
            }

            audioFader = GetComponent <AudioFader>();
        }
    void StartPlaying()
    {
        int timeSamples = PlayerPrefs.GetInt(Constants.musicTimeKey, 0);

        print("time samples (write): " + timeSamples);
        audioSource.Play();
        audioSource.timeSamples = timeSamples;
        audioSource.volume      = 0;
        StartCoroutine(AudioFader.FadeIn(audioSource, 5, 0.7f));
    }
Ejemplo n.º 11
0
    // Called at the start
    private void Start()
    {
        LoadPlayerPrefs();

        LevelSetupUI.SetActive(true);
        HUD.SetActive(false);
        LevelEndUI.SetActive(false);
        GameEndUI.SetActive(false);
        StartCoroutine(AudioFader.FadeIn(BackgroundMenuMusic, 5f));
    }
Ejemplo n.º 12
0
    // Begin playing the current Level
    public void StartNewLevel()
    {
        if (firstRun)
        {
            //If there is no date retrieved, this is the first time.
            var result = FizzyoFramework.Instance.Achievements.CheckAndUnlockAchievement(Achievements[0].AchievementName);
            if (result == FizzyoRequestReturnType.SUCCESS)
            {
                achievementAnimation.UnlockAchievmentUI(Achievements[0].AchievementName, Achievements[0].AchievementTag);
            }
            firstRun = false;
        }
        else
        {
            //Check if the user has been playing long enough for some achievements
            for (int i = 0; i < Achievements.Length; i++)
            {
                if (Achievements[i].DayRequirement > 0 && daysPlayed > Achievements[i].DayRequirement)
                {
                    var result = FizzyoFramework.Instance.Achievements.CheckAndUnlockAchievement(Achievements[i].AchievementName);
                    if (result == FizzyoRequestReturnType.SUCCESS)
                    {
                        achievementAnimation.UnlockAchievmentUI(Achievements[i].AchievementName, Achievements[i].AchievementTag);
                    }
                }
            }
        }

        currentStage = GameStage.LevelPlaying;
        GameStarted  = true;


        if (BackgroundMenuMusic.isPlaying)
        {
            StartCoroutine(AudioFader.FadeOut(BackgroundMenuMusic, 0.5f));
        }
        backgroundMusicManager.StartBackgroundMusic();

        if (LevelStartEvent != null)
        {
            LevelStartEvent();
        }

        LevelSetupUI.SetActive(false);
        HUD.SetActive(true);
        LevelEndUI.SetActive(false);

        if (levelEnd != null)
        {
            Destroy(levelEnd);
        }

        Player.transform.position = Vector3.zero;
        GameEndSound.Stop();
    }
Ejemplo n.º 13
0
 public void StartBackgroundMusic()
 {
     selectedCollection = Random.Range(0, collection.Length);
     if (BackgroundAudioSource.isPlaying)
     {
         BackgroundAudioSource.Stop();
     }
     currentLevel = 0;
     BackgroundAudioSource.clip = collection[selectedCollection].BackgroundMusic[currentLevel];
     StartCoroutine(AudioFader.FadeIn(BackgroundAudioSource, 0.5f));
 }
Ejemplo n.º 14
0
	// Use this for initialization
	void Start () {
	   	obj = GetComponent<DragableObject>();
		fader = GetComponent<AudioFader>();
		obj.OnDragStart += OnDragStart;
		obj.OnDragStop += OnDragStop;

		glowObj = new GameObject ("glow");
		glowObj.transform.parent = this.transform;
		glow = glowObj.AddComponent<SpriteRenderer> ();
		glow.sprite = GetComponent<SpriteRenderer> ().sprite;
		glow.GetComponent<Renderer>().enabled = false;
	}
Ejemplo n.º 15
0
 void Awake()
 {
     if (_instance != null)
     {
         Debug.LogError("More than two instances of SceneAudioManager exist. Destroying this one");
         Destroy(this.transform.root.gameObject);
         return;
     }
     else
     {
         //Restore selection
         _instance = this;
     }
 }
Ejemplo n.º 16
0
    public void OnTriggerExit(Collider other)
    {
        Debug.Log("exit trigger" + this.gameObject.name);
        if (audioTrigger != null)
        {
            //use this to pause with no fade
            //audioTrigger.Pause();



            //use this to fade out
            //StopAllCoroutines();
            Debug.Log("EXIT trigger " + this.gameObject.name);
            StartCoroutine(AudioFader.FadeOut(audioTrigger, 2f));
        }
    }
    IEnumerator SwapChannel(int channel)
    {
        if (channel < channels.Length)
        {
            StartCoroutine(AudioFader.FadeClip(aSource, fadeTime, false));
            yield return(new WaitForSeconds(fadeTime));

            aSource.clip          = channels[channel];
            radioChannelText.text = "Radio: 0" + (channel + 1);
            StartCoroutine(AudioFader.FadeClip(aSource, fadeTime, true));
        }
        else
        {
            StartCoroutine(AudioFader.FadeClip(aSource, fadeTime, false));
            radioChannelText.text = "Radio: Off";
        }
    }
Ejemplo n.º 18
0
    // Use this for initialization
    void Awake()
    {
        if (S == null)
        {
            S = this;
        }

        else if (S != this)
        {
            Destroy(this.gameObject);
            return;
        }

        DontDestroyOnLoad(this.gameObject);
        audioSource = GetComponent <AudioSource>();
        audioFader  = GetComponent <AudioFader>();
    }
Ejemplo n.º 19
0
    private void OnLevelChange(Level level, Level previous)
    {
        var crossfadeDuration = CrossfadeDuration;

        if (previous == null || level.info.act != previous.info.act)
        {
            crossfadeDuration = 0;
        }
        AudioSource song;

        if (previous != null)
        {
            song = songs.GetValueOrDefault(previous.info);
            if (song != null)
            {
                AudioFader.Fade(song, previous.info.soundEnv.song.volume, 0, crossfadeDuration);
            }
        }
        song = songs.GetValueOrDefault(level.info);
        if (song == null)
        {
            song              = Play(level.info.soundEnv.song);
            song.volume       = 0;
            songs[level.info] = song;
        }
        AudioFader.Fade(song, 0, level.info.soundEnv.song.volume, crossfadeDuration);

        if (ambient == null)
        {
            ambient = Create("Ambient sound");
        }
        Play(level.info.soundEnv.dayAmbience, ambient);

        if (eventsCoroutine != null)
        {
            StopCoroutine(eventsCoroutine);
        }
        if (level != null)
        {
            eventsCoroutine = StartCoroutine(PlayEnvEvents());
        }
        else
        {
            eventsCoroutine = null;
        }
    }
Ejemplo n.º 20
0
    // Called at the start
    private void Start()
    {
        FizzyoFramework.Instance.Session.SessionPaused  += Session_SessionPaused;
        FizzyoFramework.Instance.Session.SessionResumed += Session_SessionResumed;
        LoadPlayerHighScore();

        LevelSetupUI.SetActive(true);
        HUD.SetActive(false);
        LevelEndUI.SetActive(false);
        GameEndUI.SetActive(false);
        PauseUI.SetActive(false);

        playerBehaviour = Player.GetComponent <PlayerBehaviour>();

        StartCoroutine(AudioFader.FadeIn(BackgroundMenuMusic, 5f));

        CheckStartupAchievements();
    }
Ejemplo n.º 21
0
    public static void    Initialize()
    {
        if (bInitialized)
        {
            return;
        }

        bInitialized = true;

        vSounds = new List <AudioSrc>();
        vMusics = new List <AudioSrc>();

        pAudioContainer = new GameObject("AudioContainer");

        UnityEngine.Object.DontDestroyOnLoad(pAudioContainer);

        pAudioFader = pAudioContainer.AddComponent <AudioFader>();
    }
Ejemplo n.º 22
0
        private IEnumerator FadeOutProgram()
        {
            StartCoroutine(AudioFader.FadeOut(_rainAudio, FadeTime));
            var duration = 0f;
            var rain     = MaxRain;

            while (duration < FadeTime)
            {
                rain -= MaxRain / (FadeTime * FadeSteps);
                _rainEmission.rateOverTime = rain;
                yield return(new WaitForSeconds(1f / FadeSteps));

                duration += 1f / FadeSteps;
            }

            _rainVision.Stop();
            _callback();
        }
Ejemplo n.º 23
0
    public void OnTriggerEnter(Collider other)
    {
        Debug.Log("entered trigger " + this.gameObject.name);
        Debug.Log("OTHER TAG " + other.tag);
        Debug.Log("AUDIOOO " + audioTrigger);
        if (audioTrigger != null && other.tag == "Player")
        {
            //use this to start with no fade
            //audioTrigger.Play();

            //use this to fade in
            StartCoroutine(AudioFader.FadeIn(audioTrigger, 2f));
        }
        else
        {
            Debug.Log("You have not assigned an audio source in the inspector!");
        }
    }
Ejemplo n.º 24
0
    /// <summary>
    /// Initializes this instance.
    /// </summary>
    protected override void Awake()
    {
        base.Awake();

        if (_primaryFader == null)
        {
            _primaryFader = new AudioFader();
        }
        else
        {
            _primaryFader.Set0();
        }

        if (_secondaryFader == null)
        {
            _secondaryFader = new AudioFader();
        }
        else
        {
            _secondaryFader.Set0();
        }

        if (_audioSource1 == null)
        {
            _audioSource1 = audio;
        }
        else
        {
            if (_audioSource2 && _audioSource1 != audio)   // make sure that by default the primary audio source is _audioSource1
            {
                SwitchAudioSources();
            }
        }

        _Set0();

        _audioController = AudioController.Instance;
        //Debug.Log( "AudioObject.Awake" );

#if OUYA_PAUSE_SYSTEM
        OuyaSDK.registerPauseListener(this);
        OuyaSDK.registerResumeListener(this);
#endif
    }
        private AudioFader FadeMusic()
        {
            GameObject music = GameObject.FindWithTag(MUSIC_TAG);

            if (music == null)
            {
                return(null);
            }

            AudioFader fader = music.GetComponent <AudioFader>();

            if (fader == null)
            {
                return(null);
            }

            fader.targetVolume = 0.0f;

            return(fader);
        }
    public IEnumerator fadeTimer(float fadeTime)
    {
        StartCoroutine(AudioFader.FadeOutAudio(musicSrc, 7));

        render.color = new Color(render.color.r, render.color.g, render.color.b, 0);
        float fadeDurationInSeconds = 5 - 0.7f;
        float timeout    = 0.01f;
        float fadeAmount = 1 / (fadeDurationInSeconds / timeout);

        for (float f = 0; f <= 1; f += fadeAmount)
        {
            Color c = render.color;
            c.a          = f;
            render.color = c;
            yield return(new WaitForSeconds(timeout));
        }

        render.color = new Color(render.color.r, render.color.g, render.color.b, 255);

        scene1.SetActive(false);
        scene2.SetActive(true);

        yield return(new WaitForSeconds(delayBeforeScene2Audio));

        AudioFader.FadeInAudio(interiorSrc, 3, 0.456f);
        AudioFader.FadeOutAudio(windSrc, 2);

        yield return(new WaitForSeconds(delayBeforeScene2));

        fadeDurationInSeconds = fadeOutTime - 0.7f;
        fadeAmount            = 1 / (fadeDurationInSeconds / timeout);

        for (float f = 1; f > 0; f -= fadeAmount)
        {
            Color c = render.color;
            c.a          = f;
            render.color = c;
            yield return(new WaitForSeconds(timeout));
        }
    }
Ejemplo n.º 27
0
    // Use this for initialization
    void Awake()
    {
        if (S == null)
        {
            S = this;
        }
        else if (S != this)
        {
            Destroy(this.gameObject);
            return;
        }

        DontDestroyOnLoad(this.gameObject);

        // Various objects will need to respond to these
        PlayerWon = new UnityEvent();
        GameBegin = new UnityEvent();
        GameOver  = new UnityEvent();

        victorySequence   = VictorySequence;
        deathSequence     = DeathSequence;
        resetGameState    = ResetGameState;
        fadeIntoGameScene = FadeIntoGameScene;

        screenFader = GameObject.FindObjectOfType <ScreenFader>();
        musicPlayer = GameObject.Find("MusicPlayer").GetComponent <AudioSource>();
        musicFader  = musicPlayer.GetComponent <AudioFader>();

        if (SceneManager.GetActiveScene().name == "game")
        {
            GetGameSceneComponents();
        }


        //resultText.text =     "";
        UnityAction <Scene, LoadSceneMode> onSceneLoaded = OnSceneLoaded;

        SceneManager.sceneLoaded += onSceneLoaded;
    }
Ejemplo n.º 28
0
        private IEnumerator FadeInProgram()
        {
            StartCoroutine(AudioFader.FadeIn(_rainAudio, FadeTime, 0.2f));
            var rain     = 0.1f;
            var duration = 0f;

            while (duration < FadeTime)
            {
                rain += MaxRain / (FadeTime * FadeSteps);
                _rainEmission.rateOverTime = rain;
                yield return(new WaitForSeconds(1f / FadeSteps));

                duration += 1f / FadeSteps;
            }
            if (!_rainVision.enabled)
            {
                _rainVision.enabled = true;
            }
            else
            {
                _rainVision.Play();
            }
            StartCoroutine(ThunderProgram());
        }
Ejemplo n.º 29
0
    void FixedUpdate()
    {
        // Check against all layers except Player
        int layerMask = ~LayerMask.GetMask("Player");

        // check a short capsule below the player to see if we're grounded
        isGrounded = Physics.CheckCapsule(playerCollider.bounds.center,
                                          new Vector3(playerCollider.bounds.center.x,
                                                      playerCollider.bounds.min.y - 0.01f,
                                                      playerCollider.bounds.center.z),
                                          0.18f,
                                          layerMask);
        animator.SetBool("isGrounded", isGrounded);
        // Debug.Log("isGrounded: " + isGrounded.ToString());

        moveVector = new Vector3(Input.GetAxisRaw("Horizontal"), 0.0f, Input.GetAxisRaw("Vertical"));

        moveVector = Quaternion.Euler(0, Camera.main.transform.rotation.eulerAngles.y, 0) * moveVector;

        if (isGrounded)
        {
            rb.velocity += moveVector * acceleration * Time.deltaTime;
        }
        else
        {
            // Don't accelerate at full speed in the air
            rb.velocity += moveVector * acceleration * Time.deltaTime / 4.0f;
        }

        Vector3 translationalVelocity = new Vector3(rb.velocity.x, 0.0f, rb.velocity.z);

        if (translationalVelocity.sqrMagnitude > MoveSpeed * MoveSpeed)
        {
            // evil hardcoded drag constant
            translationalVelocity *= 0.75f;
        }
        // Debug.Log(translationalVelocity.magnitude);
        rb.velocity = new Vector3(translationalVelocity.x, rb.velocity.y, translationalVelocity.z);

        if (
            moveVector.sqrMagnitude < 0.5f && isGrounded ||
            translationalVelocity.sqrMagnitude > MoveSpeed * MoveSpeed
            )
        {
            rb.drag = stoppingDrag;
        }
        else
        {
            rb.drag = originalDrag;
        }



        // If we're falling, apply stronger gravity to mitigate the floaty feel
        if (rb.velocity.y < 0.0f)
        {
            // * Note: Physics.gravity is taken to be negative, so we add it
            rb.velocity += Physics.gravity * fallMultiplier * Time.fixedDeltaTime;
        }

        if (isGrounded && rb.velocity.magnitude > 2f)
        {
            StepSounds();
        }
        else
        {
            StartCoroutine(AudioFader.FadeOut(FootstepSrc, 2.0f));
        }

        stepTimer += Time.deltaTime;
    }
Ejemplo n.º 30
0
 void GetSceneComponents()
 {
     screenFader = GameObject.FindObjectOfType <ScreenFader>();
     musicPlayer = GameObject.Find("MusicPlayer").GetComponent <AudioSource>();
     musicFader  = musicPlayer.GetComponent <AudioFader>();
 }
Ejemplo n.º 31
0
 void Start()
 {
     StartCoroutine(AudioFader.FadeIn(GetComponent <AudioSource>(), fadeInTime));
 }
Ejemplo n.º 32
0
 // Fades out using the AudioFader object in deltaTime seconds. If no values is specified, it will use the
 // lowest mixer volume value.
 public void FadeOut(AudioFader fader, float deltaTime, float volume = minMixerVolume)
 {
     fadeFunction = fader.FadeOut(mixer, mixerParameter, deltaTime, volume);
 }