mirror of
https://github.com/Outer-Wilds-New-Horizons/new-horizons.git
synced 2025-12-11 20:15:44 +01:00
Fixes #514 Setting scale value to 0 should disable it
This commit is contained in:
parent
36a31f3b80
commit
e25cf1e00c
@ -1,10 +1,10 @@
|
||||
using System.Runtime.Serialization;
|
||||
using NewHorizons.Components;
|
||||
using NewHorizons.Utility;
|
||||
using UnityEngine;
|
||||
using Logger = NewHorizons.Utility.Logger;
|
||||
using NewHorizons.External.Modules.VariableSize;
|
||||
using NewHorizons.Components.Orbital;
|
||||
using NewHorizons.Components.SizeControllers;
|
||||
|
||||
namespace NewHorizons.Builder.Body
|
||||
{
|
||||
|
||||
@ -1,18 +1,19 @@
|
||||
using UnityEngine;
|
||||
namespace NewHorizons.Components
|
||||
using UnityEngine;
|
||||
namespace NewHorizons.Components.SizeControllers
|
||||
{
|
||||
public class FunnelController : MonoBehaviour
|
||||
public class FunnelController : SizeController
|
||||
{
|
||||
public AnimationCurve scaleCurve;
|
||||
public Transform target;
|
||||
public Transform anchor;
|
||||
|
||||
private void Update()
|
||||
public override void FixedUpdate()
|
||||
{
|
||||
// Temporary solution that i will never get rid of
|
||||
transform.position = anchor.position;
|
||||
|
||||
float num = scaleCurve?.Evaluate(TimeLoop.GetMinutesElapsed()) ?? 1f;
|
||||
UpdateScale();
|
||||
|
||||
float num = CurrentScale;
|
||||
|
||||
var dist = (transform.position - target.position).magnitude;
|
||||
transform.localScale = new Vector3(num, num, dist / 500f);
|
||||
@ -1,9 +1,5 @@
|
||||
using NewHorizons.Builder.Body;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using NewHorizons.Utility;
|
||||
using UnityEngine;
|
||||
|
||||
namespace NewHorizons.Components.SizeControllers
|
||||
@ -18,7 +14,7 @@ namespace NewHorizons.Components.SizeControllers
|
||||
public WhiteHoleFluidVolume fluidVolume;
|
||||
public WhiteHoleVolume volume;
|
||||
|
||||
protected new void FixedUpdate()
|
||||
public override void FixedUpdate()
|
||||
{
|
||||
base.FixedUpdate();
|
||||
|
||||
@ -56,5 +52,63 @@ namespace NewHorizons.Components.SizeControllers
|
||||
volume._radius = CurrentScale * innerScale;
|
||||
}
|
||||
}
|
||||
|
||||
protected override void Vanish()
|
||||
{
|
||||
if (audioSource != null)
|
||||
{
|
||||
audioSource.gameObject.SetActive(false);
|
||||
audioSource.Stop();
|
||||
}
|
||||
|
||||
if (oneShotAudioSource != null)
|
||||
{
|
||||
oneShotAudioSource.gameObject.SetActive(false);
|
||||
}
|
||||
|
||||
if (sphereCollider != null)
|
||||
{
|
||||
sphereCollider.gameObject.SetActive(false);
|
||||
}
|
||||
|
||||
if (fluidVolume != null)
|
||||
{
|
||||
fluidVolume.gameObject.SetActive(false);
|
||||
}
|
||||
|
||||
if (volume != null)
|
||||
{
|
||||
volume.gameObject.SetActive(false);
|
||||
}
|
||||
}
|
||||
|
||||
protected override void Appear()
|
||||
{
|
||||
if (audioSource != null)
|
||||
{
|
||||
audioSource.gameObject.SetActive(true);
|
||||
Delay.FireOnNextUpdate(audioSource.Play);
|
||||
}
|
||||
|
||||
if (oneShotAudioSource != null)
|
||||
{
|
||||
oneShotAudioSource.gameObject.SetActive(true);
|
||||
}
|
||||
|
||||
if (sphereCollider != null)
|
||||
{
|
||||
sphereCollider.gameObject.SetActive(true);
|
||||
}
|
||||
|
||||
if (fluidVolume != null)
|
||||
{
|
||||
fluidVolume.gameObject.SetActive(true);
|
||||
}
|
||||
|
||||
if (volume != null)
|
||||
{
|
||||
volume.gameObject.SetActive(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,25 +1,71 @@
|
||||
using NewHorizons.Utility;
|
||||
using UnityEngine;
|
||||
|
||||
namespace NewHorizons.Components.SizeControllers
|
||||
{
|
||||
public class SizeController : MonoBehaviour
|
||||
{
|
||||
public AnimationCurve scaleCurve { get; protected set; }
|
||||
public AnimationCurve scaleCurve;
|
||||
public float CurrentScale { get; protected set; }
|
||||
public float size = 1f;
|
||||
|
||||
protected void FixedUpdate()
|
||||
public void Awake()
|
||||
{
|
||||
UpdateScale();
|
||||
|
||||
if (CurrentScale == 0f)
|
||||
{
|
||||
Vanish();
|
||||
}
|
||||
}
|
||||
|
||||
protected void UpdateScale()
|
||||
{
|
||||
if(scaleCurve != null)
|
||||
{
|
||||
var prevScale = CurrentScale;
|
||||
CurrentScale = scaleCurve.Evaluate(TimeLoop.GetMinutesElapsed()) * size;
|
||||
|
||||
// #514 setting something's scale value to 0 should disable it
|
||||
if (prevScale != CurrentScale)
|
||||
{
|
||||
if (CurrentScale == 0f)
|
||||
{
|
||||
Vanish();
|
||||
}
|
||||
else if (prevScale == 0f)
|
||||
{
|
||||
Appear();
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
CurrentScale = size;
|
||||
}
|
||||
}
|
||||
|
||||
base.transform.localScale = Vector3.one * CurrentScale;
|
||||
protected virtual void Vanish()
|
||||
{
|
||||
foreach (var child in gameObject.GetAllChildren())
|
||||
{
|
||||
child.SetActive(false);
|
||||
}
|
||||
}
|
||||
|
||||
protected virtual void Appear()
|
||||
{
|
||||
foreach (var child in gameObject.GetAllChildren())
|
||||
{
|
||||
child.SetActive(true);
|
||||
}
|
||||
}
|
||||
|
||||
public virtual void FixedUpdate()
|
||||
{
|
||||
UpdateScale();
|
||||
|
||||
transform.localScale = Vector3.one * CurrentScale;
|
||||
}
|
||||
|
||||
public void SetScaleCurve(TimeValuePair[] curve)
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user