//call ONCE before your fixed update stuff, just an organizational thing protected override void PreUpdate() { //tick our timers if (!stopTimer.TickTimer()) { //tick the timer timer.TickTimer(); } //buffer the input newInput = data.BufferPrev(input); //getting the input from outside of tick, locking in input for the current tick //resetting the changes made by assigning the current controller state input = asyncInput; StateFrameData newState = null; if (newInput) { newState = data.GetCommand(); } //finding a command if (newState == null) { newState = data.TransitionState(!timer.IsTicking(), input); } if (newState != null) { ApplyNewState(newState); } if (!stopTimer.IsTicking()) { //get the velocity from the rigidbody to manipulate calcVelocity = rb.velocity; if (data.GetState().FindFrame(timer.ElapsedTime(), ref refFrame)) { ApplyStateFrame(refFrame); } } }
//call to buffer an input for later public bool BufferPrev(SpaxInput input, bool inStop = false) { inputChanged = inputRecorder.RecordInput(input, inStop); return(inputChanged); }
//this transition algorithm feels very bad, rewrite and organize private StateFrameData CheckTransitionState(bool timerIsDone, SpaxInput input, StateFrameData srcState) { int len = srcState._transitions.Count; //gets current transition conditions TransitionCondition curConditions = GetTransitionCondition(); //if the timer is done if (timerIsDone) { curConditions |= TransitionCondition.ON_END; } for (int i = 0; i < len; i++) { StateFrameData potenState = srcState._transitions[i].Target; TransitionCondition compare = srcState._transitions[i].GetConditions(); InputCodeFlags inputCond = srcState._transitions[i].inputConditions; CancelCondition cancelCond = srcState._transitions[i].cancelCondition; if ((compare & (TransitionCondition.FULL_METER | TransitionCondition.HALF_METER | TransitionCondition.QUART_METER)) == 0) { //if all the conditions are met if ((compare & curConditions) == compare && (cancelCond & this.cancelCondition) == cancelCond) { //get the last input change int fromInput = (int)inputRecorder.GetLatestCode(); //flip 6 and 4 direction, if needed if (!moveCondition.facingRight) { fromInput = InputCode.FlipBackForth(fromInput); } bool initialCheck = ((inputCond & (InputCodeFlags)fromInput) == inputCond); bool freePass = false; if (!initialCheck && (inputCond & InputCodeFlags.CURRENTLY_HELD) > 0) { inputCond ^= InputCodeFlags.CURRENTLY_HELD; int codeFromInput = (((int)input.direction & 510) << 2) | ((int)input.buttons << 11); int inputCondSimple = ((int)inputCond >> 3) << 3; if (!moveCondition.facingRight) { codeFromInput = InputCode.FlipBackForth(codeFromInput); } freePass = ((codeFromInput & inputCondSimple) == inputCondSimple); } //check it if (inputCond == 0 || initialCheck || freePass) { //Debug.Log(compare); return(AssignNewCurState(potenState)); } } } } //only really reached if state to transition to isn't found if (((srcState.stateConditions & StateConditions.NO_PARENT_TRANS) == 0) && (srcState.parentState != null)) { return(CheckTransitionState(timerIsDone, input, srcState.parentState)); } return(null); }
public StateFrameData TransitionState(bool timerIsDone, SpaxInput input) { return(CheckTransitionState(timerIsDone, input, currentState)); }