mirror of
https://github.com/Outer-Wilds-New-Horizons/new-horizons.git
synced 2025-12-11 20:15:44 +01:00
Switch to using a custom structure implementation instead
This commit is contained in:
parent
1bc581cee0
commit
f3f211a130
@ -21,8 +21,8 @@ namespace NewHorizons.Components.Quantum
|
|||||||
private AlignWithTargetBody _alignment;
|
private AlignWithTargetBody _alignment;
|
||||||
private OWRigidbody _rb;
|
private OWRigidbody _rb;
|
||||||
private OrbitLine _orbitLine;
|
private OrbitLine _orbitLine;
|
||||||
private QuantumShrine[] _shrines;
|
private QuantumStructure[] _structures = new QuantumStructure[0];
|
||||||
private QuantumDarkTrigger[] _darkTriggers;
|
private QuantumDarkTrigger[] _darkTriggers = new QuantumDarkTrigger[0];
|
||||||
|
|
||||||
public NHAstroObject astroObject
|
public NHAstroObject astroObject
|
||||||
{
|
{
|
||||||
@ -65,6 +65,9 @@ namespace NewHorizons.Components.Quantum
|
|||||||
|
|
||||||
public void ResetStates(bool changeState)
|
public void ResetStates(bool changeState)
|
||||||
{
|
{
|
||||||
|
_structures = GetComponentsInChildren<QuantumStructure>(true); // finds all quantum structures
|
||||||
|
_darkTriggers = GetComponentsInChildren<QuantumDarkTrigger>(true); // finds all quantum dark triggers
|
||||||
|
|
||||||
if (changeState)
|
if (changeState)
|
||||||
{
|
{
|
||||||
ChangeQuantumState(true);
|
ChangeQuantumState(true);
|
||||||
@ -73,9 +76,6 @@ namespace NewHorizons.Components.Quantum
|
|||||||
{
|
{
|
||||||
SetNewSector(states[CurrentIndex]);
|
SetNewSector(states[CurrentIndex]);
|
||||||
}
|
}
|
||||||
|
|
||||||
_shrines = GetComponentsInChildren<QuantumShrine>(true); // finds all quantum shrines
|
|
||||||
_darkTriggers = GetComponentsInChildren<QuantumDarkTrigger>(true); // finds all quantum dark triggers
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void OnDestroy()
|
public override void OnDestroy()
|
||||||
@ -168,6 +168,11 @@ namespace NewHorizons.Components.Quantum
|
|||||||
}
|
}
|
||||||
|
|
||||||
newState.sector.gameObject.SetActive(true);
|
newState.sector.gameObject.SetActive(true);
|
||||||
|
|
||||||
|
foreach (var structure in _structures)
|
||||||
|
{
|
||||||
|
structure.OnQuantumPlanetStateChanged(CurrentIndex);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void SetNewOrbit(AstroObject primaryBody, OrbitalParameters orbitalParameters)
|
private void SetNewOrbit(AstroObject primaryBody, OrbitalParameters orbitalParameters)
|
||||||
@ -200,9 +205,9 @@ namespace NewHorizons.Components.Quantum
|
|||||||
trackingOrbitLine.Reset();
|
trackingOrbitLine.Reset();
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach (var shrine in _shrines)
|
foreach (var structure in _structures)
|
||||||
{
|
{
|
||||||
shrine.OnQuantumMoonSurfaceStateChanged(CurrentIndex);
|
structure.OnQuantumPlanetOrbitChanged(CurrentIndex);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -235,11 +240,11 @@ namespace NewHorizons.Components.Quantum
|
|||||||
return states[CurrentIndex].sector.ContainsAnyOccupants(DynamicOccupant.Ship);
|
return states[CurrentIndex].sector.ContainsAnyOccupants(DynamicOccupant.Ship);
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool IsPlayerInsideShrine()
|
public bool IsPlayerInsideStructure()
|
||||||
{
|
{
|
||||||
foreach (var shrine in _shrines)
|
foreach (var structure in _structures)
|
||||||
{
|
{
|
||||||
if (shrine.IsPlayerInside())
|
if (structure.IsPlayerInside())
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
@ -252,9 +257,9 @@ namespace NewHorizons.Components.Quantum
|
|||||||
if (darkTrigger.IsPlayerInDarkness())
|
if (darkTrigger.IsPlayerInDarkness())
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
foreach (var shrine in _shrines)
|
foreach (var structure in _structures)
|
||||||
{
|
{
|
||||||
if (shrine.IsPlayerInDarkness())
|
if (structure.IsPlayerInDarkness())
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
|
|||||||
190
NewHorizons/Components/Quantum/QuantumStructure.cs
Normal file
190
NewHorizons/Components/Quantum/QuantumStructure.cs
Normal file
@ -0,0 +1,190 @@
|
|||||||
|
using NewHorizons.Utility.OWML;
|
||||||
|
using System;
|
||||||
|
using UnityEngine;
|
||||||
|
|
||||||
|
namespace NewHorizons.Components.Quantum
|
||||||
|
{
|
||||||
|
public class QuantumStructure : MonoBehaviour
|
||||||
|
{
|
||||||
|
[SerializeField]
|
||||||
|
public OWTriggerVolume insideTriggerVolume;
|
||||||
|
|
||||||
|
[SerializeField]
|
||||||
|
public Light[] lights = new Light[0];
|
||||||
|
|
||||||
|
[SerializeField]
|
||||||
|
public Light ambientLight;
|
||||||
|
|
||||||
|
[SerializeField]
|
||||||
|
public FogOverrideVolume fogOverride;
|
||||||
|
|
||||||
|
protected float fadeFraction { get; private set; } = 1f;
|
||||||
|
|
||||||
|
protected bool isPlayerInside { get; private set; }
|
||||||
|
|
||||||
|
protected bool isProbeInside { get; private set; }
|
||||||
|
|
||||||
|
protected bool fading { get; private set; }
|
||||||
|
|
||||||
|
private float _origAmbientIntensity;
|
||||||
|
|
||||||
|
private Color _origFogTint;
|
||||||
|
|
||||||
|
public virtual void Awake()
|
||||||
|
{
|
||||||
|
if (ambientLight != null)
|
||||||
|
{
|
||||||
|
_origAmbientIntensity = ambientLight.intensity;
|
||||||
|
}
|
||||||
|
if (fogOverride != null)
|
||||||
|
{
|
||||||
|
_origFogTint = fogOverride.tint;
|
||||||
|
}
|
||||||
|
if (insideTriggerVolume != null)
|
||||||
|
{
|
||||||
|
insideTriggerVolume.OnEntry += OnEntry;
|
||||||
|
insideTriggerVolume.OnExit += OnExit;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
NHLogger.LogWarning("Missing inside trigger volume for " + this.GetType());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public virtual void Start()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
public virtual void OnDestroy()
|
||||||
|
{
|
||||||
|
if (insideTriggerVolume != null)
|
||||||
|
{
|
||||||
|
insideTriggerVolume.OnEntry -= OnEntry;
|
||||||
|
insideTriggerVolume.OnExit -= OnExit;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public virtual bool IsPlayerInside()
|
||||||
|
{
|
||||||
|
return isPlayerInside;
|
||||||
|
}
|
||||||
|
|
||||||
|
public virtual bool IsProbeInside()
|
||||||
|
{
|
||||||
|
return isProbeInside;
|
||||||
|
}
|
||||||
|
|
||||||
|
public virtual bool IsPlayerInDarkness()
|
||||||
|
{
|
||||||
|
foreach (var light in lights)
|
||||||
|
{
|
||||||
|
if (light.intensity > 0f)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (isPlayerInside && fadeFraction == 0f && !isProbeInside && !PlayerState.IsFlashlightOn())
|
||||||
|
{
|
||||||
|
return Locator.GetThrusterLightTracker().GetLightRange() <= 0f;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public virtual void OnQuantumPlanetStateChanged(int currentIndex)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
public virtual void OnQuantumPlanetOrbitChanged(int state)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
public virtual void Update()
|
||||||
|
{
|
||||||
|
if (fading)
|
||||||
|
{
|
||||||
|
float target = (isPlayerInside ? (GetOpenFraction() * 0.7f) : 1f);
|
||||||
|
fadeFraction = Mathf.MoveTowards(fadeFraction, target, Time.deltaTime * 0.5f);
|
||||||
|
FadeUpdate();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public virtual float GetOpenFraction()
|
||||||
|
{
|
||||||
|
return 1f;
|
||||||
|
}
|
||||||
|
|
||||||
|
public virtual void FadeUpdate()
|
||||||
|
{
|
||||||
|
if (ambientLight != null)
|
||||||
|
{
|
||||||
|
ambientLight.intensity = _origAmbientIntensity * fadeFraction;
|
||||||
|
}
|
||||||
|
if (fogOverride != null)
|
||||||
|
{
|
||||||
|
fogOverride.tint = Color.Lerp(Color.black, _origFogTint, fadeFraction);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void OnEntry(GameObject hitObj)
|
||||||
|
{
|
||||||
|
if (hitObj.CompareTag("PlayerDetector"))
|
||||||
|
{
|
||||||
|
isPlayerInside = true;
|
||||||
|
fading = true;
|
||||||
|
OnPlayerEntry(hitObj);
|
||||||
|
}
|
||||||
|
else if (hitObj.CompareTag("ProbeDetector"))
|
||||||
|
{
|
||||||
|
isProbeInside = true;
|
||||||
|
OnProbeEntry(hitObj);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
OnOtherEntry(hitObj);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public virtual void OnPlayerEntry(GameObject playerDetector)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
public virtual void OnProbeEntry(GameObject probeDetector)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
public virtual void OnOtherEntry(GameObject otherDetector)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
public void OnExit(GameObject hitObj)
|
||||||
|
{
|
||||||
|
if (hitObj.CompareTag("PlayerDetector"))
|
||||||
|
{
|
||||||
|
isPlayerInside = false;
|
||||||
|
fading = true;
|
||||||
|
OnPlayerExit(hitObj);
|
||||||
|
}
|
||||||
|
else if (hitObj.CompareTag("ProbeDetector"))
|
||||||
|
{
|
||||||
|
isProbeInside = false;
|
||||||
|
OnProbeExit(hitObj);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
OnOtherExit(hitObj);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public virtual void OnPlayerExit(GameObject playerDetector)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
public virtual void OnProbeExit(GameObject probeDetector)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
public virtual void OnOtherExit(GameObject otherDetector)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
x
Reference in New Issue
Block a user