public GameObject PickAsteroidGameObjectFromPool(RawAsteroid rawAsteroid)
    {
        int lastIndex = asteroidPool.childCount - 1;

        if (lastIndex >= 0)
        {
            Transform transform = asteroidPool.GetChild(lastIndex);
            transform.GetComponent <Asteroid>().RawAsteroid = rawAsteroid;
            transform.gameObject.SetActive(true);
            transform.SetParent(asteroidContainer);
            transform.position = rawAsteroid.Position;
            transform.rotation = rawAsteroid.Rotation;
            return(transform.gameObject);
        }
        else
        {
            return(CreateAsteroidGameObject(rawAsteroid, asteroidContainer).gameObject);
        }
    }
    public void CreateAsteroids()
    {
        float asteroidColliderRadius = AppManager.DebugSprites ? debugAsteroidColliderRadius : this.asteroidColliderRadius;

        RawCirclesCollision2D.basicDiameterSquared = 4f * asteroidColliderRadius * asteroidColliderRadius;

        for (int i = 0; i < ASTEROID_POOL_CAPACITY; i++)
        {
            CreateAsteroidGameObject(asteroidPool);
        }

        Vector2    cellSize      = spawnGrid.cellSize;
        Vector3Int cellPosition  = Vector3Int.zero;
        Vector3    asteroidEuler = Vector3.zero;

        Bounds2 asteroidBounds = new Bounds2(Vector2.zero, new Vector2(2f * asteroidColliderRadius, 2f * asteroidColliderRadius));
        int     halfXYCount    = spawnGridXYSize >> 1;

        for (int y = -halfXYCount; y < halfXYCount; y++)
        {
            for (int x = -halfXYCount; x < halfXYCount; x++)
            {
                cellPosition.Set(x, y, 0);
                Vector3     asteroidPos = spawnGrid.GetCellCenterWorld(cellPosition);
                RawAsteroid rawAsteroid = new RawAsteroid(this, asteroidPos, asteroidEuler, asteroidBounds, asteroidColliderRadius);
                rawAsteroid.SetRandomVelocities(LINEAR_VELOCITY_MIN, LINEAR_VELOCITY_MAX, ANGULAR_VALOCITY_MIN, ANGULAR_VELOCITY_MAX);
                rawAsteroids.Add(rawAsteroid);
            }
        }
        int xyCount          = spawnGridXYSize;
        int halfXCountInView = Mathf.CeilToInt(cameraBounds.Extents.x / cellSize.x);
        int halfYCountInView = Mathf.CeilToInt(cameraBounds.Extents.y / cellSize.y);

        for (int y = -halfYCountInView; y < halfYCountInView; y++)
        {
            int yIndex = (halfXYCount + y) * xyCount;
            for (int x = -halfXCountInView; x < halfXCountInView; x++)
            {
                int index = yIndex + halfXYCount + x;
                rawAsteroids[index].SetGameObject();
            }
        }
    }
 public void RespawnAsteroid(RawAsteroid asteroid)
 {
     asteroid.SetRandomVelocities(LINEAR_VELOCITY_MIN, LINEAR_VELOCITY_MAX, ANGULAR_VALOCITY_MIN, ANGULAR_VELOCITY_MAX);
     asteroid.SetRandomPositionInBounds(threadGrid.Bounds, cameraBounds);
 }
    private Asteroid CreateAsteroidGameObject(RawAsteroid rawAsteroid, Transform parent)
    {
        Asteroid asteroidPrefab = AppManager.DebugSprites ? debugAsteroidPrefab : this.asteroidPrefab;

        return(asteroidPrefab.CreateInstance(parent, rawAsteroid));
    }