Esempio n. 1
0
        /// <summary>
        /// adds the IEnumerator to the CoroutineManager. Coroutines get ticked before Update is called each frame.
        /// </summary>
        /// <returns>The coroutine.</returns>
        /// <param name="enumerator">Enumerator.</param>
        public ICoroutine startCoroutine(IEnumerator enumerator)
        {
            // find or create a CoroutineImpl
            var coroutine = QuickCache <CoroutineImpl> .pop();

            coroutine.prepareForReuse();

            // setup the coroutine and add it
            coroutine.enumerator = enumerator;
            var shouldContinueCoroutine = tickCoroutine(coroutine);

            // guard against empty coroutines
            if (!shouldContinueCoroutine || coroutine.isDone)
            {
                coroutine.recycle();
                QuickCache <CoroutineImpl> .push(coroutine);

                return(null);
            }

            if (_isInUpdate)
            {
                _shouldRunNextFrame.Add(coroutine);
            }
            else
            {
                _unblockedCoroutines.Add(coroutine);
            }

            return(coroutine);
        }
Esempio n. 2
0
 /// <summary>
 /// removes all particles from the particle emitter
 /// </summary>
 public void clear()
 {
     for (var i = 0; i < _particles.Count; i++)
     {
         QuickCache <Particle> .push(_particles[i]);
     }
     _particles.Clear();
 }
Esempio n. 3
0
File: Tweens.cs Progetto: Pyxlre/Nez
        public override void recycleSelf()
        {
            base.recycleSelf();

            if (_shouldRecycleTween && TweenManager.cacheFloatTweens)
            {
                QuickCache <FloatTween> .push(this);
            }
        }
Esempio n. 4
0
        public void update()
        {
            if (_isPaused)
            {
                return;
            }

            // if the emitter is active and the emission rate is greater than zero then emit particles
            if (_active && _emitterConfig.emissionRate > 0)
            {
                var rate = 1.0f / _emitterConfig.emissionRate;

                if (_particles.Count < _emitterConfig.maxParticles)
                {
                    _emitCounter += Time.deltaTime;
                }

                while (_emitting && _particles.Count < _emitterConfig.maxParticles && _emitCounter > rate)
                {
                    addParticle();
                    _emitCounter -= rate;
                }

                _elapsedTime += Time.deltaTime;

                if (_emitterConfig.duration != -1 && _emitterConfig.duration < _elapsedTime)
                {
                    // when we hit our duration we dont emit any more particles
                    _emitting = false;

                    // once all our particles are done we stop the emitter
                    if (_particles.Count == 0)
                    {
                        stop();
                    }
                }
            }

            // prep data for the particle.update method
            var rootPosition = entity.transform.position + _localPosition;

            // loop through all the particles updating their location and color
            for (var i = _particles.Count - 1; i >= 0; i--)
            {
                // get the current particle and update it
                var currentParticle = _particles[i];

                // if update returns true that means the particle is done
                if (currentParticle.update(_emitterConfig, ref collisionConfig, rootPosition))
                {
                    QuickCache <Particle> .push(currentParticle);

                    _particles.RemoveAt(i);
                }
            }
        }
Esempio n. 5
0
 public override void recycleSelf()
 {
     if (_shouldRecycleTween)
     {
         _target    = null;
         _nextTween = null;
         _transform = null;
         QuickCache <TransformVector2Tween> .push(this);
     }
 }
Esempio n. 6
0
        public void update()
        {
            _isInUpdate = true;
            for (var i = 0; i < _unblockedCoroutines.Count; i++)
            {
                var coroutine = _unblockedCoroutines[i];

                // check for stopped coroutines
                if (coroutine.isDone)
                {
                    coroutine.recycle();
                    QuickCache <CoroutineImpl> .push(coroutine);

                    continue;
                }

                // are we waiting for any other coroutines to finish?
                if (coroutine.waitForCoroutine != null)
                {
                    if (coroutine.waitForCoroutine.isDone)
                    {
                        coroutine.waitForCoroutine = null;
                    }
                    else
                    {
                        _shouldRunNextFrame.Add(coroutine);
                        continue;
                    }
                }

                // deal with timers if we have them
                if (coroutine.waitTimer > 0)
                {
                    // still has time left. decrement and run again next frame
                    coroutine.waitTimer -= Time.deltaTime;
                    _shouldRunNextFrame.Add(coroutine);
                    continue;
                }

                if (tickCoroutine(coroutine))
                {
                    _shouldRunNextFrame.Add(coroutine);
                }
            }

            _unblockedCoroutines.Clear();
            _unblockedCoroutines.AddRange(_shouldRunNextFrame);
            _shouldRunNextFrame.Clear();

            _isInUpdate = false;
        }
Esempio n. 7
0
        /// <summary>
        /// ticks a coroutine. returns true if the coroutine should continue to run next frame.
        /// </summary>
        /// <returns><c>true</c>, if coroutine was ticked, <c>false</c> otherwise.</returns>
        /// <param name="coroutine">Coroutine.</param>
        bool tickCoroutine(CoroutineImpl coroutine)
        {
            // This coroutine has finished
            if (!coroutine.enumerator.MoveNext())
            {
                coroutine.recycle();
                QuickCache <CoroutineImpl> .push(coroutine);

                return(false);
            }

            if (coroutine.enumerator.Current == null)
            {
                // yielded null. run again next frame
                return(true);
            }
            else if (coroutine.enumerator.Current is int)
            {
                var wait = (int)coroutine.enumerator.Current;
                coroutine.waitTimer = wait;
                return(true);
            }
            else if (coroutine.enumerator.Current is float)
            {
                var wait = (float)coroutine.enumerator.Current;
                coroutine.waitTimer = wait;
                return(true);
            }
            else if (coroutine.enumerator.Current is CoroutineImpl)
            {
                coroutine.waitForCoroutine = coroutine.enumerator.Current as CoroutineImpl;
                return(true);
            }
            else
            {
                // This coroutine yielded null, or some other value we don't understand. run it next frame.
                return(true);
            }
        }