diff --git a/NewHorizons/Builder/General/SectorBuilder.cs b/NewHorizons/Builder/General/SectorBuilder.cs index 729871e2..a1853415 100644 --- a/NewHorizons/Builder/General/SectorBuilder.cs +++ b/NewHorizons/Builder/General/SectorBuilder.cs @@ -31,5 +31,32 @@ namespace NewHorizons.Builder.General return S; } + + public static Sector Make(GameObject planetBody, OWRigidbody owRigidBody, Sector parent) + { + if (parent == null) return null; + + GameObject sectorGO = new GameObject("Sector"); + sectorGO.SetActive(false); + sectorGO.transform.parent = planetBody.transform; + sectorGO.transform.localPosition = Vector3.zero; + + Sector S = sectorGO.AddComponent(); + S._idString = parent._idString; + S._name = parent._name; + S._attachedOWRigidbody = owRigidBody; + S._subsectors = new List(); + S._triggerRoot = parent._triggerRoot; + S._proximityTrigger = parent._proximityTrigger; + S._volumeExcluder = parent._volumeExcluder; + S._owTriggerVolume = parent._owTriggerVolume; + S._frameCounter = parent._frameCounter; + S.SetParentSector(parent); + + sectorGO.SetActive(true); + S.enabled = true; + + return S; + } } } diff --git a/NewHorizons/Handlers/PlanetCreationHandler.cs b/NewHorizons/Handlers/PlanetCreationHandler.cs index d666420a..bffe3fea 100644 --- a/NewHorizons/Handlers/PlanetCreationHandler.cs +++ b/NewHorizons/Handlers/PlanetCreationHandler.cs @@ -242,13 +242,32 @@ namespace NewHorizons.Handlers return true; } + public static Sector CreateSectorFromParent(GameObject planetGO, OWRigidbody rigidbody) + { + switch (planetGO.name) + { + case "TimeLoopRing_Body": + return SectorBuilder.Make(planetGO, rigidbody, SearchUtilities.Find("TowerTwin_Body/Sector_TowerTwin/Sector_TimeLoopInterior").GetComponent()); + case "SandFunnel_Body": + return SectorBuilder.Make(planetGO, rigidbody, SearchUtilities.Find("FocalBody/Sector_HGT").GetComponent()); + case "SS_Debris_Body": + return SectorBuilder.Make(planetGO, rigidbody, SearchUtilities.Find("SunStation_Body/Sector_SunStation").GetComponent()); + case "WhiteholeStationSuperstructure_Body": + return SectorBuilder.Make(planetGO, rigidbody, SearchUtilities.Find("WhiteholeStation_Body/Sector_WhiteholeStation").GetComponent()); + case "MiningRig_Body": + return SectorBuilder.Make(planetGO, rigidbody, SearchUtilities.Find("TimberHearth_Body/Sector_TH/Sector_ZeroGCave").GetComponent()); + default: + return null; + } + } + // Called when updating an existing planet public static GameObject UpdateBody(NewHorizonsBody body, GameObject go) { Logger.Log($"Updating existing Object {go.name}"); - var sector = go.GetComponentInChildren(); var rb = go.GetAttachedOWRigidbody(); + var sector = go.GetComponentInChildren() ?? CreateSectorFromParent(go, rb); // Since orbits are always there just check if they set a semi major axis if (body.Config.Orbit != null && body.Config.Orbit.semiMajorAxis != 0f)