From 9dcd2e06c954dc643863e8a91c4e6ffe0d978e94 Mon Sep 17 00:00:00 2001 From: JohnCorby Date: Sun, 20 Mar 2022 00:36:42 -0700 Subject: [PATCH] fake elevator sectors: attach to the collider gameobjects in case they're in a different position from the elevator --- QSB/SectorSync/QSBSectorManager.cs | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/QSB/SectorSync/QSBSectorManager.cs b/QSB/SectorSync/QSBSectorManager.cs index e6c1e79f..0473462a 100644 --- a/QSB/SectorSync/QSBSectorManager.cs +++ b/QSB/SectorSync/QSBSectorManager.cs @@ -97,16 +97,20 @@ public class QSBSectorManager : WorldObjectManager foreach (var elevator in QSBWorldSync.GetUnityObjects()) { - radius = float.MinValue; - foreach (var collider in elevator.GetComponentsInChildren()) + var colliders = elevator.GetComponentsInChildren(); + await colliders.Select(x => + UniTask.WaitUntil(() => x.bounds.extents != Vector3.zero, cancellationToken: ct)); + + static float Size(Collider collider) { - await UniTask.WaitUntil(() => collider.bounds.extents != Vector3.zero, cancellationToken: ct); - radius = Mathf.Max(radius, collider.bounds.extents.magnitude); + var extents = collider.bounds.extents; + return Mathf.Max(extents.x, extents.y, extents.z); } - FakeSector.CreateOn(elevator.gameObject, - radius, - elevator.GetComponentInParent()); + var largestCollider = colliders.MaxBy(Size); + FakeSector.CreateOn(largestCollider.gameObject, + Size(largestCollider), + largestCollider.GetComponentInParent()); } } }