diff --git a/NewHorizons/Handlers/PlanetCreationHandler.cs b/NewHorizons/Handlers/PlanetCreationHandler.cs index d15c97a9..fb702f54 100644 --- a/NewHorizons/Handlers/PlanetCreationHandler.cs +++ b/NewHorizons/Handlers/PlanetCreationHandler.cs @@ -707,6 +707,62 @@ namespace NewHorizons.Handlers var aoName = ao.GetAstroObjectName(); var aoType = ao.GetAstroObjectType(); + // When updating orbits of the twins be sure the FocalBody is gone + if (aoName == AstroObject.Name.TowerTwin || aoName == AstroObject.Name.CaveTwin) + { + var hourglassTwinsFocal = SearchUtilities.Find("FocalBody"); + + // Have to copy the HGT sector bc it has some ruleset stuff on it we want + var clonedSectorHGT = hourglassTwinsFocal.FindChild("Sector_HGT").Instantiate().Rename("Sector_HGT"); + clonedSectorHGT.transform.parent = go.transform; + clonedSectorHGT.transform.localPosition = Vector3.zero; + clonedSectorHGT.transform.localRotation = Quaternion.identity; + var rootSector = clonedSectorHGT.GetComponent(); + + var streamingGroupGO = hourglassTwinsFocal.GetComponentInChildren().gameObject.Instantiate().Rename("StreamingGroup"); + streamingGroupGO.transform.parent = go.transform; + streamingGroupGO.transform.localPosition = Vector3.zero; + streamingGroupGO.transform.localRotation = Quaternion.identity; + + // HGT streaming group is shared between the two so we have to move it onto the individual ones + // Inefficient because being on ember twin will have ash twin assets load regardless of distance but whatever + var sectorStreaming = clonedSectorHGT.GetComponentInChildren(); + sectorStreaming._streamingGroup = streamingGroupGO.GetComponent(); + sectorStreaming.SetSector(rootSector); + + hourglassTwinsFocal.SetActive(false); + + // Remove the drift tracker since its unneeded now + Component.Destroy(go.GetComponent()); + + // Fix anything pointing to the original HGT sector + foreach (var component in ao.GetComponentsInChildren(true)) + { + if (component is ISectorGroup sectorGroup) + { + if (sectorGroup.GetSector()?._name == Sector.Name.HourglassTwins) + { + sectorGroup.SetSector(rootSector); + } + } + + if (component is SectoredMonoBehaviour behaviour) + { + if (behaviour.GetSector()?._name == Sector.Name.HourglassTwins) + { + behaviour.SetSector(rootSector); + } + } + } + + // Update the parent sector + ao.GetRootSector().SetParentSector(rootSector); + + // Take the hourglass twins shader effect controller off the focal body so it can stay active + var shaderController = hourglassTwinsFocal.GetComponentInChildren(); + if (shaderController != null) shaderController.transform.parent = null; + } + var owrb = go.GetComponent(); var im = go.GetComponent();