Reorganize star evolution controller

This commit is contained in:
Nick 2022-07-14 21:56:25 -04:00
parent 746f279fc0
commit e0a65212e8

View File

@ -55,6 +55,8 @@ namespace NewHorizons.Components.SizeControllers
private float maxScale;
private static readonly int ColorRamp = Shader.PropertyToID("_ColorRamp");
private Color _currentColour;
void Start()
{
var sun = GameObject.FindObjectOfType<SunController>();
@ -151,15 +153,7 @@ namespace NewHorizons.Components.SizeControllers
if (_proxy != null) _proxy.Die();
}
protected new void FixedUpdate()
{
_age += Time.deltaTime;
var ageValue = _age / (lifespan * 60f);
// If we've gone supernova and its been 45 seconds that means it has faded out and is gone
// The 45 is from the animation curve used for the supernova alpha
if (_isSupernova)
private void UpdateSupernova()
{
// Reset the scale back to normal bc now its just the supernova scaling itself + destruction and heat volumes
transform.localScale = Vector3.one;
@ -173,14 +167,11 @@ namespace NewHorizons.Components.SizeControllers
// Just turn off the star entirely
base.gameObject.SetActive(false);
}
return;
}
Color currentColour;
if (!_isCollapsing)
private void UpdateMainSequence()
{
base.FixedUpdate();
var ageValue = _age / (lifespan * 60f);
// Only do colour transition stuff if they set an end colour
if (EndColour != null)
@ -188,17 +179,18 @@ namespace NewHorizons.Components.SizeControllers
// Use the age if theres no resizing happening, else make it get redder the larger it is or wtv
var t = ageValue;
if (maxScale > 0) t = CurrentScale / maxScale;
currentColour = Color.Lerp(_startColour, _endColour, t);
_currentColour = Color.Lerp(_startColour, _endColour, t);
supernova._surface._materials[0].Lerp(_startSurfaceMaterial, _endSurfaceMaterial, t);
}
else
{
currentColour = _startColour;
_currentColour = _startColour;
}
if (_flareEmitter != null) _flareEmitter._tint = currentColour;
if (_flareEmitter != null) _flareEmitter._tint = _currentColour;
}
else
private void UpdateCollapse()
{
// When its collapsing we directly take over the scale
var t = _collapseTimer / collapseTime;
@ -206,7 +198,7 @@ namespace NewHorizons.Components.SizeControllers
transform.localScale = Vector3.one * CurrentScale;
_collapseTimer += Time.deltaTime;
currentColour = Color.Lerp(_endColour, Color.white, t);
_currentColour = Color.Lerp(_endColour, Color.white, t);
supernova._surface._materials[0].Lerp(_collapseStartSurfaceMaterial, _collapseEndSurfaceMaterial, t);
@ -219,8 +211,30 @@ namespace NewHorizons.Components.SizeControllers
_supernovaStartTime = Time.time;
if (atmosphere != null) atmosphere.SetActive(false);
if (_destructionVolume != null) _destructionVolume._deathType = DeathType.Supernova;
}
}
protected new void FixedUpdate()
{
_age += Time.deltaTime;
// If we've gone supernova and its been 45 seconds that means it has faded out and is gone
// The 45 is from the animation curve used for the supernova alpha
if (_isSupernova)
{
UpdateSupernova();
return;
}
if (!_isCollapsing)
{
base.FixedUpdate();
UpdateMainSequence();
}
else
{
UpdateCollapse();
if (_isSupernova) return;
}
// This is just all the scales stuff for the atmosphere effects
@ -230,8 +244,8 @@ namespace NewHorizons.Components.SizeControllers
_fog.lodFadeDistance = CurrentScale * StarBuilder.OuterRadiusRatio / 3f;
// The colour thing goes over one
var max = Math.Max(currentColour.g, Math.Max(currentColour.b, currentColour.r));
var fogColour = currentColour / max / 1.5f;
var max = Math.Max(_currentColour.g, Math.Max(_currentColour.b, _currentColour.r));
var fogColour = _currentColour / max / 1.5f;
fogColour.a = 1f;
_fog.fogTint = fogColour;
_fog._fogTint = fogColour;
@ -243,9 +257,9 @@ namespace NewHorizons.Components.SizeControllers
{
lod.material.SetFloat("_InnerRadius", CurrentScale);
lod.material.SetFloat("_OuterRadius", CurrentScale * StarBuilder.OuterRadiusRatio);
lod.material.SetColor("_AtmosFar", currentColour);
lod.material.SetColor("_AtmosNear", currentColour);
lod.material.SetColor("_SkyColor", currentColour);
lod.material.SetColor("_AtmosFar", _currentColour);
lod.material.SetColor("_AtmosNear", _currentColour);
lod.material.SetColor("_SkyColor", _currentColour);
}
}
}