Exemplo n.º 1
0
        /// <summary>
        /// Update is called every frame, if the MonoBehaviour is enabled.
        /// </summary>
        protected virtual void Update()
        {
            bool lTestInput = (WeaponSets != null && WeaponSets.Count > 0);

            if (lTestInput)
            {
                lTestInput = mMotionController.IsGrounded;
            }
            if (lTestInput)
            {
                lTestInput = IsEquipStoreAllowed;
            }

            if (_InputSource != null && _InputSource.IsEnabled && !mIsEquippingItem)
            {
                if (lTestInput && _UseNumberKeys)
                {
                    for (int i = 0; i < Mathf.Max(WeaponSets.Count, 8); i++)
                    {
                        if (_InputSource.IsJustPressed(KeyCode.Alpha1 + i))
                        {
                            lTestInput       = false;
                            _ActiveWeaponSet = i;
                            StartCoroutine(SwapWeaponSet(i));
                        }
                    }
                }

                if (lTestInput && _ToggleWeaponSetAlias.Length > 0)
                {
                    float lToggle = _InputSource.GetValue(_ToggleWeaponSetAlias);
                    if (lToggle != 0f)
                    {
                        lTestInput = false;
                        StartCoroutine(SwapWeaponSet(_ActiveWeaponSet));
                    }
                }

                if (lTestInput && _ShiftWeaponSetAlias.Length > 0)
                {
                    float lShift = _InputSource.GetValue(_ShiftWeaponSetAlias);
                    if (lShift != 0f)
                    {
                        _ActiveWeaponSet += (lShift < -0.1f ? -1 : (lShift > 0.1f ? 1 : 0));
                        if (_ActiveWeaponSet < 0)
                        {
                            _ActiveWeaponSet = WeaponSets.Count - 1;
                        }
                        else if (_ActiveWeaponSet >= WeaponSets.Count)
                        {
                            _ActiveWeaponSet = 0;
                        }

                        lTestInput = false;
                        StartCoroutine(SwapWeaponSet(_ActiveWeaponSet));
                    }
                }
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// LateUpdate logic for the controller should be done here. This allows us
        /// to support dynamic and fixed update times
        /// </summary>
        /// <param name="rDeltaTime">Time since the last frame (or fixed update call)</param>
        /// <param name="rUpdateIndex">Index of the update to help manage dynamic/fixed updates. [0: Invalid update, >=1: Valid update]</param>
        public override void RigLateUpdate(float rDeltaTime, int rUpdateIndex)
        {
            // Get out if we're not in a valid update
            if (rUpdateIndex < 0)
            {
                return;
            }
            if (mInputSource == null)
            {
                return;
            }

            // Determine the linear movement
            Vector3    lMovement = Vector3.zero;
            Quaternion lRotation = _Transform.rotation;

            float lSpeed = _MoveSpeed;

            if (mInputSource.IsPressed(KeyCode.LeftShift))
            {
                lSpeed *= _FastFactor;
            }
            if (mInputSource.IsPressed(KeyCode.Space))
            {
                lSpeed *= _SlowFactor;
            }

            if (mInputSource.IsViewingActivated)
            {
                // Handle the rotations
                float lYaw         = mInputSource.ViewX;
                float lYawMovement = lYaw * mDegreesPer60FPSTick;
                mYaw = (mYaw + lYawMovement) % 360f;

                float lPitch         = mInputSource.ViewY * (_InvertPitch ? -1 : 1);
                float lPitchMovement = lPitch * mDegreesPer60FPSTick;
                mPitch = (mPitch + lPitchMovement) % 360f;

                lRotation = Quaternion.AngleAxis(mYaw, Vector3.up) * Quaternion.AngleAxis(mPitch, Vector3.right);

                // Handle the movement
                float lInputY = 0f;
                if (mInputSource.IsPressed(KeyCode.E))
                {
                    lInputY = 1f;
                }
                if (mInputSource.IsPressed(KeyCode.Q))
                {
                    lInputY = -1f;
                }

                float lInputX = 0f;
                if (mInputSource.IsPressed(KeyCode.D))
                {
                    lInputX = 1f;
                }
                if (mInputSource.IsPressed(KeyCode.A))
                {
                    lInputX = -1f;
                }

                float lInputZ = 0f;
                if (mInputSource.IsPressed(KeyCode.W))
                {
                    lInputZ = 1f;
                }
                if (mInputSource.IsPressed(KeyCode.S))
                {
                    lInputZ = -1f;
                }

                Vector3 lVelocity = new Vector3(lInputX, lInputY, lInputZ);
                lMovement = lRotation * (lVelocity * lSpeed * rDeltaTime);
            }
            // Deal with the scroll wheel
            else if (mInputSource.GetValue("Mouse ScrollWheel") != 0f)
            {
                float lInputZ = mInputSource.GetValue("Mouse ScrollWheel") * _ScrollFactor;

                Vector3 lVelocity = new Vector3(0f, 0f, lInputZ);
                lMovement = lRotation * (lVelocity * lSpeed * rDeltaTime);
            }

            if (_Anchor == null)
            {
                _Transform.rotation = lRotation;

                // Apply movement if it exists
                if (lMovement.sqrMagnitude > 0f)
                {
                    _Transform.position = _Transform.position + lMovement;
                }
            }
            else
            {
            }
        }