示例#1
0
        private StateConditions GetConditionsFromState(StateFrameData stt)
        {
            if (stt.parentState == null)
            {
                return(stt.stateConditions);
            }

            return(stt.stateConditions | GetConditionsFromState(stt.parentState));
        }
        //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);
                }
            }
        }
        private void ApplyNewState(StateFrameData newState)
        {
            //animator.SetTrigger("StateChanged");
            //currentState = newState;
            if (newState.duration > 0)
            {
                //-1 is there to have the elapsed time equal the index
                timer.StartTimer(newState.duration - 1);
                //Debug.Log(newState.Frames.Length);
            }

            if ((newState.enterStateConditions & EnterStateConditions.KILL_Y_MOMENTUM) > 0)
            {
                calcVelocity.y = 0f;
            }
            if ((newState.enterStateConditions & EnterStateConditions.KILL_X_MOMENTUM) > 0)
            {
                calcVelocity.x = 0f;
            }
            setNewState = true;
        }
示例#4
0
 //sets and returns the new state to current state
 private StateFrameData AssignNewCurState(StateFrameData newState)
 {
     currentState         = newState;
     this.cancelCondition = newState.cancelCondition;
     return(currentState);
 }
示例#5
0
        //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);
        }