Make remove children go last and on any body

This commit is contained in:
Nick 2022-08-25 21:24:53 -04:00
parent 90ef0e4beb
commit 56b439be66

View File

@ -277,27 +277,6 @@ namespace NewHorizons.Handlers
UpdateBodyOrbit(body, go); UpdateBodyOrbit(body, go);
} }
if (body.Config.removeChildren != null)
{
var goPath = go.transform.GetPath();
var transforms = go.GetComponentsInChildren<Transform>(true);
foreach (var childPath in body.Config.removeChildren)
{
// Multiple children can have the same path so we delete all that match
var path = $"{goPath}/{childPath}";
var flag = true;
foreach (var childObj in transforms.Where(x => x.GetPath() == path))
{
flag = false;
// idk why we wait here but we do
Delay.FireInNUpdates(() => childObj.gameObject.SetActive(false), 2);
}
if (flag) Logger.LogWarning($"Couldn't find \"{childPath}\".");
}
}
// Do stuff that's shared between generating new planets and updating old ones // Do stuff that's shared between generating new planets and updating old ones
go = SharedGenerateBody(body, go, sector, rb); go = SharedGenerateBody(body, go, sector, rb);
@ -589,6 +568,9 @@ namespace NewHorizons.Handlers
SupernovaEffectBuilder.Make(go, sector, body.Config, procGen, ambientLight, fog, atmosphere, null, fog?._fogImpostor); SupernovaEffectBuilder.Make(go, sector, body.Config, procGen, ambientLight, fog, atmosphere, null, fog?._fogImpostor);
} }
// We allow removing children afterwards so you can also take bits off of the modules you used
if (body.Config.removeChildren != null) RemoveChildren(go, body);
return go; return go;
} }
@ -735,5 +717,26 @@ namespace NewHorizons.Handlers
Main.FurthestOrbit = go.transform.position.magnitude + 30000f; Main.FurthestOrbit = go.transform.position.magnitude + 30000f;
} }
} }
private static void RemoveChildren(GameObject go, NewHorizonsBody body)
{
var goPath = go.transform.GetPath();
var transforms = go.GetComponentsInChildren<Transform>(true);
foreach (var childPath in body.Config.removeChildren)
{
// Multiple children can have the same path so we delete all that match
var path = $"{goPath}/{childPath}";
var flag = true;
foreach (var childObj in transforms.Where(x => x.GetPath() == path))
{
flag = false;
// idk why we wait here but we do
Delay.FireInNUpdates(() => childObj.gameObject.SetActive(false), 2);
}
if (flag) Logger.LogWarning($"Couldn't find \"{childPath}\".");
}
}
} }
} }