Пример #1
0
        private System.Collections.IEnumerator WorkRoutine(float delay)
        {
            yield return(WaitForDuration.Seconds(delay, SPTime.Real));

            while (_state == State.Running)
            {
                if (UnityEngine.Input.GetKeyDown(this.CancelKey))
                {
                    this.Cancel();
                    yield break;
                }
                if (this.CancelDelegate != null && this.CancelDelegate())
                {
                    this.Cancel();
                    yield break;
                }

                if (this.CustomPollingCallback != null)
                {
                    InputToken t;
                    if (this.CustomPollingCallback(this, out t))
                    {
                        this.InputResult = t;
                        goto Complete;
                    }
                }

                if (this.PollFromStandardSPInputs)
                {
                    if (this.PollButtons)
                    {
                        SPInputId btn;
                        if (SPInputDirect.TryPollButton(out btn, this.ButtonPollingState, this.Joystick))
                        {
                            this.InputResult = InputToken.CreateButton(btn);
                            goto Complete;
                        }
                    }

                    if (this.PollJoyAxes || this.PollMouseAxes)
                    {
                        SPInputId axis;
                        float     value;
                        if (SPInputDirect.TryPollAxis(out axis, out value, this.Joystick, this.PollMouseAxes, this.AxisPollingDeadZone) && TestConsideration(value, this.AxisConsideration, this.AxisPollingDeadZone))
                        {
                            if ((this.PollJoyAxes && axis.IsJoyAxis()) || (this.PollMouseAxes && axis.IsMouseAxis()))
                            {
                                this.InputResult = InputToken.CreateAxleButton(axis, this.AxisConsideration, this.AxisPollingDeadZone);
                                goto Complete;
                            }
                        }
                    }
                }

                if (this.PollKeyboard)
                {
                    UnityEngine.KeyCode key;
                    if (SPInputDirect.TryPollKey(out key, this.ButtonPollingState))
                    {
                        this.InputResult = InputToken.CreateButton(key);
                        goto Complete;
                    }
                }

                yield return(null);
            }

Complete:
            _state   = State.Complete;
            _routine = null;
            this.SignalOnComplete();
        }
        private System.Collections.IEnumerator WorkRoutine(float delay)
        {
            yield return(WaitForDuration.Seconds(delay, SPTime.Real));

            SPInputId positiveBtn = SPInputId.Unknown;

            UnityEngine.KeyCode positiveKey = UnityEngine.KeyCode.None;
            float t = float.NegativeInfinity;

            while (_state == State.Running)
            {
                if (UnityEngine.Input.GetKeyDown(this.CancelKey))
                {
                    this.Cancel();
                    yield break;
                }
                if (this.CancelDelegate != null && this.CancelDelegate())
                {
                    this.Cancel();
                    yield break;
                }

                if (this.CustomPollingCallback != null)
                {
                    InputToken token;
                    if (this.CustomPollingCallback(this, out token))
                    {
                        this.InputResult = token;
                        goto Complete;
                    }
                }

                if (this.PollFromStandardSPInputs)
                {
                    if (this.PollJoyAxes || this.PollMouseAxes)
                    {
                        SPInputId axis;
                        float     value;
                        if (SPInputDirect.TryPollAxis(out axis, out value, this.Joystick, this.PollMouseAxes, this.AxisPollingDeadZone) && TestConsideration(value, this.AxisConsideration, this.AxisPollingDeadZone))
                        {
                            if ((this.PollJoyAxes && axis.IsJoyAxis()) || (this.PollMouseAxes && axis.IsMouseAxis()))
                            {
                                if (this.PollAsTrigger)
                                {
                                    this.InputResult = InputToken.CreateTrigger(axis);
                                }
                                else
                                {
                                    this.InputResult = InputToken.CreateAxis(axis, value < 0f);
                                }
                                goto Complete;
                            }
                        }
                    }

                    if (this.PollButtons)
                    {
                        SPInputId btn;
                        if (SPInputDirect.TryPollButton(out btn, this.ButtonPollingState, this.Joystick))
                        {
                            if (this.PollAsTrigger)
                            {
                                this.InputResult = InputToken.CreateTrigger(btn, AxleValueConsideration.Positive);
                                goto Complete;
                            }
                            if (positiveBtn != SPInputId.Unknown)
                            {
                                this.InputResult = InputToken.CreateEmulatedAxis(positiveBtn, btn);
                                goto Complete;
                            }
                            else
                            {
                                positiveKey = UnityEngine.KeyCode.None;
                                positiveBtn = btn;
                                t           = UnityEngine.Time.realtimeSinceStartup;
                                goto Restart;
                            }
                        }
                    }
                }

                if (this.PollKeyboard)
                {
                    UnityEngine.KeyCode key;
                    if (SPInputDirect.TryPollKey(out key, this.ButtonPollingState))
                    {
                        if (this.PollAsTrigger)
                        {
                            this.InputResult = InputToken.CreateTrigger(key);
                            goto Complete;
                        }
                        if (positiveKey != UnityEngine.KeyCode.None)
                        {
                            this.InputResult = InputToken.CreateEmulatedAxis(positiveKey, key);
                            goto Complete;
                        }
                        else
                        {
                            positiveBtn = SPInputId.Unknown;
                            positiveKey = key;
                            t           = UnityEngine.Time.realtimeSinceStartup;
                            goto Restart;
                        }
                    }
                }

Restart:
                yield return(null);

                if (UnityEngine.Time.realtimeSinceStartup - t > this.ButtonPressMonitorDuration)
                {
                    positiveBtn = SPInputId.Unknown;
                    positiveKey = UnityEngine.KeyCode.None;
                }
            }

Complete:
            _state   = State.Complete;
            _routine = null;
            this.SignalOnComplete();
        }