Stop any rigidbody from unparenting itself when deleting solar system

This commit is contained in:
Noah Pilarski 2022-07-13 19:52:47 -04:00
parent adf8f0b182
commit 6945c0b6c7

View File

@ -3,6 +3,7 @@ using NewHorizons.Utility;
using OWML.Utils; using OWML.Utils;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq;
using UnityEngine; using UnityEngine;
using Logger = NewHorizons.Utility.Logger; using Logger = NewHorizons.Utility.Logger;
namespace NewHorizons.Handlers namespace NewHorizons.Handlers
@ -30,12 +31,26 @@ namespace NewHorizons.Handlers
"White Hole" "White Hole"
}; };
private static readonly string[] _suspendBlacklist = new string[]
{
"Player_Body",
"Ship_Body"
};
public static void RemoveSolarSystem() public static void RemoveSolarSystem()
{ {
// Stop the sun from killing the player // Stop the sun from killing the player
var sunVolumes = SearchUtilities.Find("Sun_Body/Sector_SUN/Volumes_SUN"); var sunVolumes = SearchUtilities.Find("Sun_Body/Sector_SUN/Volumes_SUN");
sunVolumes.SetActive(false); sunVolumes.SetActive(false);
foreach (var ow in GameObject.FindObjectsOfType<OWRigidbody>())
{
if (ow._origParent != null && (ow._origParentBody != null || ow._simulateInSector != null) && ow.transform.GetComponent<AstroObject>() == null && !ow._suspended && !_suspendBlacklist.Contains(ow.gameObject.name))
{
ow.Suspend();
}
}
foreach (var name in _solarSystemBodies) foreach (var name in _solarSystemBodies)
{ {
var ao = AstroObjectLocator.GetAstroObject(name); var ao = AstroObjectLocator.GetAstroObject(name);