private StarFieldMaterialPropertyManager GetFromPool()
    {
        if (pool.Count == 0)
        {
            return(CreateOne());
        }

        int last = pool.Count - 1;
        StarFieldMaterialPropertyManager sfmpm = pool[last];

        pool.RemoveAt(last);
        sfmpm.rend.enabled = true;
        return(sfmpm);
    }
    private StarFieldMaterialPropertyManager CreateOne()
    {
        GameObject obj = new GameObject();

        obj.transform.parent = sceneryHolder;
        obj.layer            = backgroundLayer;

        SpriteRenderer rend = obj.AddComponent <SpriteRenderer>();

        rend.material = customSpriteMaterial;

        StarFieldMaterialPropertyManager sfmpm = new StarFieldMaterialPropertyManager(rend, obj.transform, obj);

        return(sfmpm);
    }
    private void CoordsChanged(ChunkCoords newCoords, ChunkCoords oldCoords)
    {
        HashSet <ChunkCoords> activeCoords  = new HashSet <ChunkCoords>();
        HashSet <ChunkCoords> removedCoords = new HashSet <ChunkCoords>();

        //send some active objects to the transition pool
        for (int i = active.Count - 1; i >= 0; i--)
        {
            StarFieldMaterialPropertyManager sfmpm = active[i];
            activeCoords.Add(sfmpm.coord);
            if (ChunkCoords.SquareDistance(sfmpm.coord, newCoords) > ViewDistance)
            {
                removedCoords.Add(sfmpm.coord);
                active.RemoveAt(i);
                transitionActive.Add(sfmpm);
            }
        }

        //activate or create new items to fill in the scenery
        EntityNetwork.IterateCoordsInRange(newCoords,
                                           ViewDistance,
                                           cc =>
        {
            int dist = ChunkCoords.SquareDistance(cc, oldCoords);
            if (dist <= ViewDistance && dist != -1)
            {
                return(false);
            }
            ChunkCoords loopedCoords = cc;
            if (hasLoopPoint)
            {
                loopedCoords.x = Mathf.Abs(cc.x) % loopSize;
                loopedCoords.y = Mathf.Abs(cc.y) % loopSize;
            }
            FillSpace(loopedCoords);
            //create new cosmic items
            if (Chunk(loopedCoords).Count == 0)
            {
                FillChunk(loopedCoords);
            }

            SetUpScenery(cc, loopedCoords);
            return(false);
        },
                                           true);
    }