public virtual void Stop(AudioEmitter emitter)
 {
     if (emitter != null)
     {
         emitter.Stop();
     }
 }
        /// <summary>
        /// Instantly regenerates vitality and applies an adrenaline bonus.
        /// </summary>
        /// <param name="healthAmount">Amount of vitality to be healed.</param>
        /// <param name="bonus">Allow adrenaline bonus?</param>
        /// <param name="bonusDuration">Duration of the adrenaline bonus.</param>
        public virtual void Heal(float healthAmount, bool bonus = false, float bonusDuration = 10)
        {
            if (healthAmount > 0 && m_BodyParts.Count > 0)
            {
                for (int i = 0, bodyPartsCount = m_BodyParts.Count; i < bodyPartsCount; i++)
                {
                    if (m_BodyParts[i])
                    {
                        m_BodyParts[i].Heal(healthAmount / bodyPartsCount); // Heals each body part by the same amount.
                    }
                }

                Invoke(nameof(SetNormalSnapshot), 0);
                m_PlayerBreathSource.Stop();
                m_PlayerHealthSource.ForcePlay(m_HealSound, m_HealVolume);

                if (!bonus)
                {
                    return;
                }

                Limping   = false;
                Trembling = false;
                Bleeding  = false;
                StartCoroutine(m_FPController.AdrenalineShot(bonusDuration));
            }
        }
        /// <summary>
        /// Deals damage on the lower body parts (legs).
        /// </summary>
        protected virtual void FallDamage(float damage)
        {
            for (int i = 0, bodyPartsCount = m_BodyParts.Count; i < bodyPartsCount; i++)
            {
                if (!m_BodyParts[i])
                {
                    continue;
                }

                if (m_BodyParts[i].BodyPart == BodyPart.Leg && !m_BodyParts[i].CanRegenerate)
                {
                    m_BodyParts[i].Damage(damage);

                    if (m_BodyParts[i].Injured)
                    {
                        Limping = true;
                        if (!m_BodyParts[i].CanRegenerate)
                        {
                            m_BodyParts[i].ApplyBleedEffect(damage);
                        }

                        m_PlayerHealthSource.Stop();
                        AudioManager.Instance.PlayClipAtPoint(m_BreakLegsSound, transform.position, 5, 10, m_BreakLegsVolume);
                    }
                }

                if (m_BodyParts[i].BodyPart != BodyPart.FullBody)
                {
                    continue;
                }

                m_BodyParts[i].Damage(damage);
                if (damage > m_BodyParts[i].Vitality * 0.7f && !m_BodyParts[i].CanRegenerate)
                {
                    Limping = true;
                    m_BodyParts[i].ApplyBleedEffect(damage);

                    m_PlayerHealthSource.Stop();
                    AudioManager.Instance.PlayClipAtPoint(m_BreakLegsSound, transform.position, 5, 10, m_BreakLegsVolume);
                }
            }
        }
        /// <summary>
        /// Plays the hiding animation.
        /// </summary>
        public void Hide()
        {
            if (!m_Animator)
            {
                return;
            }

            if (!m_Hide)
            {
                return;
            }

            if (m_HideAnimation.Length == 0)
            {
                return;
            }

            // Normalizes the playing speed.
            m_Animator.speed = 1;

            m_Animator.CrossFadeInFixedTime(m_HideAnimation, 0.1f);
            m_PlayerBodySource.Stop();
            m_PlayerBodySource.ForcePlay(m_HideSound, m_HideVolume);
        }
示例#5
0
        protected virtual void Update()
        {
            // Movement animation
            m_MotionAnimation.MovementAnimation(m_FPController);

            // Breath animation
            m_MotionAnimation.BreathingAnimation(((m_BreathAnimationMode == BreathAnimationMode.EnableWhenAim && m_FPController.IsAiming) ||
                                                  m_BreathAnimationMode == BreathAnimationMode.Unrestricted || m_BreathAnimationMode == BreathAnimationMode.DisableWhenAim && !m_FPController.IsAiming) &&
                                                 Math.Abs(m_HoldBreathDuration) < Mathf.Epsilon ? 1 : 0);

            if (HoldBreath)
            {
                //Hold breath
                if (InputManager.GetButton(m_RunButton) && m_NextHoldBreathTime < Time.time && m_FPController.IsAiming && !m_FPController.TremorTrauma)
                {
                    if (Math.Abs(m_HoldBreathDuration) < Mathf.Epsilon)
                    {
                        m_PlayerGenericSource.Play(m_HoldBreath, m_HoldBreathVolume);
                    }

                    m_HoldBreathDuration += Time.deltaTime;
                    if (m_HoldBreathDuration > m_HoldBreath.length)
                    {
                        m_NextHoldBreathTime = Time.time + 3 + m_HoldBreathDuration;
                        m_HoldBreathDuration = 0;
                        m_PlayerGenericSource.Play(m_Exhale, m_HoldBreathVolume);
                    }
                }
                //Release the breath
                else
                {
                    if (m_HoldBreathDuration > 0)
                    {
                        m_PlayerGenericSource.Stop();
                    }

                    if (m_HoldBreathDuration > m_HoldBreath.length * 0.7f)
                    {
                        m_NextHoldBreathTime = Time.time + 3 + m_HoldBreathDuration;
                        m_PlayerGenericSource.Play(m_Exhale, m_HoldBreathVolume);
                    }

                    m_HoldBreathDuration = 0;
                }
            }

            // Leaning animations
            if (!m_MotionAnimation.Lean)
            {
                return;
            }

            if (m_FPController.State != MotionState.Flying && m_FPController.State != MotionState.Running && m_FPController.State != MotionState.Climbing)
            {
                // Lean by holding the button
                if (GameplayManager.Instance.LeanStyle == ActionMode.Hold)
                {
                    if (InputManager.GetButton(m_LeanLeft) && !InputManager.GetButton(m_LeanRight))
                    {
                        LeanDirection = CanLean(Vector3.left) ? -1 : 0;
                    }

                    if (InputManager.GetButton(m_LeanRight) && !InputManager.GetButton(m_LeanLeft))
                    {
                        LeanDirection = CanLean(Vector3.right) ? 1 : 0;
                    }

                    if (!InputManager.GetButton(m_LeanLeft) && !InputManager.GetButton(m_LeanRight))
                    {
                        LeanDirection = 0;
                    }

                    m_MotionAnimation.LeanAnimation(LeanDirection);
                }
                else
                {
                    // Lean by tapping the button
                    if (InputManager.GetButtonDown(m_LeanLeft) && LeanDirection != -1)
                    {
                        LeanDirection = LeanDirection == 1 ? 0 : -1;
                    }
                    else if (InputManager.GetButtonDown(m_LeanLeft) && LeanDirection == -1)
                    {
                        LeanDirection = 0;
                    }

                    if (InputManager.GetButtonDown(m_LeanRight) && LeanDirection != 1)
                    {
                        LeanDirection = LeanDirection == -1 ? 0 : 1;
                    }
                    else if (InputManager.GetButtonDown(m_LeanRight) && LeanDirection == 1)
                    {
                        LeanDirection = 0;
                    }

                    if ((LeanDirection == -1 && !CanLean(Vector3.left)) || (LeanDirection == 1 && !CanLean(Vector3.right)))
                    {
                        LeanDirection = 0;
                    }

                    m_MotionAnimation.LeanAnimation(LeanDirection);
                }
            }
            else
            {
                LeanDirection = 0;
                m_MotionAnimation.LeanAnimation(0);
            }
        }