public static void Update(Transform transform, PlatformerCharacterState state, PlatformerCharacterConfig config)
 {
     state.hasWallGrab = HasWallGrab(state, config);
     if (HasJumpReset(state, config))
     {
         state.jumpsRemaining = config.jumpCount;
     }
     if (state.jumpRequest == PlatformerJumpRequest.Requested && state.jumpsRemaining > 0)
     {
         state.jumpsRemaining           = state.jumpsRemaining - 1;
         state.jumpState.requestedState = MotionPlaybackState.Playing;
     }
     else if (state.jumpRequest == PlatformerJumpRequest.None && state.jumpState.currentState == MotionPlaybackState.Playing)
     {
         state.jumpState.requestedState = MotionPlaybackState.Stopped;
     }
     state.walkForce.direction = WALK_MAP[state.walkRequest];
     state.walkForce.factor    = config.walkSpeed;
     CurvedMotionForce.Update(config.jumpConfig, state.jumpState);
     GravityMotionComp.Update(state.gravityState);
     if (state.jumpState.currentState == MotionPlaybackState.Playing || state.hasWallGrab)
     {
         state.gravityState.curvedForceState.delta          = 0;
         state.gravityState.force.factor                    = 0;
         state.gravityState.curvedForceState.currentState   = MotionPlaybackState.Stopped;
         state.gravityState.curvedForceState.requestedState = MotionPlaybackState.Playing;
     }
     state.hadWallGrab = state.hasWallGrab;
     CharacterMotor.Update(transform, state.motorState, config.motorConfig);
 }
    private static bool HasJumpReset(PlatformerCharacterState state, PlatformerCharacterConfig config)
    {
        var isJumpGrab        = state.jumpRequest == PlatformerJumpRequest.Requested && state.hasWallGrab;
        var hasWallGrabChange = state.hasWallGrab && !state.hadWallGrab;
        var hasFloorChange    = !state.motorState.wasBlocked[MotionDirection.Down] && state.motorState.blocked[MotionDirection.Down];

        return(hasWallGrabChange || hasFloorChange || isJumpGrab);
    }
    void Start()
    {
        platformerInputState = new PlatformerCharacterInputState();
        platformerInputState.isJumpRequested = false;
        platformerInputState.walkDirection   = PlatformerWalkDirection.None;

        platformerState = new PlatformerCharacterState();
    }
 public static void OnGUI(PlatformerCharacterState state)
 {
     if (Application.isEditor)
     {
         var style = GUI.skin.label;
         style.fontSize = 20;
         GUI.Label(new Rect(10, 10, 400, 100), "WALK: " + state.walkRequest, style);
         GUI.Label(new Rect(10, 35, 400, 100), "JUMP STATE: " + state.jumpRequest, style);
         GUI.Label(new Rect(10, 60, 400, 100), "JUMPS LEFT: " + state.jumpsRemaining, style);
         GUI.Label(new Rect(10, 85, 400, 100), "GRAVITY: " + state.gravityState.curvedForceState.currentState, style);
     }
 }
 public static void Update(PlatformerCharacterInputState inputState, PlatformerCharacterState characterState)
 {
     if (inputState.isJumpRequested)
     {
         characterState.jumpRequest  = inputState.wasJumpRequested? PlatformerJumpRequest.Continued : PlatformerJumpRequest.Requested;
         inputState.wasJumpRequested = true;
     }
     else
     {
         characterState.jumpRequest  = PlatformerJumpRequest.None;
         inputState.wasJumpRequested = false;
     }
     characterState.walkRequest = inputState.walkDirection;
 }
    private static bool HasWallGrab(PlatformerCharacterState state, PlatformerCharacterConfig config)
    {
        var hasWallGrab = false;

        if (config.canWallGrab)
        {
            foreach (var side in WALLGRAB_SIDES)
            {
                hasWallGrab = state.motorState.blocked[side];
                if (hasWallGrab)
                {
                    break;
                }
            }
        }
        return(hasWallGrab);
    }
예제 #7
0
 void Start()
 {
     platformerState = new PlatformerCharacterState();
 }