Merge branch 'dev' into eye-of-the-universe

This commit is contained in:
Noah Pilarski 2022-10-10 17:09:57 -04:00
commit 311750a646
6 changed files with 29 additions and 20 deletions

View File

@ -3,7 +3,6 @@ using NewHorizons.Utility;
using UnityEngine; using UnityEngine;
using NewHorizons.External.Modules.VariableSize; using NewHorizons.External.Modules.VariableSize;
using Tessellation; using Tessellation;
using NewHorizons.Components.Volumes;
namespace NewHorizons.Builder.Body namespace NewHorizons.Builder.Body
{ {
@ -110,7 +109,7 @@ namespace NewHorizons.Builder.Body
var buoyancyTriggerVolume = buoyancyObject.AddComponent<OWTriggerVolume>(); var buoyancyTriggerVolume = buoyancyObject.AddComponent<OWTriggerVolume>();
buoyancyTriggerVolume._owCollider = owCollider; buoyancyTriggerVolume._owCollider = owCollider;
var fluidVolume = buoyancyObject.AddComponent<NHFluidVolume>(); var fluidVolume = buoyancyObject.AddComponent<RadialFluidVolume>();
fluidVolume._fluidType = FluidVolume.Type.WATER; fluidVolume._fluidType = FluidVolume.Type.WATER;
fluidVolume._attachedBody = rb; fluidVolume._attachedBody = rb;
fluidVolume._triggerVolume = buoyancyTriggerVolume; fluidVolume._triggerVolume = buoyancyTriggerVolume;

View File

@ -61,13 +61,15 @@ namespace NewHorizons.Builder.Props
var raftController = raftObject.GetComponent<RaftController>(); var raftController = raftObject.GetComponent<RaftController>();
raftController._sector = sector; raftController._sector = sector;
raftController._acceleration = info.acceleration;
sector.OnOccupantEnterSector += raftController.OnOccupantEnterSector; sector.OnOccupantEnterSector += raftController.OnOccupantEnterSector;
sector.OnOccupantExitSector += raftController.OnOccupantExitSector; sector.OnOccupantExitSector += raftController.OnOccupantExitSector;
// Detectors // Detectors
var fluidDetector = raftObject.transform.Find("Detector_Raft").GetComponent<RaftFluidDetector>(); var fluidDetector = raftObject.transform.Find("Detector_Raft").GetComponent<RaftFluidDetector>();
var waterVolume = (FluidVolume)planetGO.GetComponentInChildren<NHFluidVolume>() ?? planetGO.GetComponentInChildren<SphereOceanFluidVolume>(); var waterVolume = planetGO.GetComponentInChildren<RadialFluidVolume>();
fluidDetector._alignmentFluid = waterVolume; fluidDetector._alignmentFluid = waterVolume;
fluidDetector._buoyancy.checkAgainstWaves = true;
// Light sensors // Light sensors
foreach (var lightSensor in raftObject.GetComponentsInChildren<SingleLightSensor>()) foreach (var lightSensor in raftObject.GetComponentsInChildren<SingleLightSensor>())

View File

@ -1,13 +0,0 @@
using UnityEngine;
namespace NewHorizons.Components.Volumes
{
public class NHFluidVolume : RadialFluidVolume
{
public override float GetDepthAtPosition(Vector3 worldPosition)
{
Vector3 vector = transform.InverseTransformPoint(worldPosition);
float dist = Mathf.Sqrt(vector.x * vector.x + vector.z * vector.z + vector.y * vector.y);
return dist - _radius;
}
}
}

View File

@ -233,6 +233,11 @@ namespace NewHorizons.External.Modules
/// Position of the raft /// Position of the raft
/// </summary> /// </summary>
public MVector3 position; public MVector3 position;
/// <summary>
/// Acceleration of the raft. Default acceleration is 5.
/// </summary>
[DefaultValue(5f)] public float acceleration = 5f;
} }
[JsonObject] [JsonObject]

View File

@ -1,5 +1,4 @@
using HarmonyLib; using HarmonyLib;
using NewHorizons.Components.Volumes;
using UnityEngine; using UnityEngine;
namespace NewHorizons.Patches namespace NewHorizons.Patches
{ {
@ -74,17 +73,17 @@ namespace NewHorizons.Patches
} }
[HarmonyReversePatch] [HarmonyReversePatch]
[HarmonyPatch(typeof(AsymmetricFluidDetector), "ManagedFixedUpdate")] [HarmonyPatch(typeof(AsymmetricFluidDetector), nameof(AsymmetricFluidDetector.ManagedFixedUpdate))]
public static void AsymmetricFluidDetector_ManagedFixedUpdate(AsymmetricFluidDetector __instance) public static void AsymmetricFluidDetector_ManagedFixedUpdate(AsymmetricFluidDetector __instance)
{ {
// This is like doing base.FixedUpdate // This is like doing base.FixedUpdate
} }
[HarmonyPrefix] [HarmonyPrefix]
[HarmonyPatch(typeof(AlignToSurfaceFluidDetector), "ManagedFixedUpdate")] [HarmonyPatch(typeof(AlignToSurfaceFluidDetector), nameof(AlignToSurfaceFluidDetector.ManagedFixedUpdate))]
public static bool AlignToSurfaceFluidDetector_ManagedFixedUpdate(AlignToSurfaceFluidDetector __instance) public static bool AlignToSurfaceFluidDetector_ManagedFixedUpdate(AlignToSurfaceFluidDetector __instance)
{ {
if (!(__instance._alignmentFluid is NHFluidVolume)) return true; if (__instance._alignmentFluid is not RadialFluidVolume) return true;
// Mostly copy pasting from the AlignWithDirection class // Mostly copy pasting from the AlignWithDirection class
AsymmetricFluidDetector_ManagedFixedUpdate(__instance); AsymmetricFluidDetector_ManagedFixedUpdate(__instance);
@ -104,5 +103,16 @@ namespace NewHorizons.Patches
return false; return false;
} }
[HarmonyPrefix]
[HarmonyPatch(typeof(FluidVolume), nameof(FluidVolume.GetDepthAtPosition))]
public static bool FluidVolume_GetDepthAtPosition(FluidVolume __instance, ref float __result, Vector3 worldPosition)
{
if (__instance is not RadialFluidVolume radialFluidVolume) return true;
Vector3 vector = radialFluidVolume.transform.InverseTransformPoint(worldPosition);
__result = Mathf.Sqrt(vector.x * vector.x + vector.z * vector.z + vector.y * vector.y) - radialFluidVolume._radius;
return false;
}
} }
} }

View File

@ -1339,6 +1339,12 @@
"position": { "position": {
"description": "Position of the raft", "description": "Position of the raft",
"$ref": "#/definitions/MVector3" "$ref": "#/definitions/MVector3"
},
"acceleration": {
"type": "number",
"description": "Acceleration of the raft. Default acceleration is 5.",
"format": "float",
"default": 5.0
} }
} }
}, },