Exemplo n.º 1
0
    protected override void OnHandleEvent(IEventMessage msg)
    {
        if (msg is BattleEvent.DamageHurt)
        {
            if (CharData.IsDead == false)
            {
                BattleEvent.DamageHurt message = msg as BattleEvent.DamageHurt;
                CharData.DamageHurt(message.Damage);
                CharAnim.PlayAnim("getHit");

                // 随机播放角色受击音效
                string soundName = Avatar.GetRandomGetHitSound();
                if (string.IsNullOrEmpty(soundName) == false)
                {
                    AudioManager.Instance.PlaySound(soundName);
                }
            }
        }
        else if (msg is BattleEvent.CharacterDead)
        {
            CharSkill.ForbidAll();
            CharAnim.PlayAnim("die");

            // 播放角色死亡音效
            string soundName = Avatar.GetDeadSound();
            if (string.IsNullOrEmpty(soundName) == false)
            {
                AudioManager.Instance.PlaySound(soundName);
            }
        }
    }
Exemplo n.º 2
0
    protected override void OnUpdateAvatar(float deltaTime)
    {
        if (CharSkill.IsAnyLife())
        {
            return;
        }

        if (CharMove.IsMoving)
        {
            float animSpeed = CharData.MoveSpeed / Avatar.GetRunAnimationSpeed();
            CharAnim.SetSpeed(CharData.CurrentRunAnimName, animSpeed);
            if (CharAnim.IsPlaying(CharData.CurrentRunAnimName) == false)
            {
                CharAnim.PlayAnim(CharData.CurrentRunAnimName, 0.15f);
            }
        }
        else
        {
            if (CharAnim.IsPlaying(CharData.CurrentIdleAnimName) == false)
            {
                CharAnim.PlayAnim(CharData.CurrentIdleAnimName, 0.15f);
            }
        }
    }