Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix base game issue: Atmosphere volumes don't trigger while piloting a vehicle #516

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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();
}
}
}