Exemplo n.º 1
0
    /// <summary>
    /// Plays the given sound
    /// Waits until the sound is done playing
    /// Stops the sound and adds it back to the resource pool
    /// If the sound is set to loop then it won't add it back to the queue
    /// until it is done looping
    /// </summary>
    /// <param name="soundName"></param>
    /// <returns></returns>
    IEnumerator PlaySoundRoutine(AudioName soundName, SoundClip clip)
    {
        AudioClipInfo info = m_aduioDictionary[soundName];

        clip.Info   = info;
        clip.Volume = m_sfxVolume;
        clip.Play();

        // Will keep checking until the sound no longer plays
        if (clip.Loops)
        {
            // Check again next frame to see if we are done
            while (clip.IsPlaying)
            {
                yield return(new WaitForEndOfFrame());
            }
        }
        else
        {
            // Wait until the sound is done playing to re-queue it
            yield return(new WaitForSeconds(clip.Length));
        }

        // For safety ensure the sound is stopped
        clip.Stop();
        clip.Info = null;

        m_soundClips.Enqueue(clip);
    }
Exemplo n.º 2
0
        public void resetBMG(AudioSource audioSource)
        {
            SoundClip soundClip = null;

            if (_soundsDictionary.TryGetValue(BMG, out soundClip))
            {
                soundClip.Stop();
            }

            if (audioSource == null)
            {
                return;
            }
            soundClip = audioSource.GetComponent <SoundClip>();
            if (soundClip == null)
            {
                soundClip = audioSource.gameObject.AddComponent <SoundClip>();
            }

            audioSource.loop       = true;
            soundClip.loop         = true;
            _soundsDictionary[BMG] = soundClip;

            musicValue  = appSetting.musicPercent;
            musicEnable = appSetting.musicEnabled;
        }
Exemplo n.º 3
0
 private void OnDisable()
 {
     if (soundClip != null)
     {
         soundClip.Stop();
     }
 }
Exemplo n.º 4
0
    private IEnumerator Activate()
    {
        Trigger.enabled        = false;
        DamageCollider.enabled = false;

        float startTime = Time.time;

        while (Time.time < startTime + WaitTime)
        {
            //print("Waiting");
            yield return(null);
        }

        startTime = Time.time;
        AudioManager.Instance.PlaySoundWithParent("spikes", ESoundChannel.SFX, gameObject);
        while (Time.time < startTime + SpringTime)
        {
            //print("Springing");

            float t = (Time.time - startTime) / SpringTime;
            t = Interpolation.ExpoIn(t);

            DamageCollider.enabled = t > .1f;

            TrapModel.transform.position = Vector3.Lerp(WaitPos.position, SpringPos.position, t);
            yield return(null);
        }
        TrapModel.transform.position = SpringPos.position;

        startTime = Time.time;
        gears     = AudioManager.Instance.PlaySoundWithParent("gears", ESoundChannel.SFX, gameObject, true);
        while (Time.time < startTime + RecoilTime)
        {
            //print("Recoiling");

            float t = (Time.time - startTime) / RecoilTime;

            TrapModel.transform.position = Vector3.Lerp(SpringPos.position, WaitPos.position, t);
            yield return(null);
        }
        TrapModel.transform.position = WaitPos.position;

        DamageCollider.enabled = false;

        startTime = Time.time;
        while (Time.time < startTime + ReloadTime)
        {
            //print("Waiting");
            yield return(null);
        }
        gears.Stop();

        Trigger.enabled = true;
        enemiesHit.Clear();
    }
Exemplo n.º 5
0
    /// <summary>
    /// Stops the current music from playing (if any)
    /// and play the given music
    /// </summary>
    /// <param name="musicName"></param>
    public void PlayMusic(AudioName musicName)
    {
        // Don't know it
        if (!m_aduioDictionary.ContainsKey(musicName))
        {
            Debug.LogWarningFormat("Unknown Music {0}", musicName);
            return;
        }

        // Already playing no need to trigger it
        if (m_musicClip.Info != null && m_musicClip.ClipName == musicName && m_musicClip.IsPlaying)
        {
            return;
        }

        m_musicClip.Stop();

        // Update the music and play it
        m_musicClip.Info   = m_aduioDictionary[musicName];
        m_musicClip.Volume = m_musicVolume;
        m_musicClip.Play();
    }
Exemplo n.º 6
0
    /// <summary>
    /// Handles moving the player based on player input
    /// </summary>
    void Move()
    {
        if (m_input == Vector3.zero)
        {
            AnimController.SetFloat("Speed", 0f);
            if (m_walkingClip != null)
            {
                m_walkingClip.Stop();
            }
            return;
        }
        else
        {
            AnimController.SetFloat("Speed", 1f);

            if (!IsFalling && IsGrounded)
            {
                bool isAlreadyPlaying = m_walkingClip != null && m_walkingClip.IsPlaying;
                if (!isAlreadyPlaying)
                {
                    m_walkingClip = AudioManager.instance.PlaySound(AudioName.Walk);
                }
            }
            else
            {
                if (m_walkingClip != null)
                {
                    m_walkingClip.Stop();
                }
            }
        }

        // m_rigidbody.AddForce(m_input * m_moveSpeed, ForceMode.VelocityChange);
        Vector3 targetPosition = m_rigidbody.position + m_input * m_moveSpeed * Time.deltaTime;

        m_rigidbody.MovePosition(targetPosition);
    }
    IEnumerator FadeOut(SoundClip clip)
    {
        float time       = FadeInTime;
        float origVolume = clip.standardVolume;

        while (time > 0)
        {
            time -= Time.deltaTime;

            clip.volume = Mathf.Lerp(0, origVolume, time / FadeInTime);

            yield return(null);
        }
        clip.volume = 0;
        clip.Stop();
    }
Exemplo n.º 8
0
    /// <summary>
    /// While the camera's recoil is engaged the camera will stop tracking its target
    /// and move in the direction being recoiled until it is released
    /// </summary>
    /// <returns></returns>
    IEnumerator RecoilRoutine()
    {
        TrackTarget            = false;
        m_recoilRoutineStarted = true;
        bool cancelRecoil = false;

        SoundClip clip = AudioManager.instance.PlaySound(AudioName.PullLevel);

        while (IsEnganged)
        {
            cancelRecoil = !GameManager.instance.IsGamePlay ||
                           PlayerScript.IsDead ||
                           PlayerScript.IsFalling ||
                           !PlayerScript.IsGrounded;

            if (cancelRecoil)
            {
                break;
            }

            float speed = GetRecoilSpeed();

            Vector3 targetPosition = new Vector3(
                transform.position.x,
                Mathf.Clamp(transform.position.y - speed, m_maxPosition.y, m_startingPosition.y),
                transform.position.z
                );

            transform.position = Vector3.Lerp(transform.position, targetPosition, m_recoilingSpeed * Time.deltaTime);
            yield return(new WaitForEndOfFrame());
        }

        // Make sure the sound is stopped
        clip.Stop();

        // Play animation
        Vector3 recoilPosition = transform.position;
        float   difference     = m_startingPosition.y - recoilPosition.y;

        // Meets minimum threshold
        // Also, we may have cancelled it
        if (!cancelRecoil && difference >= m_minRecoilDistance)
        {
            AudioManager.instance.PlaySound(AudioName.ReleaseLevel);
            yield return(StartCoroutine(SpringRoutine(transform.position, m_startingPosition)));

            // Find all recoilable objects on the screen to apply the recoil force
            Vector3 force = Vector3.up * (m_springForce * difference);
            AddForceToRecoilables(force);

            // Apply to the player too
            GameManager.instance.PlayerScript.AddRecoilForce(force);
            GameManager.instance.PlayerScript.IsJumping = true;
        }

        TrackTarget = true;

        // Wait for a bit to ensure the objects take-off before we allow this action to be re-enabled
        yield return(new WaitForSeconds(.25f));

        m_recoilRoutineStarted = false;
    }