Create sectors using parent for children without one

This commit is contained in:
Noah Pilarski 2022-07-29 11:27:01 -04:00
parent 256fd0eb95
commit 24c43ae747
2 changed files with 47 additions and 1 deletions

View File

@ -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<Sector>();
S._idString = parent._idString;
S._name = parent._name;
S._attachedOWRigidbody = owRigidBody;
S._subsectors = new List<Sector>();
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;
}
}
}

View File

@ -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<Sector>());
case "SandFunnel_Body":
return SectorBuilder.Make(planetGO, rigidbody, SearchUtilities.Find("FocalBody/Sector_HGT").GetComponent<Sector>());
case "SS_Debris_Body":
return SectorBuilder.Make(planetGO, rigidbody, SearchUtilities.Find("SunStation_Body/Sector_SunStation").GetComponent<Sector>());
case "WhiteholeStationSuperstructure_Body":
return SectorBuilder.Make(planetGO, rigidbody, SearchUtilities.Find("WhiteholeStation_Body/Sector_WhiteholeStation").GetComponent<Sector>());
case "MiningRig_Body":
return SectorBuilder.Make(planetGO, rigidbody, SearchUtilities.Find("TimberHearth_Body/Sector_TH/Sector_ZeroGCave").GetComponent<Sector>());
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<Sector>();
var rb = go.GetAttachedOWRigidbody();
var sector = go.GetComponentInChildren<Sector>() ?? 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)