Fix destruction

This commit is contained in:
Nick 2023-08-04 21:39:20 -04:00
parent 59980f8635
commit 7c745b92c4
2 changed files with 32 additions and 17 deletions

View File

@ -36,6 +36,12 @@ namespace NewHorizons.Handlers
public static void Init(List<NewHorizonsBody> 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<SunLightController>().gameObject);
foreach (var comp in starLightGO.GetComponents<Component>())
{
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)

View File

@ -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<GameObject>();
// 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<ProxyBody>())
{
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>())
proxyBody.gameObject.SetActive(false);
foreach (var gameObject in toDisable)
{
gameObject.SetActive(false);
}
GameObject.FindObjectOfType<SunProxy>().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
{
//streamingAssetBundle.Unload();
}
}
public static void RemoveEyeOfTheUniverse()