Пример #1
0
        /// <summary>
        /// Initialize the default values.
        /// </summary>
        public override void Awake()
        {
            base.Awake();

            m_Handler = m_GameObject.GetCachedComponent <UltimateCharacterLocomotionHandler>();

            // Work with the handler to listen for any input events.
            if (m_Handler != null)
            {
                m_StartRotateInputEvent = ObjectPool.Get <ActiveInputEvent>();
                m_StartRotateInputEvent.Initialize(ActiveInputEvent.Type.ButtonDown, m_RotateInputName, "OnRPGMovementTypeStartRotate");

                m_StopRotateInputEvent = ObjectPool.Get <ActiveInputEvent>();
                m_StopRotateInputEvent.Initialize(ActiveInputEvent.Type.ButtonUp, m_RotateInputName, "OnRPGMovementTypeStopRotate");

                m_TurnInputEvent = ObjectPool.Get <ActiveInputEvent>();
                m_TurnInputEvent.Initialize(ActiveInputEvent.Type.Axis, m_TurnInputName, "OnRPGMovementTypeTurn");

                m_AutoMoveInputEvent = ObjectPool.Get <ActiveInputEvent>();
                m_AutoMoveInputEvent.Initialize(ActiveInputEvent.Type.ButtonDown, m_AutoMoveInputName, "OnRPGMovementTypeAutoMove");

                m_Handler.RegisterInputEvent(m_StartRotateInputEvent);
                m_Handler.RegisterInputEvent(m_TurnInputEvent);
                m_Handler.RegisterInputEvent(m_AutoMoveInputEvent);
            }
            EventHandler.RegisterEvent(m_GameObject, "OnRPGMovementTypeStartRotate", OnStartRotate);
            EventHandler.RegisterEvent(m_GameObject, "OnRPGMovementTypeStopRotate", OnStopRotate);
            EventHandler.RegisterEvent <float>(m_GameObject, "OnRPGMovementTypeTurn", OnTurn);
            EventHandler.RegisterEvent(m_GameObject, "OnRPGMovementTypeAutoMove", OnToggleAutoMove);
        }
Пример #2
0
        /// <summary>
        /// The character has either landed or just left the ground.
        /// </summary>
        /// <param name="grounded">Is the character on the ground?</param>
        private void OnGrounded(bool grounded)
        {
            if (grounded)
            {
                if (IsActive)
                {
                    StopAbility(true);
                }
                m_RepeatedJumpCount = 0;
                m_JumpApplied       = false;
                // Remember the land time to prevent jumping more than the JumpReoccuranceDelay.
                m_LandTime  = Time.time;
                m_InAirTime = -1;

                // Unregister the jump input within OnGrounded so a repeated jump can be applied when fall is active.
                if (m_RepeatedJumpInput != null)
                {
                    m_Handler.UnregisterInputEvent(m_RepeatedJumpInput);
                    ObjectPool.Return(m_RepeatedJumpInput);
                    m_RepeatedJumpInput = null;
                }
                EventHandler.UnregisterEvent(m_GameObject, "OnJumpAbilityRepeatedJump", OnRepeatedJump);
                m_RepeatedJumpRegistered = false;
            }
            else if (!IsActive)
            {
                m_InAirTime = Time.time;
            }
        }
Пример #3
0
        /// <summary>
        /// The character has either landed or just left the ground.
        /// </summary>
        /// <param name="grounded">Is the character on the ground?</param>
        private void OnGrounded(bool grounded)
        {
            if (grounded)
            {
                if (IsActive)
                {
                    StopAbility(true);
                }
                m_AirborneJumpCount = 0;
                m_JumpApplied       = false;
                // Remember the land time to prevent jumping more than the JumpReoccuranceDelay.
                // Add the deltaTime to prevent the ability from starting during the same frame. This can happen if the character is updated within FixedUpdate
                // but the input is updated within Update.
                m_LandTime  = Time.time + Time.deltaTime;
                m_InAirTime = -1;

                // Unregister the jump input within OnGrounded so a repeated jump can be applied when fall is active.
                if (m_AirborneJumpInput != null)
                {
                    m_Handler.UnregisterInputEvent(m_AirborneJumpInput);
                    GenericObjectPool.Return(m_AirborneJumpInput);
                    m_AirborneJumpInput = null;
                }
                EventHandler.UnregisterEvent(m_GameObject, "OnJumpAbilityAirborneJump", OnPerformAirborneJump);
                m_AirborneJumpRegistered = false;
            }
            else if (!IsActive)
            {
                m_InAirTime = Time.time;
            }
        }
Пример #4
0
        /// <summary>
        /// The ability has started.
        /// </summary>
        protected override void AbilityStarted()
        {
            // If a handler exists then the ability is interested in updates when the axis value changes. This for example allows the lean to switch
            // between the left and right lean without having to stop and start again.
            if (m_Handler != null)
            {
                m_LeanInput = GenericObjectPool.Get <ActiveInputEvent>();
                m_LeanInput.Initialize(ActiveInputEvent.Type.Axis, InputNames[InputIndex], "OnLeanInputUpdate");
                m_Handler.RegisterInputEvent(m_LeanInput);
            }
            EventHandler.RegisterEvent <float>(m_GameObject, "OnLeanInputUpdate", OnInputUpdate);

            base.AbilityStarted();

            // The collider should be activated when the ability starts. The collider detects when the character would be clipping with a wall
            // and also allows the character to be shot at while leaning.
            if (m_ColliderGameObject != null)
            {
                m_ColliderGameObject.SetActive(true);
            }

            // Start leaning.
            m_AxisValue = InputAxisValue;
            UpdateLean(true);
        }
 /// <summary>
 /// Register an input event which allows the view type to receive button callbacks while it is active.
 /// </summary>
 /// <param name="inputEvent">The input event object to register.</param>
 public virtual void RegisterInputEvent(ActiveInputEvent inputEvent)
 {
     if (m_ActiveInputList == null)
     {
         m_ActiveInputList = new List <ActiveInputEvent>();
     }
     m_ActiveInputList.Add(inputEvent);
 }
Пример #6
0
 /// <summary>
 /// Unregister the specified input event.
 /// </summary>
 /// <param name="inputEvent">The input event object to unregister.</param>
 public void UnregisterInputEvent(ActiveInputEvent inputEvent)
 {
     // The input list may be null when the object is being destroyed.
     if (m_ActiveInputList == null || inputEvent == null)
     {
         return;
     }
     m_ActiveInputList.Remove(inputEvent);
 }
Пример #7
0
        /// <summary>
        /// The ability has started.
        /// </summary>
        protected override void AbilityStarted()
        {
            m_ApplyHoldForce = true;
            m_HoldForce      = 0;

            // If the jump has already been applied then it is a repeated jump.
            if (m_JumpApplied)
            {
                OnRepeatedJump();
            }
            else
            {
                if (!m_JumpEvent.WaitForAnimationEvent || m_ForceImmediateJump)
                {
                    Scheduler.ScheduleFixed(m_ForceImmediateJump ? 0 : m_JumpEvent.Duration, ApplyJumpForce);
                }
            }

            if (m_ForceHold > 0)
            {
                if (m_Handler != null && InputIndex != -1)
                {
                    m_HoldInput = ObjectPool.Get <ActiveInputEvent>();
                    m_HoldInput.Initialize(ActiveInputEvent.Type.ButtonUp, InputNames[InputIndex], "OnJumpAbilityReleaseHold");
                    m_Handler.RegisterInputEvent(m_HoldInput);
                }
                EventHandler.RegisterEvent(m_GameObject, "OnJumpAbilityReleaseHold", OnReleaseHold);
            }

            // The character can do a repeated jump after the character is already in the air.
            if (!m_RepeatedJumpRegistered)
            {
                if (m_Handler != null && InputIndex != -1)
                {
                    m_RepeatedJumpInput = ObjectPool.Get <ActiveInputEvent>();
                    m_RepeatedJumpInput.Initialize(ActiveInputEvent.Type.ButtonDown, InputNames[InputIndex], "OnJumpAbilityRepeatedJump");
                    m_Handler.RegisterInputEvent(m_RepeatedJumpInput);
                }
                EventHandler.RegisterEvent(m_GameObject, "OnJumpAbilityRepeatedJump", OnRepeatedJump);
                m_RepeatedJumpRegistered = true;
            }
            m_ForceImmediateJump = false;

            base.AbilityStarted();
        }
Пример #8
0
        /// <summary>
        /// The view type has changed.
        /// </summary>
        /// <param name="activate">Should the current view type be activated?</param>
        /// <param name="pitch">The pitch of the camera (in degrees).</param>
        /// <param name="yaw">The yaw of the camera (in degrees).</param>
        /// <param name="characterRotation">The rotation of the character.</param>
        public override void ChangeViewType(bool activate, float pitch, float yaw, Quaternion characterRotation)
        {
            base.ChangeViewType(activate, pitch, yaw, characterRotation);

            if (activate)
            {
                // Work with the handler to listen for any input events.
                if (m_Handler != null)
                {
                    m_StartFreeMovementInputEvent = GenericObjectPool.Get <ActiveInputEvent>();
                    m_StartFreeMovementInputEvent.Initialize(ActiveInputEvent.Type.ButtonDown, m_CameraFreeMovementInputName, "OnRPGViewTypeStartFreeMovement");

                    m_StopFreeMovementInputEvent = GenericObjectPool.Get <ActiveInputEvent>();
                    m_StopFreeMovementInputEvent.Initialize(ActiveInputEvent.Type.ButtonUp, m_CameraFreeMovementInputName, "OnRPGViewTypeStopFreeMovement");

                    m_Handler.RegisterInputEvent(m_StartFreeMovementInputEvent);
                }
                EventHandler.RegisterEvent(m_GameObject, "OnRPGViewTypeStartFreeMovement", OnStartFreeMovement);
                EventHandler.RegisterEvent(m_GameObject, "OnRPGViewTypeStopFreeMovement", OnStopFreeMovement);
                EventHandler.RegisterEvent(m_Character, "OnRPGMovementTypeStartRotate", OnStartCharacterRotate);
                EventHandler.RegisterEvent(m_Character, "OnRPGMovementTypeStopRotate", OnStopCharacterRotate);
            }
            else
            {
                // The ViewType no longer needs to listen for input events when to ViewType is no longer active.
                if (m_Handler != null)
                {
                    if (m_FreeMovement)
                    {
                        m_Handler.UnregisterAbilityInputEvent(m_StopFreeMovementInputEvent);
                    }
                    else
                    {
                        m_Handler.UnregisterAbilityInputEvent(m_StartFreeMovementInputEvent);
                    }

                    GenericObjectPool.Return(m_StartFreeMovementInputEvent);
                    GenericObjectPool.Return(m_StopFreeMovementInputEvent);
                }
                EventHandler.UnregisterEvent(m_GameObject, "OnRPGViewTypeStartFreeMovement", OnStartFreeMovement);
                EventHandler.UnregisterEvent(m_GameObject, "OnRPGViewTypeStopFreeMovement", OnStopFreeMovement);
                EventHandler.UnregisterEvent(m_Character, "OnRPGMovementTypeStartRotate", OnStartCharacterRotate);
                EventHandler.UnregisterEvent(m_Character, "OnRPGMovementTypeStopRotate", OnStopCharacterRotate);
            }
        }
Пример #9
0
 /// <summary>
 /// The view type has changed.
 /// </summary>
 /// <param name="activate">Should the current view type be activated?</param>
 /// <param name="pitch">The pitch of the camera (in degrees).</param>
 /// <param name="yaw">The yaw of the camera (in degrees).</param>
 /// <param name="characterRotation">The rotation of the character.</param>
 public override void ChangeViewType(bool activate, float pitch, float yaw, Quaternion characterRotation)
 {
     if (activate)
     {
         m_Pitch             = pitch;
         m_Yaw               = yaw;
         m_CharacterRotation = characterRotation;
         if (m_CharacterLocomotion.Platform != null)
         {
             UpdatePlatformRotationOffset(m_CharacterLocomotion.Platform);
         }
         if (m_Camera.fieldOfView != m_FieldOfView)
         {
             m_FieldOfViewChangeTime = Time.time + m_FieldOfViewDamping / m_CharacterLocomotion.TimeScale;
         }
         if (m_StepZoomSensitivity > 0)
         {
             if (m_Handler != null)
             {
                 m_StepZoomInputEvent = ObjectPool.Get <ActiveInputEvent>();
                 m_StepZoomInputEvent.Initialize(ActiveInputEvent.Type.Axis, m_StepZoomInputName, "OnThirdPersonViewTypeStepZoom");
                 m_Handler.RegisterInputEvent(m_StepZoomInputEvent);
             }
             EventHandler.RegisterEvent <float>(m_GameObject, "OnThirdPersonViewTypeStepZoom", OnStepZoom);
         }
     }
     else
     {
         if (m_StepZoomSensitivity > 0)
         {
             if (m_Handler != null)
             {
                 m_StepZoomInputEvent = ObjectPool.Get <ActiveInputEvent>();
                 m_Handler.UnregisterAbilityInputEvent(m_StepZoomInputEvent);
                 ObjectPool.Return(m_StepZoomInputEvent);
             }
             EventHandler.UnregisterEvent <float>(m_GameObject, "OnThirdPersonViewTypeStepZoom", OnStepZoom);
         }
     }
 }
Пример #10
0
        /// <summary>
        /// The view type has changed.
        /// </summary>
        /// <param name="activate">Should the current view type be activated?</param>
        /// <param name="pitch">The pitch of the camera (in degrees).</param>
        /// <param name="yaw">The yaw of the camera (in degrees).</param>
        /// <param name="characterRotation">The rotation of the character.</param>
        public override void ChangeViewType(bool activate, float pitch, float yaw, Quaternion characterRotation)
        {
            base.ChangeViewType(activate, pitch, yaw, characterRotation);

            if (activate)
            {
                m_Pitch             = pitch;
                m_Yaw               = yaw;
                m_CharacterRotation = characterRotation;
                if (m_CharacterLocomotion.Platform != null)
                {
                    UpdatePlatformRotationOffset(m_CharacterLocomotion.Platform);
                }
                if (m_StepZoomSensitivity > 0)
                {
                    if (m_Handler != null)
                    {
                        m_StepZoomInputEvent = GenericObjectPool.Get <ActiveInputEvent>();
                        m_StepZoomInputEvent.Initialize(ActiveInputEvent.Type.Axis, m_StepZoomInputName, "OnThirdPersonViewTypeStepZoom");
                        m_Handler.RegisterInputEvent(m_StepZoomInputEvent);
                    }
                    EventHandler.RegisterEvent <float>(m_GameObject, "OnThirdPersonViewTypeStepZoom", OnStepZoom);
                }
            }
            else
            {
                if (m_StepZoomSensitivity > 0)
                {
                    if (m_Handler != null)
                    {
                        m_StepZoomInputEvent = GenericObjectPool.Get <ActiveInputEvent>();
                        m_Handler.UnregisterAbilityInputEvent(m_StepZoomInputEvent);
                        GenericObjectPool.Return(m_StepZoomInputEvent);
                    }
                    EventHandler.UnregisterEvent <float>(m_GameObject, "OnThirdPersonViewTypeStepZoom", OnStepZoom);
                }
            }
        }
 /// <summary>
 /// Unregister the specified input event.
 /// </summary>
 /// <param name="inputEvent">The input event object to unregister.</param>
 public void UnregisterAbilityInputEvent(ActiveInputEvent inputEvent)
 {
     m_ActiveInputList.Remove(inputEvent);
 }