mirror of
https://github.com/Outer-Wilds-New-Horizons/new-horizons.git
synced 2025-12-11 20:15:44 +01:00
Add fluid volumes
This commit is contained in:
parent
643a520202
commit
4754dfe043
41
NewHorizons/Builder/Volumes/FluidVolumeBuilder.cs
Normal file
41
NewHorizons/Builder/Volumes/FluidVolumeBuilder.cs
Normal file
@ -0,0 +1,41 @@
|
||||
using NewHorizons.Components.Volumes;
|
||||
using NewHorizons.External.Modules;
|
||||
using OWML.Utils;
|
||||
using UnityEngine;
|
||||
|
||||
namespace NewHorizons.Builder.Volumes
|
||||
{
|
||||
public static class FluidVolumeBuilder
|
||||
{
|
||||
public static FluidVolume Make(GameObject planetGO, Sector sector, VolumesModule.FluidVolumeInfo info)
|
||||
{
|
||||
var type = EnumUtils.Parse<FluidVolume.Type>(info.type.ToString(), FluidVolume.Type.NONE);
|
||||
FluidVolume volume = null;
|
||||
switch (type)
|
||||
{
|
||||
case FluidVolume.Type.PLASMA:
|
||||
case FluidVolume.Type.WATER:
|
||||
var radialVolume = PriorityVolumeBuilder.Make<RadialFluidVolume>(planetGO, sector, info);
|
||||
radialVolume._radius = info.radius;
|
||||
volume = radialVolume;
|
||||
break;
|
||||
case FluidVolume.Type.CLOUD:
|
||||
volume = PriorityVolumeBuilder.Make<CloudLayerFluidVolume>(planetGO, sector, info);
|
||||
break;
|
||||
default:
|
||||
var sphericalVolume = PriorityVolumeBuilder.Make<SphericalFluidVolume>(planetGO, sector, info);
|
||||
sphericalVolume.radius = info.radius;
|
||||
volume = sphericalVolume;
|
||||
break;
|
||||
}
|
||||
|
||||
volume._density = info.density;
|
||||
volume._fluidType = type;
|
||||
volume._alignmentFluid = info.alignmentFluid;
|
||||
volume._allowShipAutoroll = info.allowShipAutoroll;
|
||||
volume._disableOnStart = info.disableOnStart;
|
||||
|
||||
return volume;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -99,6 +99,13 @@ namespace NewHorizons.Builder.Volumes
|
||||
OxygenVolumeBuilder.Make(go, sector, oxygenVolume);
|
||||
}
|
||||
}
|
||||
if (config.Volumes.fluidVolumes != null)
|
||||
{
|
||||
foreach (var fluidVolume in config.Volumes.fluidVolumes)
|
||||
{
|
||||
FluidVolumeBuilder.Make(go, sector, fluidVolume);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
35
NewHorizons/Components/Volumes/SphericalFluidVolume.cs
Normal file
35
NewHorizons/Components/Volumes/SphericalFluidVolume.cs
Normal file
@ -0,0 +1,35 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using UnityEngine;
|
||||
|
||||
namespace NewHorizons.Components.Volumes
|
||||
{
|
||||
public class SphericalFluidVolume : FluidVolume
|
||||
{
|
||||
public float radius;
|
||||
|
||||
public virtual void OnValidate()
|
||||
{
|
||||
SphereCollider collider = GetComponent<SphereCollider>();
|
||||
if (collider != null) collider.radius = radius;
|
||||
|
||||
SphereShape shape = GetComponent<SphereShape>();
|
||||
if (shape != null) shape.radius = radius;
|
||||
}
|
||||
|
||||
public override Vector3 GetPointFluidVelocity(Vector3 worldPosition, FluidDetector detector) => _attachedBody.GetPointVelocity(worldPosition);
|
||||
|
||||
public override bool IsSpherical() => true;
|
||||
|
||||
public override float GetFractionSubmerged(FluidDetector detector) => detector.GetBuoyancyData().CalculateSubmergedFraction((detector.transform.position - transform.position).magnitude, radius);
|
||||
|
||||
public virtual void OnDrawGizmosSelected()
|
||||
{
|
||||
Gizmos.color = Color.cyan;
|
||||
Gizmos.DrawWireSphere(transform.position, radius);
|
||||
}
|
||||
}
|
||||
}
|
||||
46
NewHorizons/External/Modules/VolumesModule.cs
vendored
46
NewHorizons/External/Modules/VolumesModule.cs
vendored
@ -25,6 +25,11 @@ namespace NewHorizons.External.Modules
|
||||
/// </summary>
|
||||
public DestructionVolumeInfo[] destructionVolumes;
|
||||
|
||||
/// <summary>
|
||||
/// Add fluid volumes to this planet.
|
||||
/// </summary>
|
||||
public FluidVolumeInfo[] fluidVolumes;
|
||||
|
||||
/// <summary>
|
||||
/// Add hazard volumes to this planet.
|
||||
/// </summary>
|
||||
@ -338,6 +343,47 @@ namespace NewHorizons.External.Modules
|
||||
/// </summary>
|
||||
[DefaultValue(true)] public bool playRefillAudio = true;
|
||||
}
|
||||
|
||||
[JsonObject]
|
||||
public class FluidVolumeInfo : PriorityVolumeInfo
|
||||
{
|
||||
/// <summary>
|
||||
/// Density of the fluid. The higher the density, the harder it is to go through this fluid.
|
||||
/// </summary>
|
||||
[DefaultValue(1.2f)] public float density = 1.2f;
|
||||
|
||||
/// <summary>
|
||||
/// The type of fluid for this volume.
|
||||
/// </summary>
|
||||
public FluidType type;
|
||||
|
||||
/// <summary>
|
||||
/// Should the player and rafts align to this fluid.
|
||||
/// </summary>
|
||||
[DefaultValue(true)] public bool alignmentFluid = true;
|
||||
|
||||
/// <summary>
|
||||
/// Should the ship align to the fluid by rolling.
|
||||
/// </summary>
|
||||
public bool allowShipAutoroll;
|
||||
|
||||
/// <summary>
|
||||
/// Disable this fluid volume immediately?
|
||||
/// </summary>
|
||||
public bool disableOnStart;
|
||||
|
||||
[JsonConverter(typeof(StringEnumConverter))]
|
||||
public enum FluidType
|
||||
{
|
||||
[EnumMember(Value = @"none")] NONE = 0,
|
||||
[EnumMember(Value = @"air")] AIR,
|
||||
[EnumMember(Value = @"water")] WATER,
|
||||
[EnumMember(Value = @"cloud")] CLOUD,
|
||||
[EnumMember(Value = @"sand")] SAND,
|
||||
[EnumMember(Value = @"plasma")] PLASMA,
|
||||
[EnumMember(Value = @"fog")] FOG
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
[JsonConverter(typeof(StringEnumConverter))]
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user