From 3059468d79197b7cd55cfdd22be311f3848d76cc Mon Sep 17 00:00:00 2001 From: dev <81720436+developer9998@users.noreply.github.com> Date: Mon, 9 Sep 2024 00:59:45 -0230 Subject: [PATCH] Update Main.cs --- GorillaShirts/Behaviours/Main.cs | 52 +++++++++++++++++--------------- 1 file changed, 27 insertions(+), 25 deletions(-) diff --git a/GorillaShirts/Behaviours/Main.cs b/GorillaShirts/Behaviours/Main.cs index bd17a7b..b7e016f 100644 --- a/GorillaShirts/Behaviours/Main.cs +++ b/GorillaShirts/Behaviours/Main.cs @@ -182,31 +182,7 @@ public async Task InitStand() shirtStand.transform.rotation = Quaternion.Euler(_standLocations.First().Location.Item2); AudioSource standAudio = shirtStand.transform.Find("MainSource").GetComponent(); - ZoneManagement.OnZoneChange += (ZoneData[] zones) => - { - IEnumerable changedZones = zones.Select(zone => zone.zone); - - foreach (GTZone currentZone in changedZones) - { - IStandLocation currentLocation = _standLocations.FirstOrDefault(zone => zone.IsInZone(currentZone)); - if (currentLocation != null) - { - try - { - Tuple locationData = currentLocation.Location; - shirtStand.transform.position = locationData.Item1; - shirtStand.transform.rotation = Quaternion.Euler(locationData.Item2); - shirtStand.SetActive(true); - } - catch - { - Logging.Error($"No stand location exists for zones {string.Join(", ", changedZones)}, hiding shirt stand"); - shirtStand.SetActive(false); - } - break; - } - } - }; + ZoneManagement.OnZoneChange += OnZoneChange; StandRig standRig = new() { @@ -366,6 +342,32 @@ public async Task InitStand() }; } + private void OnZoneChange(ZoneData[] zones) + { + IEnumerable activeZones = zones.Where(zone => zone.active).Select(zone => zone.zone); + + Logging.Info($"Zone changed: {string.Join(", ", activeZones)}"); + + foreach (GTZone currentZone in activeZones) + { + IStandLocation currentLocation = _standLocations.FirstOrDefault(zone => zone.IsInZone(currentZone)); + + if (currentLocation != null) + { + Logging.Info($"We are in {currentLocation.GetType().Name} ({currentZone} is active)"); + + Tuple locationData = currentLocation.Location; + Stand.Object.transform.position = locationData.Item1; + Stand.Object.transform.rotation = Quaternion.Euler(locationData.Item2); + Stand.Object.SetActive(true); + return; + } + } + + Logging.Error($"No stand location exists for zones {string.Join(", ", activeZones)}, hiding shirt stand"); + Stand.Object.SetActive(false); + } + public async Task InitAudio() { _audios =