/// <summary> /// Strip out various modules from the asteroids as they make excessive amounts of GC allocations. /// Then set up the initial asteroid rotations. /// </summary> IEnumerator CleanOutAsteroids() { var wait = new WaitForFixedUpdate(); while (asteroids.Any(a => a != null && (a.packed || !a.loaded))) { yield return(wait); } for (int i = 0; i < asteroids.Length; ++i) { if (asteroids[i] == null) { continue; } AsteroidUtils.CleanOutAsteroid(asteroids[i]); } yield return(InitialRotation()); }
/// <summary> /// Wait until the collider bounds have been generated, then remove various modules from the asteroid for performance reasons. /// </summary> /// <param name="asteroid">The asteroid to clean.</param> IEnumerator CleanAsteroid(Vessel asteroid) { ++cleaningInProgress; var wait = new WaitForFixedUpdate(); asteroid.gameObject.SetActive(true); var startTime = Time.time; while (asteroid != null && Time.time - startTime < 10 && (asteroid.packed || !asteroid.loaded || asteroid.rootPart.GetColliderBounds().Length < 2)) { yield return(wait); } if (asteroid != null) { if (Time.time - startTime >= 10) { Debug.LogWarning($"[BDArmory.Asteroids]: Timed out waiting for colliders on {asteroid.vesselName} to be generated."); } AsteroidUtils.CleanOutAsteroid(asteroid); asteroid.gameObject.SetActive(false); } --cleaningInProgress; }