From 09bf155abcd71474c01e2ed73961b8beeb3de4af Mon Sep 17 00:00:00 2001 From: Lee23 <31892011+LeeTwentyThree@users.noreply.github.com> Date: Sun, 31 Dec 2023 21:37:54 -0500 Subject: [PATCH] fix: Fix base game issue: Atmosphere volumes don't trigger while piloting a vehicle (#516) * Custom atmosphere volumes now work while piloting * Improve template docs --- .../AtmosphereVolumeTemplate.cs | 12 +++++++- .../AtmosphereVolumeTriggerFix.cs | 28 +++++++++++++++++++ 2 files changed, 39 insertions(+), 1 deletion(-) create mode 100644 Nautilus/MonoBehaviours/AtmosphereVolumeTriggerFix.cs diff --git a/Nautilus/Assets/PrefabTemplates/AtmosphereVolumeTemplate.cs b/Nautilus/Assets/PrefabTemplates/AtmosphereVolumeTemplate.cs index 2db3ce64f..fbf3f1a95 100644 --- a/Nautilus/Assets/PrefabTemplates/AtmosphereVolumeTemplate.cs +++ b/Nautilus/Assets/PrefabTemplates/AtmosphereVolumeTemplate.cs @@ -1,11 +1,12 @@ using System; using System.Collections; +using Nautilus.MonoBehaviours; using UnityEngine; namespace Nautilus.Assets.PrefabTemplates; /// -/// A template for Atmosphere Volumes, which are basic invisible triggers for mini-biomes. +/// A template for Atmosphere Volumes, which are basic invisible triggers for mini-biomes. Atmosphere volumes can affect fog, music, ambient sounds and even the player's swim speed. /// public class AtmosphereVolumeTemplate : PrefabTemplate { @@ -23,6 +24,10 @@ public class AtmosphereVolumeTemplate : PrefabTemplate /// The priority of this atmosphere volume. Atmosphere volumes with higher priorities override those with lower priorities. The default priority is 10. /// public int Priority { get; set; } + /// + /// Whether this atmosphere volume can be entered while inside a vehicle or not. For unknown reasons, this is NOT true for base game volumes. However, in this template, it is true by default. + /// + public bool CanEnterWhileInsideVehicle { get; set; } = true; /// /// Determines the loading distance of this atmosphere volume prefab. Default value is . Although vanilla prefabs always use Batch for this, this does not work with our custom systems. @@ -78,6 +83,11 @@ public override IEnumerator GetPrefabAsync(TaskResult gameObject) var atmosphereVolume = prefab.AddComponent(); atmosphereVolume.overrideBiome = OverrideBiome; atmosphereVolume.priority = Priority; + + if (CanEnterWhileInsideVehicle) + { + prefab.AddComponent().atmosphereVolume = atmosphereVolume; + } ModifyPrefab?.Invoke(prefab); if (ModifyPrefabAsync is { }) diff --git a/Nautilus/MonoBehaviours/AtmosphereVolumeTriggerFix.cs b/Nautilus/MonoBehaviours/AtmosphereVolumeTriggerFix.cs new file mode 100644 index 000000000..815b3ab17 --- /dev/null +++ b/Nautilus/MonoBehaviours/AtmosphereVolumeTriggerFix.cs @@ -0,0 +1,28 @@ +using UnityEngine; + +namespace Nautilus.MonoBehaviours; + +// In the base game, atmosphere volumes will not trigger while you're inside a vehicle. This file fixes that issue on custom atmosphere volumes (can be opted out). +internal class AtmosphereVolumeTriggerFix : MonoBehaviour +{ + public AtmosphereVolume atmosphereVolume; + + private void Start() + { + InvokeRepeating(nameof(CheckTriggerEnter), Random.value, 3f); + } + + private void CheckTriggerEnter() + { + if (atmosphereVolume.settingsActive || !isActiveAndEnabled) + { + return; + } + var playerObject = Player.mainObject; + if (playerObject == null) return; + if (atmosphereVolume.Contains(playerObject.transform.position)) + { + atmosphereVolume.PushSettings(); + } + } +} \ No newline at end of file