internal static System.Collections.IEnumerator RadicalInvokeRedirect(System.Action method, float delay, float repeatRate = -1f, ITimeSupplier time = null)
        {
            yield return(WaitForDuration.Seconds(delay, time));

            if (repeatRate < 0f)
            {
                method();
            }
            else if (repeatRate == 0f)
            {
                while (true)
                {
                    method();
                    yield return(null);
                }
            }
            else
            {
                while (true)
                {
                    method();
                    yield return(WaitForDuration.Seconds(repeatRate, time));
                }
            }
        }
Exemplo n.º 2
0
        public static InvokeHandle Begin(UpdatePump pump, System.Action callback, float duration, ITimeSupplier time)
        {
            if (pump == null)
            {
                throw new System.ArgumentNullException("pump");
            }

            var handle = _pool.GetInstance();

            handle._callback = callback;
            handle._handle   = WaitForDuration.Seconds(duration, time);
            handle._pump     = pump;

            pump.Add(handle);

            return(handle);
        }
Exemplo n.º 3
0
        private System.Collections.IEnumerator SenseRoutine()
        {
            while (true)
            {
                if (_sensor == null)
                {
                    yield break;
                }

                if (_sensor.SenseAny())
                {
                    this.ActivateTrigger();
                }

                yield return(WaitForDuration.Seconds(_interval));
            }
        }
Exemplo n.º 4
0
        private System.Collections.IEnumerator UpdateRoutine()
        {
            yield return(null);

            while (true)
            {
                if (_onUpdate != null)
                {
                    _onUpdate();
                }

                if (_updateInterval > 0f)
                {
                    yield return(WaitForDuration.Seconds(_updateInterval));
                }
                else
                {
                    yield return(null);
                }
            }
        }
        private System.Collections.IEnumerator TickerCallback()
        {
            if (_delay > 0f)
            {
                yield return(WaitForDuration.Seconds(_delay, _interval.TimeSupplier));
            }

            int cnt = 0;

            while (true)
            {
                yield return(WaitForDuration.Period(_interval));

                this.ActivateTrigger();

                cnt++;
                if (cnt > _repeatCount)
                {
                    yield break;
                }
            }
        }
        internal static System.Collections.IEnumerator RadicalInvokeRedirect(System.Action method, float delay, float repeatRate = -1f, ITimeSupplier time = null)
        {
            //if (delay < SPConstants.MIN_FRAME_DELTA)
            //    yield return null;
            //else if (delay > 0f)
            //    yield return WaitForDuration.Seconds(delay, time);

            if (time == null)
            {
                time = SPTime.Normal;
            }
            float t = time.Total;

            while (time.Total - t < delay)
            {
                yield return(null);
            }

            if (repeatRate < 0f)
            {
                method();
            }
            else if (repeatRate == 0f)
            {
                while (true)
                {
                    method();
                    yield return(null);
                }
            }
            else
            {
                while (true)
                {
                    method();
                    yield return(WaitForDuration.Seconds(repeatRate, time));
                }
            }
        }
        private System.Collections.IEnumerator TickerCallback()
        {
            if (_delay > 0f)
            {
                yield return(WaitForDuration.Seconds(_delay, _timeSupplier));
            }

            int cnt = 0;

            while (true)
            {
                yield return(WaitForDuration.Seconds(RandomUtil.Standard.Range(_interval.Max, _interval.Min), _timeSupplier.TimeSupplier));

                this.ActivateTrigger();

                cnt++;
                if (cnt > _repeatCount)
                {
                    yield break;
                }
            }
        }
Exemplo n.º 8
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();
        }