Esempio n. 1
0
    private IEnumerator Swing()
    {
        _canFire    = false;
        _isBlocked  = false;
        _isCanceled = false;
        _animator.SetBool("IsCanceled", false);
        _animator.SetBool("IsBlocked", false);
        AlreadyHitTargets.Clear();
        var direction = Math2.AngleDegToVector(transform.rotation.eulerAngles.z + RotationAdjustment);

        // ready phase
        if (!_isCanceled)
        {
            _animator.SetBool("IsRedying", true);
            if (ReadyMoves != null)
            {
                for (var i = 0; i < ReadyMoves.Count; i++)
                {
                    if (_isCanceled)
                    {
                        break;
                    }
                    var move = ReadyMoves[i];
                    this.GetPubSub()
                    .PublishMessageInContext(new ForceMovementMessage(direction, move.Speed, move.Time,
                                                                      move.AllowOtherMovement));
                    yield return(new WaitForSeconds(move.Time));
                }
            }
        }
        _animator.SetBool("IsRedying", false);

        // swing phase
        if (!_isCanceled)
        {
            _animator.SetBool("IsSwinging", true);
            if (SwingMoves != null)
            {
                direction = Math2.AngleDegToVector(transform.rotation.eulerAngles.z + RotationAdjustment); //recalculate
                for (var i = 0; i < SwingMoves.Count; i++)
                {
                    if (_isBlocked || _isCanceled)
                    {
                        break;
                    }
                    var move = SwingMoves[i];
                    this.GetPubSub()
                    .PublishMessageInContext(new ForceMovementMessage(direction, move.Speed, move.Time,
                                                                      move.AllowOtherMovement));
                    yield return(new WaitForSeconds(move.Time));
                }
            }
        }
        _animator.SetBool("IsSwinging", false);

        //recover phase
        if (!_isCanceled)
        {
            direction = Math2.AngleDegToVector(transform.rotation.eulerAngles.z + RotationAdjustment); // recaulculate
            _animator.SetBool("IsRecovering", true);
            if (RecoverMoves != null)
            {
                for (var i = 0; i < RecoverMoves.Count; i++)
                {
                    if (_isCanceled)
                    {
                        break;
                    }
                    var move = RecoverMoves[i];
                    this.GetPubSub()
                    .PublishMessageInContext(new ForceMovementMessage(direction, move.Speed, move.Time,
                                                                      move.AllowOtherMovement));
                    yield return(new WaitForSeconds(move.Time));
                }
            }
        }
        _animator.SetBool("IsRecovering", false);
        _canFire = true;

        this.GetPubSub().PublishMessageInContext(new AttackEndedMessage());
    }