Exemplo n.º 1
0
    void Update()
    {
        if (_hasStarted)
        {
            if (Time.time >= _nextSpwanTime)
            {
                if (GhostSpritesQueue.Count == _startSize)
                {
                    GhostSprite peekedGhostSprite = GhostSpritesQueue.Peek();

                    bool canBeReused = peekedGhostSprite.CanBeReused();

                    if (canBeReused)
                    {
                        GhostSpritesQueue.Dequeue();
                        GhostSpritesQueue.Enqueue(peekedGhostSprite);

                        peekedGhostSprite.Initialize(_sprite, _duration, _alpha);

                        _nextSpwanTime += _spwanRate;
                    }
                    else
                    {
                        return;
                    }
                }

                if (GhostSpritesQueue.Count < _startSize)
                {
                    GhostSprite newGhostSprite = Get();
                    GhostSpritesQueue.Enqueue(newGhostSprite);

                    newGhostSprite.Initialize(_sprite, _duration, _alpha);

                    _nextSpwanTime += _spwanRate;
                }

                if (_ghostSpritesQueue.Count > _startSize)
                {
                    int size = GhostSpritesQueue.Count - _startSize;

                    for (int index = 0; index < size; index++)
                    {
                        GhostSprite ghostSprite = GhostSpritesQueue.Dequeue();
                        InactiveGhostSpritePool.Add(ghostSprite);
                    }

                    return;
                }
            }
        }
    }
Exemplo n.º 2
0
    void Update()
    {
        if (ghostingEnabled)
        {
            //check for spawn rate
            //check if we're ok to spawn a new ghost
            if (Time.time >= _nextSpawnTime)
            {
                //is the queue count number equal than the trail length?
                if (GhostingSpritesQueue.Count == trailLength)
                {
                    GhostSprite peekedGhostingSprite = GhostingSpritesQueue.Peek();
                    //is it ok to use?
                    bool canBeReused = peekedGhostingSprite.CanBeReused();
                    if (canBeReused)
                    {
                        //pop the queue
                        GhostingSpritesQueue.Dequeue();
                        GhostingSpritesQueue.Enqueue(peekedGhostingSprite);



                        //initialize the ghosting sprite
                        if (!useTint)
                        {
                            peekedGhostingSprite.Init(effectDuration, _desiredAlpha, _spriteRenderer.sprite, sortingLayer, _spriteRenderer.sortingOrder - 1, transform, Vector3.zero);
                        }
                        else
                        {
                            peekedGhostingSprite.Init(effectDuration, _desiredAlpha, _spriteRenderer.sprite, sortingLayer, _spriteRenderer.sortingOrder - 1, transform, Vector3.zero, _desiredColor);
                        }
                        _nextSpawnTime += spawnRate;
                    }
                    else                         //not ok, wait until next frame to try again
                                                 //peekedGhostingSprite.KillAnimationAndSpeedUpDissapearing();
                    {
                        return;
                    }
                }
                //check if the count is less than the trail length, we need to create a new ghosting sprite
                if (GhostingSpritesQueue.Count < trailLength)
                {
                    GhostSprite newGhostingSprite = Get();
                    GhostingSpritesQueue.Enqueue(newGhostingSprite);                      //queue it up!
                    //newGhostingSprite.Init(_effectDuration, _desiredAlpha, _refSpriteRenderer.sprite, _sortingLayer,_refSpriteRenderer.sortingOrder-1, transform, Vector3.zero );

                    if (!useTint)
                    {
                        newGhostingSprite.Init(effectDuration, _desiredAlpha, _spriteRenderer.sprite, sortingLayer, _spriteRenderer.sortingOrder - 1, transform, Vector3.zero);
                    }
                    else
                    {
                        newGhostingSprite.Init(effectDuration, _desiredAlpha, _spriteRenderer.sprite, sortingLayer, _spriteRenderer.sortingOrder - 1, transform, Vector3.zero, _desiredColor);
                    }
                    _nextSpawnTime += spawnRate;
                }
                //check if the queue count is greater than the trail length. Dequeue these items off the queue, as they are no longer needed
                if (GhostingSpritesQueue.Count > trailLength)
                {
                    int difference = GhostingSpritesQueue.Count - trailLength;
                    for (int i = 1; i < difference; i++)
                    {
                        GhostSprite gs = GhostingSpritesQueue.Dequeue();
                        InactiveGhostSpritePool.Add(gs);
                    }
                    return;
                }
            }
        }
    }