Пример #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);
        }
Пример #2
0
        /// <summary>
        /// adds a Particle to the emitter
        /// </summary>
        void addParticle()
        {
            // take the next particle out of the particle pool we have created and initialize it
            var particle = QuickCache <Particle> .pop();

            particle.initialize(_emitterConfig);
            _particles.Add(particle);
        }
Пример #3
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();
 }
Пример #4
0
        /// <summary>
        /// schedules a one-time or repeating timer that will call the passed in Action
        /// </summary>
        /// <param name="timeInSeconds">Time in seconds.</param>
        /// <param name="repeats">If set to <c>true</c> repeats.</param>
        /// <param name="context">Context.</param>
        /// <param name="onTime">On time.</param>
        internal ITimer schedule(float timeInSeconds, bool repeats, object context, Action <ITimer> onTime)
        {
            var timer = QuickCache <Timer> .pop();

            timer.initialize(timeInSeconds, repeats, context, onTime);
            _timers.Add(timer);

            return(timer);
        }
Пример #5
0
        public static ITween <Color> colorPropertyTo(object self, string propertyName, Color to, float duration)
        {
            var tweenTarget = new PropertyTarget <Color>(self, propertyName);
            var tween       = TweenManager.cacheColorTweens ? QuickCache <ColorTween> .pop() : new ColorTween();

            tween.initialize(tweenTarget, to, duration);

            return(tween);
        }
Пример #6
0
        public static ITween <float> floatPropertyTo(object self, string propertyName, float to, float duration)
        {
            var tweenTarget = new PropertyTarget <float>(self, propertyName);
            var tween       = TweenManager.cacheFloatTweens ? QuickCache <FloatTween> .pop() : new FloatTween();

            tween.initialize(tweenTarget, to, duration);

            return(tween);
        }
Пример #7
0
        public override void recycleSelf()
        {
            base.recycleSelf();

            if (_shouldRecycleTween && TweenManager.cacheFloatTweens)
            {
                QuickCache <FloatTween> .push(this);
            }
        }
Пример #8
0
        public static ITween <Vector3> vector3PropertyTo(object self, string propertyName, Vector3 to, float duration)
        {
            var tweenTarget = new PropertyTarget <Vector3>(self, propertyName);
            var tween       = TweenManager.cacheVector3Tweens ? QuickCache <Vector3Tween> .pop() : new Vector3Tween();

            tween.initialize(tweenTarget, to, duration);

            return(tween);
        }
Пример #9
0
        public static ITween <Quaternion> quaternionPropertyTo(object self, string propertyName, Quaternion to, float duration)
        {
            var tweenTarget = new PropertyTarget <Quaternion>(self, propertyName);
            var tween       = TweenManager.cacheQuaternionTweens ? QuickCache <QuaternionTween> .pop() : new QuaternionTween();

            tween.initialize(tweenTarget, to, duration);

            return(tween);
        }
Пример #10
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);
                }
            }
        }
Пример #11
0
 public override void recycleSelf()
 {
     if (_shouldRecycleTween)
     {
         _target    = null;
         _nextTween = null;
         _transform = null;
         QuickCache <TransformVector2Tween> .push(this);
     }
 }
Пример #12
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;
        }
Пример #13
0
        public ParticleEmitter(ParticleEmitterConfig emitterConfig, bool playOnAwake = true)
        {
            _emitterConfig = emitterConfig;
            _playOnAwake   = playOnAwake;
            _particles     = new List <Particle>((int)_emitterConfig.maxParticles);
            QuickCache <Particle> .warmCache((int)_emitterConfig.maxParticles);

            // set some sensible defaults
            collisionConfig.elasticity          = 0.5f;
            collisionConfig.friction            = 0.5f;
            collisionConfig.collidesWithLayers  = Physics.allLayers;
            collisionConfig.gravity             = _emitterConfig.gravity;
            collisionConfig.lifetimeLoss        = 0f;
            collisionConfig.minKillSpeedSquared = float.MinValue;
            collisionConfig.radiusScale         = 0.8f;

            initialize();
        }
Пример #14
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);
            }
        }
Пример #15
0
 public static IntTween create()
 {
     return(TweenManager.cacheIntTweens ? QuickCache <IntTween> .pop() : new IntTween());
 }
Пример #16
0
 public static ColorTween create()
 {
     return(TweenManager.cacheColorTweens ? QuickCache <ColorTween> .pop() : new ColorTween());
 }
Пример #17
0
 public static RectangleTween create()
 {
     return(TweenManager.cacheRectTweens ? QuickCache <RectangleTween> .pop() : new RectangleTween());
 }
Пример #18
0
 public static FloatTween create()
 {
     return(TweenManager.cacheFloatTweens ? QuickCache <FloatTween> .pop() : new FloatTween());
 }
Пример #19
0
 public static Vector2Tween create()
 {
     return(TweenManager.cacheVector2Tweens ? QuickCache <Vector2Tween> .pop() : new Vector2Tween());
 }
Пример #20
0
 public static QuaternionTween create()
 {
     return(TweenManager.cacheQuaternionTweens ? QuickCache <QuaternionTween> .pop() : new QuaternionTween());
 }