diff --git a/NewHorizons/Components/SizeControllers/StarEvolutionController.cs b/NewHorizons/Components/SizeControllers/StarEvolutionController.cs index 0a0e2024..8edb3ab7 100644 --- a/NewHorizons/Components/SizeControllers/StarEvolutionController.cs +++ b/NewHorizons/Components/SizeControllers/StarEvolutionController.cs @@ -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(); @@ -151,76 +153,88 @@ namespace NewHorizons.Components.SizeControllers if (_proxy != null) _proxy.Die(); } + 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; + + // Make the destruction volume scale slightly smaller so you really have to be in the supernova to die + if (_destructionVolume != null) _destructionVolume.transform.localScale = Vector3.one * supernova.GetSupernovaRadius() * 0.9f; + if (_heatVolume != null) _heatVolume.transform.localScale = Vector3.one * supernova.GetSupernovaRadius(); + + if (Time.time > _supernovaStartTime + 45f) + { + // Just turn off the star entirely + base.gameObject.SetActive(false); + } + } + + private void UpdateMainSequence() + { + var ageValue = _age / (lifespan * 60f); + + // Only do colour transition stuff if they set an end colour + if (EndColour != null) + { + // 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); + supernova._surface._materials[0].Lerp(_startSurfaceMaterial, _endSurfaceMaterial, t); + } + else + { + _currentColour = _startColour; + } + + if (_flareEmitter != null) _flareEmitter._tint = _currentColour; + } + + private void UpdateCollapse() + { + // When its collapsing we directly take over the scale + var t = _collapseTimer / collapseTime; + CurrentScale = Mathf.Lerp(_collapseStartSize, 0, t); + transform.localScale = Vector3.one * CurrentScale; + _collapseTimer += Time.deltaTime; + + _currentColour = Color.Lerp(_endColour, Color.white, t); + + supernova._surface._materials[0].Lerp(_collapseStartSurfaceMaterial, _collapseEndSurfaceMaterial, t); + + // After the collapse is done we go supernova + if (_collapseTimer > collapseTime) + { + SupernovaStart.Invoke(); + supernova.enabled = true; + _isSupernova = true; + _supernovaStartTime = Time.time; + if (atmosphere != null) atmosphere.SetActive(false); + if (_destructionVolume != null) _destructionVolume._deathType = DeathType.Supernova; + } + } + 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) { - // Reset the scale back to normal bc now its just the supernova scaling itself + destruction and heat volumes - transform.localScale = Vector3.one; - - // Make the destruction volume scale slightly smaller so you really have to be in the supernova to die - if (_destructionVolume != null) _destructionVolume.transform.localScale = Vector3.one * supernova.GetSupernovaRadius() * 0.9f; - if (_heatVolume != null) _heatVolume.transform.localScale = Vector3.one * supernova.GetSupernovaRadius(); - - if (Time.time > _supernovaStartTime + 45f) - { - // Just turn off the star entirely - base.gameObject.SetActive(false); - } + UpdateSupernova(); return; } - Color currentColour; - if (!_isCollapsing) { base.FixedUpdate(); - - // Only do colour transition stuff if they set an end colour - if (EndColour != null) - { - // 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); - supernova._surface._materials[0].Lerp(_startSurfaceMaterial, _endSurfaceMaterial, t); - } - else - { - currentColour = _startColour; - } - - if (_flareEmitter != null) _flareEmitter._tint = currentColour; + UpdateMainSequence(); } else { - // When its collapsing we directly take over the scale - var t = _collapseTimer / collapseTime; - CurrentScale = Mathf.Lerp(_collapseStartSize, 0, t); - transform.localScale = Vector3.one * CurrentScale; - _collapseTimer += Time.deltaTime; - - currentColour = Color.Lerp(_endColour, Color.white, t); - - supernova._surface._materials[0].Lerp(_collapseStartSurfaceMaterial, _collapseEndSurfaceMaterial, t); - - // After the collapse is done we go supernova - if (_collapseTimer > collapseTime) - { - SupernovaStart.Invoke(); - supernova.enabled = true; - _isSupernova = true; - _supernovaStartTime = Time.time; - if (atmosphere != null) atmosphere.SetActive(false); - if (_destructionVolume != null) _destructionVolume._deathType = DeathType.Supernova; - return; - } + 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); } } }