Ejemplo n.º 1
0
 private void FixedUpdate()
 {
     if (_fixedUpdateSource != null)
     {
         _fixedUpdateSource.OnNext(Time.fixedDeltaTime);
     }
 }
Ejemplo n.º 2
0
        public void Unsubscribe_CanBeCalledFromOnNext()
        {
            // Arrange
            var updateSource = new AsyncUpdateSource();
            var observer     = Substitute.For <IObserver <float> >();
            var subscription = updateSource.Subscribe(observer);

            observer.When(x => x.OnNext(Arg.Any <float>())).Do(x => subscription.Dispose());

            // Act
            updateSource.OnNext(0);
            updateSource.OnNext(0);

            // Assert
            observer.Received(1).OnNext(Arg.Any <float>());
        }
Ejemplo n.º 3
0
 private void LateUpdate()
 {
     if (_lateUpdateSource != null)
     {
         _lateUpdateSource.OnNext(Time.deltaTime);
     }
 }
Ejemplo n.º 4
0
        public void AddListener_CanBeCalledFromUpdate()
        {
            // Arrange
            var updateSource = new AsyncUpdateSource();
            var observer     = Substitute.For <IAsyncUpdatable>();

            observer.When(x => x.Update(Arg.Any <float>())).Do(x => updateSource.AddListener(observer));
            updateSource.AddListener(observer);

            // Act
            updateSource.OnNext(0);
            updateSource.OnNext(0);

            // Assert
            observer.Received(3).Update(Arg.Any <float>());
        }
Ejemplo n.º 5
0
            private IEnumerator EofEnumerator()
            {
                yield return(_eof);

                if (_eofUpdateSource != null)
                {
                    _eofUpdateSource.OnNext(Time.deltaTime);
                }
            }
Ejemplo n.º 6
0
            private void FixedUpdate()
            {
                if (_fixedUpdateSource != null)
                {
                    _fixedUpdateSource.OnNext(Time.fixedDeltaTime);
                }

                if (_fixedUpdateActions != null)
                {
                    InvokeFrameCallbacks(_fixedUpdateActions, this);
                }
            }
Ejemplo n.º 7
0
            private void LateUpdate()
            {
                if (_lateUpdateSource != null)
                {
                    _lateUpdateSource.OnNext(Time.deltaTime);
                }

                if (_lateUpdateActions != null)
                {
                    InvokeFrameCallbacks(_lateUpdateActions, this);
                }
            }
Ejemplo n.º 8
0
        public void OnNext_CallsNext()
        {
            // Arrange
            var updateSource = new AsyncUpdateSource();
            var observer     = Substitute.For <IObserver <float> >();

            updateSource.Subscribe(observer);

            // Act
            updateSource.OnNext(0);

            // Assert
            observer.Received().OnNext(0);
        }
Ejemplo n.º 9
0
        public void OnNext_CallsUpdate()
        {
            // Arrange
            var updateSource = new AsyncUpdateSource();
            var observer     = Substitute.For <IAsyncUpdatable>();

            updateSource.AddListener(observer);

            // Act
            updateSource.OnNext(0);

            // Assert
            observer.Received().Update(0);
        }
Ejemplo n.º 10
0
            private void FixedUpdate()
            {
                if (_fixedUpdateSource != null)
                {
                    try
                    {
                        _fixedUpdateSource.OnNext(Time.fixedDeltaTime);
                    }
                    catch (Exception e)
                    {
                        Debug.LogException(e, this);
                    }
                }

                if (_fixedUpdateActions != null)
                {
                    InvokeFrameCallbacks(_fixedUpdateActions, this);
                }
            }
Ejemplo n.º 11
0
            private IEnumerator EofEnumerator()
            {
                yield return(_eof);

                if (_eofUpdateSource != null)
                {
                    try
                    {
                        _eofUpdateSource.OnNext(Time.deltaTime);
                    }
                    catch (Exception e)
                    {
                        Debug.LogException(e, this);
                    }
                }

                if (_eofUpdateActions != null)
                {
                    InvokeFrameCallbacks(_eofUpdateActions, this);
                }
            }
Ejemplo n.º 12
0
            private void Update()
            {
                if (_ops != null && _ops.Count > 0)
                {
                    try
                    {
                        foreach (var item in _ops)
                        {
                            if (item.Key is AsyncOperation)
                            {
                                var asyncOp = item.Key as AsyncOperation;

                                if (asyncOp.isDone)
                                {
                                    _opsToRemove.Add(asyncOp);
                                    item.Value();
                                }
                            }
#if UNITY_5_2_OR_NEWER || UNITY_5_3_OR_NEWER || UNITY_2017 || UNITY_2018
                            else if (item.Key is UnityWebRequest)
                            {
                                var asyncOp = item.Key as UnityWebRequest;

                                if (asyncOp.isDone)
                                {
                                    _opsToRemove.Add(asyncOp);
                                    item.Value();
                                }
                            }
#endif
                            else if (item.Key is WWW)
                            {
                                var asyncOp = item.Key as WWW;

                                if (asyncOp.isDone)
                                {
                                    _opsToRemove.Add(asyncOp);
                                    item.Value();
                                }
                            }
                        }
                    }
                    catch (Exception e)
                    {
                        Debug.LogException(e, this);
                    }

                    foreach (var item in _opsToRemove)
                    {
                        _ops.Remove(item);
                    }

                    _opsToRemove.Clear();
                }

                if (_updateSource != null)
                {
                    try
                    {
                        _updateSource.OnNext(Time.deltaTime);
                    }
                    catch (Exception e)
                    {
                        Debug.LogException(e, this);
                    }
                }

                if (_actionQueue.Count > 0)
                {
                    lock (_actionQueue)
                    {
                        while (_actionQueue.Count > 0)
                        {
                            var asyncResult = _actionQueue.Dequeue();

                            try
                            {
                                asyncResult.Start();
                                asyncResult.SetCompleted();
                            }
                            catch (Exception e)
                            {
                                asyncResult.SetException(e);
                                Debug.LogException(e, this);
                            }
                        }
                    }
                }
            }
Ejemplo n.º 13
0
            private void Update()
            {
                if (_ops != null && _ops.Count > 0)
                {
                    foreach (var item in _ops)
                    {
                        if (item.Key is AsyncOperation)
                        {
                            var asyncOp = item.Key as AsyncOperation;

                            if (asyncOp.isDone)
                            {
                                _opsToRemove.Add(item);
                            }
                        }
                        else if (item.Key is UnityWebRequest)
                        {
                            var asyncOp = item.Key as UnityWebRequest;

                            if (asyncOp.isDone)
                            {
                                _opsToRemove.Add(item);
                            }
                        }
#if !UNITY_2018_3_OR_NEWER
                        else if (item.Key is WWW)
                        {
                            var asyncOp = item.Key as WWW;

                            if (asyncOp.isDone)
                            {
                                _opsToRemove.Add(item);
                            }
                        }
#endif
                    }

                    foreach (var item in _opsToRemove)
                    {
                        _ops.Remove(item.Key);

                        try
                        {
                            item.Value();
                        }
                        catch (Exception e)
                        {
                            Debug.LogException(e, this);
                        }
                    }

                    _opsToRemove.Clear();
                }

                if (_updateSource != null)
                {
                    try
                    {
                        _updateSource.OnNext(Time.deltaTime);
                    }
                    catch (Exception e)
                    {
                        Debug.LogException(e, this);
                    }
                }

                if (_updateActions != null)
                {
                    InvokeFrameCallbacks(_updateActions, this);
                }

                if (_mainThreadContext is Helpers.MainThreadSynchronizationContext)
                {
                    (_mainThreadContext as Helpers.MainThreadSynchronizationContext).Update(this);
                }
            }