Skip to content

Commit

Permalink
fix: Fix base game issue: Atmosphere volumes don't trigger while pilo…
Browse files Browse the repository at this point in the history
…ting a vehicle (#516)

* Custom atmosphere volumes now work while piloting

* Improve template docs
  • Loading branch information
LeeTwentyThree authored Jan 1, 2024
1 parent 688d017 commit 09bf155
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 1 deletion.
12 changes: 11 additions & 1 deletion Nautilus/Assets/PrefabTemplates/AtmosphereVolumeTemplate.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
using System;
using System.Collections;
using Nautilus.MonoBehaviours;
using UnityEngine;

namespace Nautilus.Assets.PrefabTemplates;

/// <summary>
/// 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.
/// </summary>
public class AtmosphereVolumeTemplate : PrefabTemplate
{
Expand All @@ -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.
/// </summary>
public int Priority { get; set; }
/// <summary>
/// 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.
/// </summary>
public bool CanEnterWhileInsideVehicle { get; set; } = true;

/// <summary>
/// Determines the loading distance of this atmosphere volume prefab. Default value is <see cref="LargeWorldEntity.CellLevel.Far"/>. Although vanilla prefabs always use Batch for this, this does not work with our custom systems.
Expand Down Expand Up @@ -78,6 +83,11 @@ public override IEnumerator GetPrefabAsync(TaskResult<GameObject> gameObject)
var atmosphereVolume = prefab.AddComponent<AtmosphereVolume>();
atmosphereVolume.overrideBiome = OverrideBiome;
atmosphereVolume.priority = Priority;

if (CanEnterWhileInsideVehicle)
{
prefab.AddComponent<AtmosphereVolumeTriggerFix>().atmosphereVolume = atmosphereVolume;
}

ModifyPrefab?.Invoke(prefab);
if (ModifyPrefabAsync is { })
Expand Down
28 changes: 28 additions & 0 deletions Nautilus/MonoBehaviours/AtmosphereVolumeTriggerFix.cs
Original file line number Diff line number Diff line change
@@ -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();
}
}
}

0 comments on commit 09bf155

Please sign in to comment.