Пример #1
0
        public void Update()
        {
            if (Time.frameCount == lastUpdateFrame)
            {
                return;
            }
            lastUpdateFrame = Time.frameCount;


            for (int slot = 0; slot < rawValues.Length; slot++)
            {
                rawValues[slot] = Sinput.GetAxis(positiveControl, (InputDeviceSlot)slot) - Sinput.GetAxis(negativeControl, (InputDeviceSlot)slot);

                if (inversion[slot])
                {
                    rawValues[slot] *= -1f;
                }

                valuePrefersDeltaUse[slot] = true;
                if (!Sinput.PrefersDeltaUse(positiveControl, (InputDeviceSlot)slot) || !Sinput.PrefersDeltaUse(negativeControl, (InputDeviceSlot)slot))
                {
                    //the rawvalue this frame is from a framerate independent input like a mouse movement, so we don't want it smoothed and wanna force getAxis checks to return raw
                    valuePrefersDeltaUse[slot] = false;
                }
            }

            for (int slot = 0; slot < controlValues.Length; slot++)
            {
                if (!valuePrefersDeltaUse[slot])
                {
                    //we're forcing things to be unsmoothed for now, zero smoothed input now so when we stop smoothing, it doesn't seem weird
                    controlValues[slot] = 0f;
                }
                else
                {
                    //shift to zero
                    if (gravity > 0f)
                    {
                        if (rawValues[slot] == 0f || (rawValues[slot] < controlValues[slot] && controlValues[slot] > 0f) || (rawValues[slot] > controlValues[slot] && controlValues[slot] < 0f))
                        {
                            if (controlValues[slot] > 0f)
                            {
                                controlValues[slot] -= gravity * Time.deltaTime;
                                if (controlValues[slot] < 0f)
                                {
                                    controlValues[slot] = 0f;
                                }
                                if (controlValues[slot] < rawValues[slot])
                                {
                                    controlValues[slot] = rawValues[slot];
                                }
                            }
                            else if (controlValues[slot] < 0f)
                            {
                                controlValues[slot] += gravity * Time.deltaTime;
                                if (controlValues[slot] > 0f)
                                {
                                    controlValues[slot] = 0f;
                                }
                                if (controlValues[slot] > rawValues[slot])
                                {
                                    controlValues[slot] = rawValues[slot];
                                }
                            }
                        }
                    }

                    //snapping
                    if (snap)
                    {
                        if (rawValues[slot] > 0f && controlValues[slot] < 0f)
                        {
                            controlValues[slot] = 0f;
                        }
                        if (rawValues[slot] < 0f && controlValues[slot] > 0f)
                        {
                            controlValues[slot] = 0f;
                        }
                    }

                    //move value towards target value
                    if (rawValues[slot] < 0f)
                    {
                        if (controlValues[slot] > rawValues[slot])
                        {
                            controlValues[slot] -= speed * Time.deltaTime;
                            if (controlValues[slot] < rawValues[slot])
                            {
                                controlValues[slot] = rawValues[slot];
                            }
                        }
                    }
                    if (rawValues[slot] > 0f)
                    {
                        if (controlValues[slot] < rawValues[slot])
                        {
                            controlValues[slot] += speed * Time.deltaTime;
                            if (controlValues[slot] > rawValues[slot])
                            {
                                controlValues[slot] = rawValues[slot];
                            }
                        }
                    }

                    if (speed == 0f)
                    {
                        controlValues[slot] = rawValues[slot];
                    }
                }
            }
        }