From 7c745b92c4046194db92fd411c8cb2e0b3b66383 Mon Sep 17 00:00:00 2001 From: Nick Date: Fri, 4 Aug 2023 21:39:20 -0400 Subject: [PATCH] Fix destruction --- NewHorizons/Handlers/PlanetCreationHandler.cs | 12 +++--- .../Handlers/PlanetDestructionHandler.cs | 37 +++++++++++++------ 2 files changed, 32 insertions(+), 17 deletions(-) diff --git a/NewHorizons/Handlers/PlanetCreationHandler.cs b/NewHorizons/Handlers/PlanetCreationHandler.cs index 38958aa2..aca59e13 100644 --- a/NewHorizons/Handlers/PlanetCreationHandler.cs +++ b/NewHorizons/Handlers/PlanetCreationHandler.cs @@ -36,6 +36,12 @@ namespace NewHorizons.Handlers public static void Init(List bodies) { + // Start by destroying all planets if need be + if (Main.SystemDict[Main.Instance.CurrentStarSystem].Config.destroyStockPlanets) + { + PlanetDestructionHandler.RemoveStockPlanets(); + } + // Base game value SolarSystemRadius = DefaultFurthestOrbit; @@ -60,7 +66,7 @@ namespace NewHorizons.Handlers var starLightGO = UnityEngine.Object.Instantiate(sun.GetComponentInChildren().gameObject); foreach (var comp in starLightGO.GetComponents()) { - if (!(comp is SunLightController) && !(comp is SunLightParamUpdater) && !(comp is Light) && !(comp is Transform)) + if (comp is not SunLightController && comp is not SunLightParamUpdater && comp is not Light && comp is not Transform) { UnityEngine.Object.Destroy(comp); } @@ -138,10 +144,6 @@ namespace NewHorizons.Handlers NHLogger.Log("Done loading bodies"); SingularityBuilder.PairAllSingularities(); - - // Events.FireOnNextUpdate(PlanetDestroyer.RemoveAllProxies); - - if (Main.SystemDict[Main.Instance.CurrentStarSystem].Config.destroyStockPlanets) PlanetDestructionHandler.RemoveStockPlanets(); } public static bool LoadBody(NewHorizonsBody body, bool defaultPrimaryToSun = false) diff --git a/NewHorizons/Handlers/PlanetDestructionHandler.cs b/NewHorizons/Handlers/PlanetDestructionHandler.cs index 9fa47805..79f65cb6 100644 --- a/NewHorizons/Handlers/PlanetDestructionHandler.cs +++ b/NewHorizons/Handlers/PlanetDestructionHandler.cs @@ -54,23 +54,36 @@ namespace NewHorizons.Handlers public static void RemoveSolarSystem() { - // Stop the sun from killing the player if they spawn at the center of the solar system - SearchUtilities.Find("Sun_Body/Sector_SUN/Volumes_SUN").SetActive(false); + // Adapted from EOTS thanks corby + var toDisable = new List(); + + // Collect all rigid bodies and proxies + foreach (var rigidbody in CenterOfTheUniverse.s_rigidbodies) + { + if (rigidbody.name is not "Player_Body" && rigidbody.name is not "Ship_Body") + { + toDisable.Add(rigidbody.gameObject); + } + } + + foreach (var proxyBody in GameObject.FindObjectsOfType()) + { + toDisable.Add(proxyBody.gameObject); + } Delay.FireInNUpdates(() => { - // From EOTS thanks corby - foreach (var rigidbody in CenterOfTheUniverse.s_rigidbodies) - if (rigidbody.name is not "Player_Body" or "Ship_Body") - rigidbody.gameObject.SetActive(false); - - foreach (var proxyBody in GameObject.FindObjectsOfType()) - proxyBody.gameObject.SetActive(false); + foreach (var gameObject in toDisable) + { + gameObject.SetActive(false); + } GameObject.FindObjectOfType().gameObject.SetActive(false); + }, 2); // Have to wait or shit goes wild - foreach (var streamingAssetBundle in StreamingManager.s_activeBundles) - streamingAssetBundle.Unload(); - }, 2); // Random shit breaks if we don't wait idk why + foreach (var streamingAssetBundle in StreamingManager.s_activeBundles) + { + //streamingAssetBundle.Unload(); + } } public static void RemoveEyeOfTheUniverse()