/// <summary>
        /// Internal method to check if an input manager is present or not
        /// </summary>
        protected virtual void InternalHandleInput()
        {
            if (_inputManager == null)
            {
                return;
            }

            _verticalInput   = _inputManager.PrimaryMovement.y;
            _horizontalInput = _inputManager.PrimaryMovement.x;

            if (_characterGravity != null)
            {
                if (_characterGravity.ShouldReverseInput())
                {
                    if (_characterGravity.ReverseVerticalInputWhenUpsideDown)
                    {
                        _verticalInput = -_verticalInput;
                    }
                    if (_characterGravity.ReverseHorizontalInputWhenUpsideDown)
                    {
                        _horizontalInput = -_horizontalInput;
                    }
                }
            }
            HandleInput();
        }
Esempio n. 2
0
        /// <summary>
        /// Computes the current aim direction
        /// </summary>
        protected virtual void GetCurrentAim()
        {
            if (_weapon.Owner == null)
            {
                return;
            }

            if ((_weapon.Owner.LinkedInputManager == null) && (_weapon.Owner.CharacterType == Character.CharacterTypes.Player))
            {
                return;
            }

            switch (AimControl)
            {
            case AimControls.Off:
                if (_weapon.Owner == null)
                {
                    return;
                }

                _currentAim = Vector2.right;
                _direction  = Vector2.right;
                if (_characterGravity != null)
                {
                    _currentAim = _characterGravity.transform.right;
                    _direction  = _characterGravity.transform.right;
                }
                break;

            case AimControls.Script:
                _currentAim = (_weapon.Owner.IsFacingRight) ? _currentAim : -_currentAim;
                _direction  = -(transform.position - _currentAim);
                break;

            case AimControls.PrimaryMovement:
                if (_weapon.Owner == null)
                {
                    return;
                }

                if (_weapon.Owner.IsFacingRight)
                {
                    _currentAim = _weapon.Owner.LinkedInputManager.PrimaryMovement;
                    _direction  = transform.position + _currentAim;
                }
                else
                {
                    _currentAim = -_weapon.Owner.LinkedInputManager.PrimaryMovement;
                    _direction  = -(transform.position - _currentAim);
                }

                if (_characterGravity != null)
                {
                    _currentAim = MMMaths.RotateVector2(_currentAim, _characterGravity.GravityAngle);
                    if (_characterGravity.ShouldReverseInput())
                    {
                        _currentAim = -_currentAim;
                    }
                }
                break;

            case AimControls.SecondaryMovement:
                if (_weapon.Owner == null)
                {
                    return;
                }

                if (_weapon.Owner.IsFacingRight)
                {
                    _currentAim = _weapon.Owner.LinkedInputManager.SecondaryMovement;
                    _direction  = transform.position + _currentAim;
                }
                else
                {
                    _currentAim = -_weapon.Owner.LinkedInputManager.SecondaryMovement;
                    _direction  = -(transform.position - _currentAim);
                }
                break;

            case AimControls.Mouse:
                if (_weapon.Owner == null)
                {
                    return;
                }

                _mousePosition   = Input.mousePosition;
                _mousePosition.z = 10;


                _direction   = Camera.main.ScreenToWorldPoint(_mousePosition);
                _direction.z = transform.position.z;

                if (_weapon.Owner.IsFacingRight)
                {
                    _currentAim = _direction - transform.position;
                }
                else
                {
                    _currentAim = transform.position - _direction;
                }
                break;
            }
        }