Suspend individually

This commit is contained in:
Noah Pilarski 2022-07-14 01:12:08 -04:00
parent 5bd5ec4950
commit a7af414975
2 changed files with 34 additions and 10 deletions

View File

@ -165,7 +165,7 @@ namespace NewHorizons.Handlers
{
var ao = existingPlanet.GetComponent<AstroObject>();
if (ao != null) Delay.FireInNUpdates(() => PlanetDestructionHandler.RemoveBody(ao), 2);
else Delay.FireInNUpdates(() => existingPlanet.SetActive(false), 2);
else Delay.FireInNUpdates(() => PlanetDestructionHandler.DisableBody(existingPlanet, false), 2);
}
else if (body.Config.isQuantumState)
{

View File

@ -43,14 +43,6 @@ namespace NewHorizons.Handlers
var sunVolumes = SearchUtilities.Find("Sun_Body/Sector_SUN/Volumes_SUN");
sunVolumes.SetActive(false);
foreach (var ow in CenterOfTheUniverse.s_rigidbodies)
{
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)
{
var ao = AstroObjectLocator.GetAstroObject(name);
@ -219,12 +211,44 @@ namespace NewHorizons.Handlers
}
}
private static void DisableBody(GameObject go, bool delete)
private static bool CanSuspend(OWRigidbody rigidbody, string name)
{
if (rigidbody.transform.name == name) return true;
if (rigidbody._origParentBody == null) return false;
return CanSuspend(rigidbody._origParentBody, name);
}
internal static void DisableBody(GameObject go, bool delete)
{
if (go == null) return;
Logger.LogVerbose($"Removing [{go.name}]");
OWRigidbody rigidbody = go.GetComponent<OWRigidbody>();
if (rigidbody != null)
{
string name = rigidbody.transform.name;
foreach (var ow in CenterOfTheUniverse.s_rigidbodies)
{
if (_suspendBlacklist.Contains(ow.transform.name)) continue;
if (ow.GetComponent<AstroObject>() != null) continue;
if (ow._origParentBody != null)
{
if (CanSuspend(ow, name))
{
ow.Suspend();
}
}
else if (ow._simulateInSector != null)
{
if (CanSuspend(ow._simulateInSector.GetAttachedOWRigidbody(), name))
{
ow.Suspend();
}
}
}
}
if (delete)
{
GameObject.Destroy(go);