diff --git a/NewHorizons/Builder/General/PlanetDestroyer.cs b/NewHorizons/Builder/General/PlanetDestroyer.cs index 9fb99db6..c05d2024 100644 --- a/NewHorizons/Builder/General/PlanetDestroyer.cs +++ b/NewHorizons/Builder/General/PlanetDestroyer.cs @@ -91,55 +91,24 @@ namespace NewHorizons.Builder.General { if (ao.GetAstroObjectName() == AstroObject.Name.CaveTwin || ao.GetAstroObjectName() == AstroObject.Name.TowerTwin) { - if (ao.GetAstroObjectName() == AstroObject.Name.TowerTwin) - { - DisableBody(GameObject.Find("TimeLoopRing_Body"), delete); - } DisableBody(GameObject.Find("FocalBody"), delete); } else if (ao.GetAstroObjectName() == AstroObject.Name.MapSatellite) { DisableBody(GameObject.Find("MapSatellite_Body"), delete); } - else if (ao.GetAstroObjectName() == AstroObject.Name.ProbeCannon) - { - DisableBody(GameObject.Find("NomaiProbe_Body"), delete); - DisableBody(GameObject.Find("CannonMuzzle_Body"), delete); - DisableBody(GameObject.Find("FakeCannonMuzzle_Body (1)"), delete); - DisableBody(GameObject.Find("CannonBarrel_Body"), delete); - DisableBody(GameObject.Find("FakeCannonBarrel_Body (1)"), delete); - DisableBody(GameObject.Find("Debris_Body (1)"), delete); - } - else if (ao.GetAstroObjectName() == AstroObject.Name.SunStation) - { - DisableBody(GameObject.Find("SS_Debris_Body"), delete); - } else if (ao.GetAstroObjectName() == AstroObject.Name.GiantsDeep) { - DisableBody(GameObject.Find("BrambleIsland_Body"), delete); - DisableBody(GameObject.Find("GabbroIsland_Body"), delete); - DisableBody(GameObject.Find("QuantumIsland_Body"), delete); - DisableBody(GameObject.Find("StatueIsland_Body"), delete); - DisableBody(GameObject.Find("ConstructionYardIsland_Body"), delete); - DisableBody(GameObject.Find("GabbroShip_Body"), delete); - foreach (var jelly in GameObject.FindObjectsOfType()) { DisableBody(jelly.gameObject, delete); } } - else if (ao.GetAstroObjectName() == AstroObject.Name.WhiteHole) - { - DisableBody(GameObject.Find("WhiteholeStation_Body"), delete); - DisableBody(GameObject.Find("WhiteholeStationSuperstructure_Body"), delete); - } else if (ao.GetAstroObjectName() == AstroObject.Name.TimberHearth) { // Always just fucking kill this one to stop THE WARP BUG!!! DisableBody(GameObject.Find("StreamingGroup_TH"), true); - DisableBody(GameObject.Find("MiningRig_Body"), delete); - foreach (var obj in GameObject.FindObjectsOfType()) { DisableBody(obj.gameObject, true); @@ -176,10 +145,11 @@ namespace NewHorizons.Builder.General GameObject.Destroy(sunProxy.gameObject); } } - else if (ao.GetAstroObjectName() == AstroObject.Name.DreamWorld) + + // Just delete the children + foreach(var child in AstroObjectLocator.GetChildren(ao)) { - DisableBody(GameObject.Find("BackRaft_Body"), delete); - DisableBody(GameObject.Find("SealRaft_Body"), delete); + DisableBody(child, true); } } catch(Exception e) diff --git a/NewHorizons/Main.cs b/NewHorizons/Main.cs index 9303e800..c9eaaec4 100644 --- a/NewHorizons/Main.cs +++ b/NewHorizons/Main.cs @@ -210,7 +210,7 @@ namespace NewHorizons NewHorizonsData.Load(); SignalBuilder.Init(); - AstroObjectLocator.RefreshList(); + AstroObjectLocator.Init(); OWAssetHandler.Init(); PlanetCreationHandler.Init(BodyDict[CurrentStarSystem]); SystemCreationHandler.LoadSystem(SystemDict[CurrentStarSystem]); diff --git a/NewHorizons/Utility/AstroObjectLocator.cs b/NewHorizons/Utility/AstroObjectLocator.cs index f9cd019f..36160891 100644 --- a/NewHorizons/Utility/AstroObjectLocator.cs +++ b/NewHorizons/Utility/AstroObjectLocator.cs @@ -17,6 +17,16 @@ namespace NewHorizons.Utility private static List _list = new List(); + public static void Init() + { + _list = new List(); + _customAstroObjectDictionary = new Dictionary(); + foreach (AstroObject ao in GameObject.FindObjectsOfType()) + { + AddAstroObject(ao); + } + } + public static AstroObject GetAstroObject(string name, bool flag = false) { if (_customAstroObjectDictionary.ContainsKey(name)) return _customAstroObjectDictionary[name]; @@ -98,16 +108,6 @@ namespace NewHorizons.Utility _customAstroObjectDictionary.Remove(ao.GetCustomName()); } - public static void RefreshList() - { - _customAstroObjectDictionary = new Dictionary(); - _list = new List(); - foreach (AstroObject ao in GameObject.FindObjectsOfType()) - { - AddAstroObject(ao); - } - } - public static AstroObject[] GetAllAstroObjects() { return _list.ToArray(); @@ -123,9 +123,54 @@ namespace NewHorizons.Utility _list.Remove(ao); } - public static AstroObject[] GetMoons(AstroObject primary) - { - return _list.Where(x => x._primaryBody == primary).ToArray(); + public static GameObject[] GetMoons(AstroObject primary) + { + return _list.Where(x => x._primaryBody == primary).Select(x => x.gameObject).ToArray(); + } + + public static GameObject[] GetChildren(AstroObject primary) + { + var otherChildren = new List(); + switch(primary.GetAstroObjectName()) + { + case AstroObject.Name.TowerTwin: + otherChildren.Add(GameObject.Find("TimeLoopRing_Body")); + break; + case AstroObject.Name.ProbeCannon: + otherChildren.Add(GameObject.Find("NomaiProbe_Body")); + otherChildren.Add(GameObject.Find("CannonMuzzle_Body")); + otherChildren.Add(GameObject.Find("FakeCannonMuzzle_Body (1)")); + otherChildren.Add(GameObject.Find("CannonBarrel_Body")); + otherChildren.Add(GameObject.Find("FakeCannonBarrel_Body (1)")); + otherChildren.Add(GameObject.Find("Debris_Body (1)")); + break; + case AstroObject.Name.SunStation: + otherChildren.Add(GameObject.Find("SS_Debris_Body")); + break; + case AstroObject.Name.GiantsDeep: + otherChildren.Add(GameObject.Find("BrambleIsland_Body")); + otherChildren.Add(GameObject.Find("GabbroIsland_Body")); + otherChildren.Add(GameObject.Find("QuantumIsland_Body")); + otherChildren.Add(GameObject.Find("StatueIsland_Body")); + otherChildren.Add(GameObject.Find("ConstructionYardIsland_Body")); + otherChildren.Add(GameObject.Find("GabbroShip_Body")); + break; + case AstroObject.Name.WhiteHole: + otherChildren.Add(GameObject.Find("WhiteholeStation_Body")); + otherChildren.Add(GameObject.Find("WhiteholeStationSuperstructure_Body")); + break; + case AstroObject.Name.TimberHearth: + otherChildren.Add(GameObject.Find("MiningRig_Body")); + break; + case AstroObject.Name.DreamWorld: + otherChildren.Add(GameObject.Find("BackRaft_Body")); + otherChildren.Add(GameObject.Find("SealRaft_Body")); + break; + default: + break; + } + + return otherChildren.ToArray(); } } }