Exemplo n.º 1
0
 public static void Update(CurvedMotionForceConfig config, CurvedMotionForceState state)
 {
     if (state.currentState != state.requestedState)
     {
         if (state.requestedState == MotionPlaybackState.Playing)
         {
             state.delta = 0;
         }
         else if (state.requestedState == MotionPlaybackState.Complete)
         {
             state.delta = config.duration;
             if (config.isStopedOnComplete)
             {
                 state.requestedState = MotionPlaybackState.Stopped;
             }
         }
         if (state.requestedState == MotionPlaybackState.Stopped)
         {
             state.force.factor = 0;
             state.delta        = 0;
         }
         state.currentState = state.requestedState;
     }
     if (state.currentState == MotionPlaybackState.Playing)
     {
         state.delta = Math.Min(state.delta + Time.deltaTime, config.duration);
         var percent = state.delta / config.duration;
         state.force.factor = config.curve.Evaluate(percent) * config.factor;
         if (state.delta >= config.duration)
         {
             state.requestedState = MotionPlaybackState.Complete;
         }
     }
 }
 public GravityForceState(CharacterMotorState motorState)
 {
     force.direction       = MotionDirection.Down;
     this.curvedForceState = new CurvedMotionForceState(force);
     this.curvedForceState.requestedState = MotionPlaybackState.Playing;
     this.motorState = motorState;
 }
 public PlatformerCharacterState()
 {
     this.motorState     = new CharacterMotorState("platformer-character");
     this.gravityState   = new GravityForceState(motorState);
     this.jumpState      = new CurvedMotionForceState(jumpForce);
     jumpForce.direction = MotionDirection.Up;
     motorState.forces.AddFirst(jumpForce);
     motorState.forces.AddFirst(walkForce);
     motorState.forces.AddFirst(gravityState.force);
 }