示例#1
0
        internal void SetValue(float value)
        {
            uint updateTick = Time.frameCount;

            if (updateTick > pendingTick)
            {
                lastState = thisState;
                nextState.Reset();
                pendingTick   = updateTick;
                pendingCommit = true;
            }

            nextState.RawValue = value;
            nextState.Set(value, StateThreshold);
        }
示例#2
0
        public void Commit()
        {
            pendingCommit = false;
            //			nextState.Set( Utility.ApplySmoothing( nextState.Value, lastState.Value, Time.deltaTime, sensitivity ), stateThreshold );
            thisState = nextState;

            if (clearInputState)
            {
                // The net result here should be that the entire state will return zero/false
                // from when ResetState() is called until the next call to Commit(), which is
                // the next update tick, and WasPressed, WasReleased and WasRepeated will then
                // return false during this following tick.
                lastState       = nextState;
                UpdateTick      = pendingTick;
                clearInputState = false;
                return;
            }

            var lastPressed = lastState.State;
            var thisPressed = thisState.State;

            wasRepeated = false;
            if (lastPressed && !thisPressed) // if was released...
            {
                nextRepeatTime = 0.0f;
            }
            else
            if (thisPressed)                    // if is pressed...
            {
                if (lastPressed != thisPressed) // if has changed...
                {
                    nextRepeatTime = Time.time + FirstRepeatDelay;
                }
                else
                if (Time.time >= nextRepeatTime)
                {
                    wasRepeated    = true;
                    nextRepeatTime = Time.time + RepeatDelay;
                }
            }

            if (thisState != lastState)
            {
                UpdateTick = pendingTick;
            }
        }
示例#3
0
        void PrepareForUpdate()
        {
            uint updateTick = Time.frameCount;

            if (updateTick < pendingTick)
            {
                throw new InvalidOperationException("Cannot be updated with an earlier tick.");
            }

            if (pendingCommit && updateTick != pendingTick)
            {
                throw new InvalidOperationException("Cannot be updated for a new tick until pending tick is committed.");
            }

            if (updateTick > pendingTick)
            {
                lastState = thisState;
                nextState.Reset();
                pendingTick   = updateTick;
                pendingCommit = true;
            }
        }