mirror of
https://github.com/Outer-Wilds-New-Horizons/new-horizons.git
synced 2025-12-11 20:15:44 +01:00
Make sand funnels actually work
This commit is contained in:
parent
83f99029af
commit
6c32b3c7a2
@ -1,4 +1,5 @@
|
||||
using NewHorizons.External.VariableSize;
|
||||
using NewHorizons.Components;
|
||||
using NewHorizons.External.VariableSize;
|
||||
using NewHorizons.Utility;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
@ -20,7 +21,7 @@ namespace NewHorizons.Builder.Body
|
||||
STAR
|
||||
}
|
||||
|
||||
public static void Make(GameObject go, ConstantForceDetector detector, InitialMotion initialMotion, FunnelModule module)
|
||||
public static void Make(GameObject go, ConstantForceDetector detector, OWRigidbody rigidbody, FunnelModule module)
|
||||
{
|
||||
var funnelType = FunnelType.SAND;
|
||||
if (module.Type.ToUpper().Equals("WATER")) funnelType = FunnelType.WATER;
|
||||
@ -29,17 +30,16 @@ namespace NewHorizons.Builder.Body
|
||||
|
||||
var funnelGO = new GameObject($"{go.name.Replace("_Body", "")}Funnel_Body");
|
||||
funnelGO.SetActive(false);
|
||||
funnelGO.transform.parent = go.transform;
|
||||
|
||||
var owrb = funnelGO.AddComponent<OWRigidbody>();
|
||||
var alignment = funnelGO.AddComponent<AlignWithTargetBody>();
|
||||
Main.Instance.ModHelper.Events.Unity.FireOnNextUpdate(() => alignment.SetTargetBody(AstroObjectLocator.GetAstroObject(module.Target)?.GetAttachedOWRigidbody()));
|
||||
|
||||
var im = funnelGO.AddComponent<InitialMotion>();
|
||||
var velocity = initialMotion.GetInitVelocity();
|
||||
im._initLinearDirection = initialMotion._initLinearDirection;
|
||||
im._initLinearSpeed = initialMotion._initLinearSpeed;
|
||||
funnelGO.AddComponent<InitialMotion>();
|
||||
|
||||
var matchMotion = funnelGO.AddComponent<MatchInitialMotion>();
|
||||
matchMotion.SetBodyToMatch(rigidbody);
|
||||
|
||||
funnelGO.AddComponent<SandFunnelController>();
|
||||
funnelGO.AddComponent<CenterOfTheUniverseOffsetApplier>();
|
||||
funnelGO.AddComponent<KinematicRigidbody>();
|
||||
|
||||
@ -53,6 +53,9 @@ namespace NewHorizons.Builder.Body
|
||||
|
||||
var scaleRoot = new GameObject("ScaleRoot");
|
||||
scaleRoot.transform.parent = funnelGO.transform;
|
||||
scaleRoot.transform.rotation = Quaternion.Euler(90, 0, 0);
|
||||
scaleRoot.transform.localPosition = new Vector3(0, 30, 0);
|
||||
scaleRoot.transform.localScale = new Vector3(1, 1, 1.075f);
|
||||
|
||||
var proxyGO = GameObject.Instantiate(GameObject.Find("SandFunnel_Body/ScaleRoot/Proxy_SandFunnel"), scaleRoot.transform);
|
||||
proxyGO.name = "Proxy_Funnel";
|
||||
@ -63,24 +66,107 @@ namespace NewHorizons.Builder.Body
|
||||
var volumesGO = GameObject.Instantiate(GameObject.Find("SandFunnel_Body/ScaleRoot/Volumes_SandFunnel"), scaleRoot.transform);
|
||||
volumesGO.name = "Volumes_Funnel";
|
||||
var sfv = volumesGO.GetComponentInChildren<SimpleFluidVolume>();
|
||||
switch(funnelType)
|
||||
var fluidVolume = sfv.gameObject;
|
||||
switch (funnelType)
|
||||
{
|
||||
case FunnelType.SAND:
|
||||
sfv._fluidType = FluidVolume.Type.SAND;
|
||||
break;
|
||||
case FunnelType.WATER:
|
||||
sfv._fluidType = FluidVolume.Type.WATER;
|
||||
|
||||
GameObject.Destroy(geoGO.transform.Find("Effects_HT_SandColumn/SandColumn_Interior").gameObject);
|
||||
|
||||
var waterMaterial = GameObject.Find("TimberHearth_Body/Sector_TH/Geometry_TH/Terrain_TH_Water_v3/Village_Upper_Water/Village_Upper_Water_Geo").GetComponent<MeshRenderer>().material;
|
||||
proxyGO.GetComponentInChildren<MeshRenderer>().material = waterMaterial;
|
||||
geoGO.GetComponentInChildren<MeshRenderer>().material = waterMaterial;
|
||||
|
||||
break;
|
||||
case FunnelType.LAVA:
|
||||
sfv._fluidType = FluidVolume.Type.PLASMA;
|
||||
|
||||
GameObject.Destroy(geoGO.transform.Find("Effects_HT_SandColumn/SandColumn_Interior").gameObject);
|
||||
|
||||
var lavaMaterial = GameObject.Find("VolcanicMoon_Body/MoltenCore_VM/LavaSphere").GetComponent<MeshRenderer>().material;
|
||||
proxyGO.GetComponentInChildren<MeshRenderer>().material = lavaMaterial;
|
||||
geoGO.GetComponentInChildren<MeshRenderer>().material = lavaMaterial;
|
||||
|
||||
AddDestructionVolumes(fluidVolume);
|
||||
|
||||
break;
|
||||
case FunnelType.STAR:
|
||||
sfv._fluidType = FluidVolume.Type.PLASMA;
|
||||
|
||||
GameObject.Destroy(geoGO.transform.Find("Effects_HT_SandColumn/SandColumn_Interior").gameObject);
|
||||
|
||||
var starMaterial = GameObject.Find("VolcanicMoon_Body/MoltenCore_VM/LavaSphere").GetComponent<MeshRenderer>().material;
|
||||
proxyGO.GetComponentInChildren<MeshRenderer>().material = starMaterial;
|
||||
geoGO.GetComponentInChildren<MeshRenderer>().material = starMaterial;
|
||||
|
||||
AddDestructionVolumes(fluidVolume);
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
funnelGO.transform.position = go.transform.position;
|
||||
var sector = go.GetComponent<AstroObject>().GetPrimaryBody().GetRootSector();
|
||||
proxyGO.GetComponent<SectorProxy>().SetSector(sector);
|
||||
geoGO.GetComponent<SectorCullGroup>().SetSector(sector);
|
||||
volumesGO.GetComponent<SectorCollisionGroup>().SetSector(sector);
|
||||
|
||||
funnelGO.transform.localPosition = Vector3.zero;
|
||||
|
||||
var funnelSizeController = funnelGO.AddComponent<FunnelSizeController>();
|
||||
|
||||
if(module.Curve != null)
|
||||
{
|
||||
var curve = new AnimationCurve();
|
||||
foreach (var pair in module.Curve)
|
||||
{
|
||||
curve.AddKey(new Keyframe(pair.Time, pair.Value));
|
||||
}
|
||||
funnelSizeController.scaleCurve = curve;
|
||||
}
|
||||
|
||||
// Finish up next tick
|
||||
Main.Instance.ModHelper.Events.Unity.FireOnNextUpdate(() => PostMake(funnelGO, alignment, funnelSizeController, module));
|
||||
}
|
||||
|
||||
private static void PostMake(GameObject funnelGO, AlignWithTargetBody alignment, FunnelSizeController funnelSizeController, FunnelModule module)
|
||||
{
|
||||
var target = AstroObjectLocator.GetAstroObject(module.Target)?.GetAttachedOWRigidbody();
|
||||
if(target == null)
|
||||
{
|
||||
Logger.LogWarning($"Couldn't find the target for the funnel {funnelGO.name}");
|
||||
return;
|
||||
}
|
||||
|
||||
alignment.SetTargetBody(target);
|
||||
|
||||
funnelSizeController.target = target.gameObject.transform;
|
||||
|
||||
funnelGO.SetActive(true);
|
||||
|
||||
// This has to happen last idk
|
||||
alignment.SetUsePhysicsToRotate(true);
|
||||
}
|
||||
|
||||
private static void AddDestructionVolumes(GameObject go)
|
||||
{
|
||||
// Gotta put destruction volumes on the children reeeeeeeeee
|
||||
foreach (Transform child in go.transform)
|
||||
{
|
||||
var capsuleShape = child.GetComponent<CapsuleShape>();
|
||||
|
||||
var capsuleCollider = child.gameObject.AddComponent<CapsuleCollider>();
|
||||
capsuleCollider.radius = capsuleShape.radius;
|
||||
capsuleCollider.height = capsuleShape.height;
|
||||
capsuleCollider.isTrigger = true;
|
||||
|
||||
child.gameObject.AddComponent<OWCapsuleCollider>();
|
||||
|
||||
var destructionVolume = child.gameObject.AddComponent<DestructionVolume>();
|
||||
destructionVolume._deathType = DeathType.Lava;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
22
NewHorizons/Components/FunnelSizeController.cs
Normal file
22
NewHorizons/Components/FunnelSizeController.cs
Normal file
@ -0,0 +1,22 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using UnityEngine;
|
||||
|
||||
namespace NewHorizons.Components
|
||||
{
|
||||
public class FunnelSizeController : MonoBehaviour
|
||||
{
|
||||
public AnimationCurve scaleCurve;
|
||||
public Transform target;
|
||||
|
||||
private void FixedUpdate()
|
||||
{
|
||||
float num = scaleCurve == null ? 1f : scaleCurve.Evaluate(TimeLoop.GetMinutesElapsed());
|
||||
var dist = (transform.position - target.position).magnitude;
|
||||
transform.localScale = new Vector3(num, dist/500f, num);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -433,6 +433,8 @@ namespace NewHorizons
|
||||
|
||||
var atmoSize = body.Config.Atmosphere != null ? body.Config.Atmosphere.Size : 0f;
|
||||
float sphereOfInfluence = Mathf.Max(Mathf.Max(atmoSize, 50), body.Config.Base.SurfaceSize * 2f);
|
||||
var overrideSOI = body.Config.Base.SphereOfInfluence;
|
||||
if (overrideSOI != 0) sphereOfInfluence = overrideSOI;
|
||||
|
||||
var outputTuple = BaseBuilder.Make(go, primaryBody, body.Config);
|
||||
var ao = (AstroObject)outputTuple.Item1;
|
||||
@ -495,7 +497,7 @@ namespace NewHorizons
|
||||
if (!body.Config.Orbit.IsStatic) DetectorBuilder.Make(go, owRigidBody, primaryBody, ao);
|
||||
|
||||
if (body.Config.Funnel != null)
|
||||
FunnelBuilder.Make(go, go.GetComponentInChildren<ConstantForceDetector>(), initialMotion, body.Config.Funnel);
|
||||
FunnelBuilder.Make(go, go.GetComponentInChildren<ConstantForceDetector>(), owRigidBody, body.Config.Funnel);
|
||||
|
||||
if (ao.GetAstroObjectName() == AstroObject.Name.CustomString) AstroObjectLocator.RegisterCustomAstroObject(ao);
|
||||
|
||||
|
||||
@ -362,7 +362,7 @@
|
||||
"default": 0
|
||||
},
|
||||
"value": {
|
||||
"type": "integer",
|
||||
"type": "number",
|
||||
"default": 0
|
||||
}
|
||||
}
|
||||
@ -582,7 +582,7 @@
|
||||
"default": 0
|
||||
},
|
||||
"value": {
|
||||
"type": "integer",
|
||||
"type": "number",
|
||||
"default": 0
|
||||
}
|
||||
}
|
||||
@ -950,7 +950,7 @@
|
||||
"default": 0
|
||||
},
|
||||
"value": {
|
||||
"type": "integer",
|
||||
"type": "number",
|
||||
"default": 0
|
||||
}
|
||||
}
|
||||
@ -975,7 +975,7 @@
|
||||
"default": 0
|
||||
},
|
||||
"value": {
|
||||
"type": "integer",
|
||||
"type": "number",
|
||||
"default": 0
|
||||
}
|
||||
}
|
||||
@ -1029,7 +1029,7 @@
|
||||
"default": 0
|
||||
},
|
||||
"value": {
|
||||
"type": "integer",
|
||||
"type": "number",
|
||||
"default": 0
|
||||
}
|
||||
}
|
||||
@ -1093,7 +1093,7 @@
|
||||
"default": 0
|
||||
},
|
||||
"value": {
|
||||
"type": "integer",
|
||||
"type": "number",
|
||||
"default": 0
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user