From 233bc506250a2010261a149a34ba244965fc8327 Mon Sep 17 00:00:00 2001 From: Nick Date: Sat, 26 Aug 2023 16:26:27 -0400 Subject: [PATCH] Fix moving the twins --- NewHorizons/Handlers/PlanetCreationHandler.cs | 54 ++++--------------- NewHorizons/Streaming/VanillaStreamingFix.cs | 24 +++++---- 2 files changed, 23 insertions(+), 55 deletions(-) diff --git a/NewHorizons/Handlers/PlanetCreationHandler.cs b/NewHorizons/Handlers/PlanetCreationHandler.cs index 86962829..e0e7fe93 100644 --- a/NewHorizons/Handlers/PlanetCreationHandler.cs +++ b/NewHorizons/Handlers/PlanetCreationHandler.cs @@ -16,7 +16,7 @@ using System; using System.Collections.Generic; using System.Linq; using UnityEngine; - +using NewHorizons.Streaming; namespace NewHorizons.Handlers { @@ -717,58 +717,22 @@ namespace NewHorizons.Handlers clonedSectorHGT.transform.parent = go.transform; clonedSectorHGT.transform.localPosition = Vector3.zero; clonedSectorHGT.transform.localRotation = Quaternion.identity; - var hgtSector = 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; + // Don't need this part + GameObject.Destroy(clonedSectorHGT.GetComponentInChildren().gameObject); - // 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(hgtSector); + // 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; 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(hgtSector); - } - } - - if (component is SectoredMonoBehaviour behaviour) - { - if (behaviour.GetSector()?._name == Sector.Name.HourglassTwins) - { - behaviour.SetSector(hgtSector); - } - } - } - - // Sector tweaks - if (aoName == AstroObject.Name.CaveTwin) - { - // Ember Twin hemisphere geometry only fully appears at 300 so we shrink the HGT sector to this size since it controls the proxy geometry - hgtSector.GetComponent().radius = 300; - } - - - // Update the parent sector - ao.GetRootSector().SetParentSector(hgtSector); - - // 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; + // Fix sectors + VanillaStreamingFix.UnparentSectorStreaming(ao.GetRootSector(), ao.gameObject, AstroObject.Name.HourglassTwins, Sector.Name.HourglassTwins); + ao.GetRootSector().SetParentSector(null); } var owrb = go.GetComponent(); diff --git a/NewHorizons/Streaming/VanillaStreamingFix.cs b/NewHorizons/Streaming/VanillaStreamingFix.cs index b6ba2a77..2b5b0c36 100644 --- a/NewHorizons/Streaming/VanillaStreamingFix.cs +++ b/NewHorizons/Streaming/VanillaStreamingFix.cs @@ -1,10 +1,4 @@ using NewHorizons.Handlers; -using NewHorizons.Utility; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; using UnityEngine; namespace NewHorizons.Streaming; @@ -12,21 +6,31 @@ namespace NewHorizons.Streaming; internal static class VanillaStreamingFix { internal static void UnparentSectorStreaming(Sector rootSector, AstroObject.Name streamingGroupName) + => UnparentSectorStreaming(rootSector, rootSector.gameObject, streamingGroupName, Sector.Name.Unnamed); + + internal static void UnparentSectorStreaming(Sector rootSector, GameObject startingObject, AstroObject.Name streamingGroupName, Sector.Name originalParentSectorName) { - foreach (var component in rootSector.GetComponentsInChildren(true)) + // Set originalParentSectorName to unnamed to alter all sectors + foreach (var component in startingObject.GetComponentsInChildren(true)) { if (component is ISectorGroup sectorGroup) { - sectorGroup.SetSector(rootSector); + if (sectorGroup.GetSector()?.GetName() == originalParentSectorName || originalParentSectorName == Sector.Name.Unnamed) + { + sectorGroup.SetSector(rootSector); + } } if (component is SectoredMonoBehaviour behaviour) { - behaviour.SetSector(rootSector); + if (behaviour.GetSector()?.GetName() == originalParentSectorName || originalParentSectorName == Sector.Name.Unnamed) + { + behaviour.SetSector(rootSector); + } } } var sectorStreamingObj = new GameObject("Sector_Streaming"); - sectorStreamingObj.transform.SetParent(rootSector.transform, false); + sectorStreamingObj.transform.SetParent(startingObject.transform, false); var sectorStreaming = sectorStreamingObj.AddComponent(); sectorStreaming._streamingGroup = StreamingHandler.GetStreamingGroup(streamingGroupName);