コード例 #1
0
        protected void CheckLadders(float _inputDirection)
        {
            if (isClimbing && isEnabled)
            {
                float topBuffer       = 0.1f;
                bool  isOnTopOfLadder = (controller.GravityScaleMultiplier() > 0.0f) ? !(boxCollider.bounds.min.y < activeLadderTopCrestPosition - topBuffer) : !(boxCollider.bounds.max.y > activeLadderBottomCrestPosition + topBuffer);
                if (!isOnTopOfLadder)                //You're not on top of the ladder
                {
                    isTouching = true;
                }
            }

            if (!isEnabled && isClimbing)
            {
                Drop();
            }

            if (!isEnabled || controller.framesSinceDrop < 10)
            {
                return;
            }

            if (isTouching)
            {
                if (_inputDirection == 1.0f && !IsLockedForAttack(Attack.ActionType.Climbing) && !controller.isKnockbackActive && !controller.isStunned && !isClimbing && IsHorizontallyCenteredOnLadder())                //Mount a ladder
                {
                    Begin();
                    controller.slots.physicsObject.SetVelocityX(0.0f);
                    isClimbing = true;
                    willAllowDirectionChange = false;
                }
                else if (controller.slots.input && controller.slots.input.isJumpButtonDownThisFrame && isClimbing)
                {
                    Drop();
                }
                else if (_inputDirection == -1.0f && controller.slots.physicsObject.IsOnSurface() && isClimbing)                //Dismounting by climbing to the floor
                {
                    End();
                }
            }
            else
            {
                if (!controller.isKnockbackActive)                //On top of a ladder; going down
                {
                    if (_inputDirection == -1.0f && !IsLockedForAttack(Attack.ActionType.Climbing))
                    {
                        if (RaycastHelper.IsOnSurface("Ladder", (Direction.Vertical)(-1.0f * controller.GravityScaleMultiplier()), boxCollider))
                        {
                            Collider2D col = RaycastHelper.GetColliderForSurface("Ladder", (Direction.Vertical)(-1.0f * controller.GravityScaleMultiplier()), boxCollider);
                            SetLadderValues(col);

                            if (!IsHorizontallyCenteredOnLadder())
                            {
                                return;
                            }

                            controller.slots.actor.SetPosition(new Vector2(activeLadderXPosition, transform.position.y));
                            controller.slots.physicsObject.SetVelocityX(0);

                            isClimbing = true;
                            willAllowDirectionChange = false;
                            Begin();
                            controller.slots.physicsObject.SetVelocityX(0.0f);
                            controller.slots.actor.SetPosition(new Vector2(transform.position.x, transform.position.y - (0.25f * controller.GravityScaleMultiplier())));
                        }
                    }
                }
            }
        }