예제 #1
0
 /// <summary>
 /// Animate Agent's graphics by legacy Animation Clip.
 /// </summary>
 /// <param name="clip"></param>
 /// <param name="fadeLength"></param>
 private void Animate(AnimationClip clip, float fadeLength = 0.3F)
 {
     if (_agentAnimation != null)
     {
         _agentAnimation.Animate(clip, fadeLength, true);
     }
 }
예제 #2
0
        /// <summary>
        /// Take Agent's health, locking his components for specified
        /// amount of time and inducingspecific sound and animation.
        /// </summary>
        /// <param name="value"></param>
        public void Damage(int value)
        {
            if (!_useHealth)
            {
                return;
            }

            _agent.GetAudioSource().PlayRandomClip(_onDamageSounds);


            _curHealthPoints = Mathf.Max(0, _curHealthPoints - value);
            if (_curHealthPoints < 0)
            {
                _curHealthPoints = 0;
            }

            if (_lockTime > 0)
            {
                _agent.Motion.Lock();
            }
            if (_alive && _curHealthPoints <= 0)
            {
                _alive = false;
                Death.Die();
            }

            // Check wheather Agent needs to animate the damage.
            var animate = true;

            try
            {
                animate = !((_agent.CurrentSkill.State == SkillState.Loading ||
                             _agent.CurrentSkill.State == SkillState.Invoking) &&
                            !_agent.CurrentSkill.Interruptible);
            }
            catch (Exception)
            {
                /*ignore*/
            }

            if (animate)
            {
                switch (_agentAnimation.AnimationMode)
                {
                case AnimationMode.Legacy:
                    _agentAnimation.Animate(AnimationState.TakingDamage, 0, true);
                    break;

                case AnimationMode.Mecanim:
                    _agentAnimation.Animate(_agentAnimation.Parameters.TakeDamageTrigger, _lockTime);
                    break;
                }
            }
            if (_lockTime > 0)
            {
                _agent.StartCoroutine(UnlockMovementEnum());
            }
        }