コード例 #1
0
    public void OnUpdate()
    {
        if (IsFinished())
        {
            return;
        }

        _transform.position += _transform.forward * _speed * Time.deltaTime;
        _hit = HandleAttackResult.DoRangeDamage(_agent, _transform, _damage, _hitMomentum);
    }
コード例 #2
0
    public override void OnUpdate()
    {
        switch (_state)
        {
        case AttackRollState.PREPARE:
        {
            UpdateFinalRotation();
            if (_rotationOk == false)
            {
                _curRotationTime += Time.deltaTime;
                if (_curRotationTime >= _rotationTime)
                {
                    _curRotationTime = _rotationTime;
                    _rotationOk      = true;
                }

                float      progress = _curRotationTime / _rotationTime;
                Quaternion q        = Quaternion.Lerp(_startRotation, _finalRotation, progress);
                Agent.Transform.rotation = q;
            }

            if (_endOfStateTime < Time.timeSinceLevelLoad)
            {
                InitializeRoll();
            }
        }
        break;

        case AttackRollState.ROLL:
        {
            if (TransformTools.Instance.MoveOnGround(Agent.Transform, Agent.CharacterController,
                                                     Agent.Transform.forward * Agent.BlackBoard.attackRollSpeed * Time.deltaTime, false) == false)
            {
                HandleAttackResult.DoRollDamage(Agent, _eventAttackRoll.animAttackData, Agent.BlackBoard.attackRollWeaponRange);
                InitializeStandUp();
            }
            else if (_hitTimer < Time.timeSinceLevelLoad)
            {
                HandleAttackResult.DoRollDamage(Agent, _eventAttackRoll.animAttackData, Agent.BlackBoard.attackRollWeaponRange);
                _hitTimer = Time.timeSinceLevelLoad + Agent.BlackBoard.attackRollHitTime;        //0.2f;
            }
        }
        break;

        case AttackRollState.STAND_UP:
        {
            if (_endOfStateTime < Time.timeSinceLevelLoad)
            {
                IsFinished = true;
                _eventAttackRoll.IsFinished = true;
            }
        }
        break;
        }
    }
コード例 #3
0
    public override void OnUpdate()
    {
        UpdateFinalRotation();

        _rotationProgress       += Time.deltaTime * Agent.BlackBoard.rotationSmoothInMove;
        _rotationProgress        = Mathf.Min(_rotationProgress, 1);
        Agent.Transform.rotation = Quaternion.Slerp(_startRotation, _finalRotation, _rotationProgress);
        if (Agent.AnimEngine[_eventWhirl.data.animName].time >
            Agent.AnimEngine[_eventWhirl.data.animName].length * 0.1f /*为了防止动画开始时候的滑步*/)
        {
            float preSpeed  = Agent.BlackBoard.speed;
            float curSmooth = Agent.BlackBoard.speedSmooth * Time.deltaTime;
            Agent.BlackBoard.speed = Mathfx.Hermite(Agent.BlackBoard.speed,
                                                    Agent.BlackBoard.maxWhirlMoveSpeed, curSmooth);
            Agent.BlackBoard.moveDir = Agent.Forward;

            float dist    = Agent.BlackBoard.speed * Time.deltaTime;
            bool  _moveOk = TransformTools.MoveOnGround(Agent.transform, Agent.CharacterController,
                                                        Agent.BlackBoard.moveDir * dist, true);
            if (_moveOk == false)
            {
                Agent.BlackBoard.speed = preSpeed;
            }
        }

        if (_hitTimer < Time.timeSinceLevelLoad) // 伤害结算计时
        {
            HandleAttackResult.DoMeleeDamage(Agent, _eventWhirl.target /*Agent.BlackBoard.desiredTarget*/, Agent.BlackBoard.weaponSelected,
                                             _eventWhirl.data, false, false, false);
            _hitTimer = Time.timeSinceLevelLoad + Agent.BlackBoard.attackWhirlHitTime;//0.75f;
        }

        if (_timeToEndState < Time.timeSinceLevelLoad)
        {
            IsFinished             = true;
            _eventWhirl.IsFinished = true;
        }
    }
コード例 #4
0
    public override void OnUpdate()
    {
        if (_attackStatus == AttackStatus.PREPARING)
        {
            bool dontMove = false;
            if (_rotationOk == false)
            {
                _currentRotationTime += Time.deltaTime;
                if (_currentRotationTime >= _rotationTime)
                {
                    _currentRotationTime = _rotationTime;
                    _rotationOk          = true;
                }
                float      progress = _currentRotationTime / _rotationTime;
                Quaternion rotation = Quaternion.Lerp(_startRotation, _finalRotation, progress);
                Agent.Transform.rotation = rotation;
            }

            if (_positionOK == false)
            {
                _currentMoveTime += Time.deltaTime;
                if (_currentMoveTime >= _moveTime)
                {
                    _currentMoveTime = _moveTime;
                    _positionOK      = true;
                    ParticleTools.Instance.Stop(Agent.particleSystemFlashTust);
                }

                if (_currentMoveTime > 0)
                {
                    float   progress = _currentMoveTime / _moveTime;
                    Vector3 finalPos = Mathfx.Hermite(_startPosition, _finalPosition, progress);
                    //if (MoveToCollideWithEnemy(finalPos, Transform.forward) == false)
                    if (TransformTools.Instance.MoveOnGround(Agent.transform, Agent.CharacterController,
                                                             finalPos - Agent.Transform.position, true) == false)
                    {
                        _positionOK = true;
                        ParticleTools.Instance.Stop(Agent.particleSystemFlashTust);
                    }
                }
            }

            if (_rotationOk && _positionOK)
            {
                _attackStatus = AttackStatus.ATTACKING;
                InitializeAttacking();
            }
        }
        else if (_attackStatus == AttackStatus.ATTACKING)
        {
            _currentMoveTime += Time.deltaTime;
            if (_attackPhaseTime < Time.timeSinceLevelLoad)
            {
                //Debug.Log(Time.timeSinceLevelLoad + " attack phase done");
                _eventAttackMelee.attackPhaseDone = true;
                _attackStatus = AttackStatus.FINISHED;
            }

            if (_currentMoveTime >= _moveTime)
            {
                _currentMoveTime = _moveTime;
            }

            if (_currentMoveTime > 0 && _currentMoveTime <= _moveTime)
            {
                float   progress = Mathf.Min(1.0f, _currentMoveTime / _moveTime);
                Vector3 finalPos = Mathfx.Hermite(_startPosition, _finalPosition, progress);
                //if (MoveToCollideWithEnemy(finalPos, Transform.forward) == false)
                if (TransformTools.Instance.MoveOnGround(Agent.transform, Agent.CharacterController,
                                                         finalPos - Agent.Transform.position, false) == false)
                {
                    _currentMoveTime = _moveTime;
                }
            }

            if (_hitTimeStart == false && _hitTime <= Time.timeSinceLevelLoad)
            {
                _hitTimeStart = true;
                HandleAttackResult.DoMeleeDamage(Agent, _eventAttackMelee.target, Agent.BlackBoard.attackerWeapon,
                                                 _eventAttackMelee.animAttackData, _isCritical, _knockdown,
                                                 _eventAttackMelee.animAttackData.isFatal);

                // 显示刀光(方案1:美术做好mesh,参见player)
                if (_eventAttackMelee.animAttackData.lastAttackInCombo)
                {
                    HandleTrail.ShowTrail(Agent, _eventAttackMelee.animAttackData, 0.4f);
                }
                else
                {
                    HandleTrail.ShowTrail(Agent, _eventAttackMelee.animAttackData, 0.5f);
                }

                /*// 屏幕震动
                 * if (AnimAttackData.LastAttackInCombo || AnimAttackData.ComboStep == 3)
                 *  CameraBehaviour.Instance.ComboShake(AnimAttackData.ComboStep - 3);
                 *
                 * if (Owner.IsPlayer && AnimAttackData.FullCombo)
                 *  GuiManager.Instance.ShowComboMessage(AnimAttackData.ComboIndex);*/
            }
        }
        else if (_attackStatus == AttackStatus.FINISHED && _endOfStateTime <= Time.timeSinceLevelLoad)
        {
            IsFinished = true;
            _eventAttackMelee.IsFinished = true;
        }
    }
コード例 #5
0
    public override void OnUpdate()
    {
        if (_attackStatus == AttackStatus.PREPARING)
        {
            bool dontMove = false;
            if (_rotationOk == false)
            {
                _currentRotationTime += Time.deltaTime;
                if (_currentRotationTime >= _rotationTime)
                {
                    _currentRotationTime = _rotationTime;
                    _rotationOk          = true;
                }
                float      progress = _currentRotationTime / _rotationTime;
                Quaternion rotation = Quaternion.Lerp(_startRotation, _finalRotation, progress);
                Agent.Transform.rotation = rotation;
            }

            if (_positionOK == false)
            {
                _currentMoveTime += Time.deltaTime;
                if (_currentMoveTime >= _moveTime)
                {
                    _currentMoveTime = _moveTime;
                    _positionOK      = true;
                }

                if (_currentMoveTime > 0)
                {
                    float   progress = _currentMoveTime / _moveTime;
                    Vector3 finalPos = Mathfx.Hermite(_startPosition, _finalPosition, progress);
                    //if (MoveToCollideWithEnemy(finalPos, Transform.forward) == false)
                    if (TransformTools.MoveOnGround(Agent.transform, Agent.CharacterController,
                                                    finalPos - Agent.Transform.position, true) == false)
                    {
                        _positionOK = true;
                    }
                }
            }

            if (_rotationOk && _positionOK)
            {
                _attackStatus = AttackStatus.ATTACKING;
                InitializeAttacking();
            }
        }
        else if (_attackStatus == AttackStatus.ATTACKING)
        {
            _currentMoveTime += Time.deltaTime;
            if (_currentMoveTime >= _moveTime)
            {
                _currentMoveTime = _moveTime;
            }

            if (_currentMoveTime > 0 && _currentMoveTime <= _moveTime)
            {
                float   progress = Mathf.Min(1.0f, _currentMoveTime / _moveTime);
                Vector3 finalPos = Mathfx.Hermite(_startPosition, _finalPosition, progress);
                //if (MoveToCollideWithEnemy(finalPos, Transform.forward) == false)
                if (TransformTools.MoveOnGround(Agent.transform, Agent.CharacterController,
                                                finalPos - Agent.Transform.position, false) == false)
                {
                    _currentMoveTime = _moveTime;
                }
            }

            if (_hitTimeStart == false && _hitTime <= Time.timeSinceLevelLoad)
            {
                _hitTimeStart = true;
                HandleAttackResult.DoMeleeDamage(Agent, _eventAttackCross.target, Agent.BlackBoard.attackerWeapon,
                                                 _eventAttackCross.animAttackData, _isCritical, _knockdown,
                                                 _eventAttackCross.animAttackData.isFatal);
            }

            if (_attackPhaseTime < Time.timeSinceLevelLoad)
            {
                if (--_remainAttackCount > 0)
                {
                    // 再次攻击
                    InitializeAttacking(false);
                }
                else
                {
                    _attackStatus = AttackStatus.FINISHED;
                }
            }
        }
        else if (_attackStatus == AttackStatus.FINISHED && _endOfStateTime <= Time.timeSinceLevelLoad)
        {
            //Debug.Log(Time.timeSinceLevelLoad + " attack finished");
            IsFinished = true;
            _eventAttackCross.IsFinished = true;
        }
    }