mirror of
https://github.com/Outer-Wilds-New-Horizons/new-horizons.git
synced 2025-12-11 20:15:44 +01:00
Try making planetary nebula also fix end tint not going onto collapse ramp when no collapse ramp is specified
This commit is contained in:
parent
4c031f9df5
commit
972486d545
@ -7,6 +7,7 @@ using NewHorizons.Utility.OuterWilds;
|
||||
using OWML.Common;
|
||||
using System.Linq;
|
||||
using UnityEngine;
|
||||
using static Mono.Security.X509.X520;
|
||||
|
||||
namespace NewHorizons.Builder.Body
|
||||
{
|
||||
@ -287,27 +288,27 @@ namespace NewHorizons.Builder.Body
|
||||
|
||||
var starGO = MakeStarGraphics(planetGO, sector, starModule, mod);
|
||||
starGO.SetActive(false);
|
||||
|
||||
var ramp = starGO.GetComponentInChildren<TessellatedSphereRenderer>(true).sharedMaterial.GetTexture(ColorRamp);
|
||||
|
||||
var starEvolutionController = starGO.AddComponent<StarEvolutionController>();
|
||||
var starEvolutionController = starGO.GetComponent<StarEvolutionController>();
|
||||
starEvolutionController.isRemnant = isStellarRemnant;
|
||||
if (starModule.curve != null) starEvolutionController.SetScaleCurve(starModule.curve);
|
||||
starEvolutionController.size = starModule.size;
|
||||
starEvolutionController.startColour = starModule.tint;
|
||||
starEvolutionController.endColour = starModule.endTint;
|
||||
|
||||
starEvolutionController.normalRamp = !string.IsNullOrEmpty(starModule.starRampTexture) ? ImageUtilities.GetTexture(mod, starModule.starRampTexture) : ramp;
|
||||
if (!string.IsNullOrEmpty(starModule.starCollapseRampTexture))
|
||||
{
|
||||
starEvolutionController.collapseRamp = ImageUtilities.GetTexture(mod, starModule.starCollapseRampTexture);
|
||||
}
|
||||
|
||||
StellarDeathController supernova = null;
|
||||
var willExplode = !isStellarRemnant && starModule.stellarDeathType != StellarDeathType.None;
|
||||
if (willExplode)
|
||||
{
|
||||
supernova = MakeSupernova(starGO, starModule);
|
||||
if (starModule.stellarDeathType == StellarDeathType.PlanetaryNebula)
|
||||
{
|
||||
starEvolutionController.planetaryNebula =
|
||||
[
|
||||
MakeSupernova(starGO, starModule, true, true),
|
||||
MakeSupernova(starGO, starModule, true, true),
|
||||
MakeSupernova(starGO, starModule, true, true)
|
||||
];
|
||||
}
|
||||
else
|
||||
{
|
||||
supernova = MakeSupernova(starGO, starModule);
|
||||
starEvolutionController.supernova = supernova;
|
||||
}
|
||||
|
||||
starEvolutionController.supernovaSize = starModule.supernovaSize;
|
||||
var duration = starModule.supernovaSize / starModule.supernovaSpeed;
|
||||
@ -315,7 +316,7 @@ namespace NewHorizons.Builder.Body
|
||||
starEvolutionController.supernovaScaleEnd = duration;
|
||||
starEvolutionController.supernovaScaleStart = duration * 0.9f;
|
||||
starEvolutionController.deathType = starModule.stellarDeathType;
|
||||
starEvolutionController.supernova = supernova;
|
||||
|
||||
starEvolutionController.supernovaColour = starModule.supernovaTint;
|
||||
starEvolutionController.lifespan = starModule.lifespan;
|
||||
}
|
||||
@ -359,6 +360,20 @@ namespace NewHorizons.Builder.Body
|
||||
emitter.tint = starModule.tint.ToColor();
|
||||
}
|
||||
|
||||
var ramp = starGO.GetComponentInChildren<TessellatedSphereRenderer>(true).sharedMaterial.GetTexture(ColorRamp);
|
||||
|
||||
var starEvolutionController = starGO.AddComponent<StarEvolutionController>();
|
||||
if (starModule.curve != null) starEvolutionController.SetScaleCurve(starModule.curve);
|
||||
starEvolutionController.size = starModule.size;
|
||||
starEvolutionController.startColour = starModule.tint;
|
||||
starEvolutionController.endColour = starModule.endTint;
|
||||
|
||||
starEvolutionController.normalRamp = !string.IsNullOrEmpty(starModule.starRampTexture) ? ImageUtilities.GetTexture(mod, starModule.starRampTexture) : ramp;
|
||||
if (!string.IsNullOrEmpty(starModule.starCollapseRampTexture))
|
||||
{
|
||||
starEvolutionController.collapseRamp = ImageUtilities.GetTexture(mod, starModule.starCollapseRampTexture);
|
||||
}
|
||||
|
||||
var material = new Material(_flareMaterial);
|
||||
|
||||
// Make our own copies of all prefabs to make sure we don't actually modify them
|
||||
@ -412,6 +427,11 @@ namespace NewHorizons.Builder.Body
|
||||
Color.RGBToHSV(adjustedEndColour, out var hEnd, out var sEnd, out var vEnd);
|
||||
var darkenedEndColor = Color.HSVToRGB(hEnd, sEnd * 1.2f, vEnd * 0.1f);
|
||||
surface.sharedMaterial.SetTexture(ColorRamp, ImageUtilities.LerpGreyscaleImageAlongX(_colorOverTime, adjustedColour, darkenedColor, adjustedEndColour, darkenedEndColor));
|
||||
|
||||
if (string.IsNullOrEmpty(starModule.starCollapseRampTexture))
|
||||
{
|
||||
starEvolutionController.collapseRamp = ImageUtilities.LerpGreyscaleImageAlongX(_colorOverTime, adjustedEndColour, darkenedEndColor, Color.white, Color.white);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -421,10 +441,10 @@ namespace NewHorizons.Builder.Body
|
||||
|
||||
if (!string.IsNullOrEmpty(starModule.starRampTexture))
|
||||
{
|
||||
var ramp = ImageUtilities.GetTexture(mod, starModule.starRampTexture);
|
||||
if (ramp != null)
|
||||
var starRamp = ImageUtilities.GetTexture(mod, starModule.starRampTexture);
|
||||
if (starRamp != null)
|
||||
{
|
||||
surface.sharedMaterial.SetTexture(ColorRamp, ramp);
|
||||
surface.sharedMaterial.SetTexture(ColorRamp, starRamp);
|
||||
}
|
||||
}
|
||||
|
||||
@ -433,7 +453,7 @@ namespace NewHorizons.Builder.Body
|
||||
return starGO;
|
||||
}
|
||||
|
||||
public static StellarDeathController MakeSupernova(GameObject starGO, StarModule starModule, bool noAudio = false)
|
||||
public static StellarDeathController MakeSupernova(GameObject starGO, StarModule starModule, bool noAudio = false, bool noSurface = false)
|
||||
{
|
||||
InitPrefabs();
|
||||
|
||||
@ -444,8 +464,11 @@ namespace NewHorizons.Builder.Body
|
||||
|
||||
var supernova = supernovaGO.GetComponent<SupernovaEffectController>();
|
||||
var stellarDeath = supernovaGO.AddComponent<StellarDeathController>();
|
||||
stellarDeath.enabled = false;
|
||||
stellarDeath.surface = starGO.GetComponentInChildren<TessellatedSphereRenderer>(true);
|
||||
stellarDeath.enabled = false;
|
||||
if (!noSurface)
|
||||
{
|
||||
stellarDeath.surface = starGO.GetComponentInChildren<TessellatedSphereRenderer>(true);
|
||||
}
|
||||
var duration = starModule.supernovaSize / starModule.supernovaSpeed;
|
||||
stellarDeath.supernovaScale = new AnimationCurve(new Keyframe(0, 200, 0, 0, 1f / 3f, 1f / 3f), new Keyframe(duration, starModule.supernovaSize, 1758.508f, 1758.508f, 1f / 3f, 1f / 3f));
|
||||
stellarDeath.supernovaAlpha = new AnimationCurve(new Keyframe(duration * 0.1f, 1, 0, 0, 1f / 3f, 1f / 3f), new Keyframe(duration * 0.3f, 1.0002f, 0, 0, 1f / 3f, 1f / 3f), new Keyframe(duration, 0, -0.0578f, 1 / 3f, -0.0578f, 1 / 3f));
|
||||
|
||||
@ -10,6 +10,7 @@ using System;
|
||||
using System.Linq;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Events;
|
||||
using NewHorizons.Utility.Files;
|
||||
|
||||
|
||||
namespace NewHorizons.Components.SizeControllers
|
||||
@ -22,6 +23,7 @@ namespace NewHorizons.Components.SizeControllers
|
||||
public GameObject atmosphere;
|
||||
public StarController controller;
|
||||
public StellarDeathController supernova;
|
||||
public StellarDeathController[] planetaryNebula;
|
||||
public bool willExplode;
|
||||
public MColor startColour;
|
||||
public MColor endColour;
|
||||
@ -98,6 +100,8 @@ namespace NewHorizons.Components.SizeControllers
|
||||
|
||||
private TessellatedSphereRenderer _surface;
|
||||
|
||||
public static Material WhiteDwarfCollapseMaterial;
|
||||
|
||||
public static void Init()
|
||||
{
|
||||
var sun = SearchUtilities.Find("Sun_Body").GetComponent<SunController>();
|
||||
@ -109,12 +113,20 @@ namespace NewHorizons.Components.SizeControllers
|
||||
if (_defaultCollapseEndSurfaceMaterial == null) _defaultCollapseEndSurfaceMaterial = new Material(sun._collapseEndSurfaceMaterial).DontDestroyOnLoad();
|
||||
if (_defaultStartSurfaceMaterial == null) _defaultStartSurfaceMaterial = new Material(sun._startSurfaceMaterial).DontDestroyOnLoad();
|
||||
if (_defaultEndSurfaceMaterial == null) _defaultEndSurfaceMaterial = new Material(sun._endSurfaceMaterial).DontDestroyOnLoad();
|
||||
if (_defaultEndSurfaceMaterial == null) _defaultEndSurfaceMaterial = new Material(sun._endSurfaceMaterial).DontDestroyOnLoad();
|
||||
|
||||
if (_defaultNormalRamp == null) _defaultNormalRamp = sun._startSurfaceMaterial.GetTexture(ColorRamp).DontDestroyOnLoad();
|
||||
if (_defaultCollapseRamp == null) _defaultCollapseRamp = sun._collapseStartSurfaceMaterial.GetTexture(ColorRamp).DontDestroyOnLoad();
|
||||
|
||||
if (WhiteDwarfCollapseMaterial == null)
|
||||
{
|
||||
WhiteDwarfCollapseMaterial = new Material(_defaultStartSurfaceMaterial).DontDestroyOnLoad();
|
||||
WhiteDwarfCollapseMaterial.SetTexture(ColorRamp, ImageUtilities.MakeSolidColorTexture(1, 1, Color.white));
|
||||
WhiteDwarfCollapseMaterial.color = Color.white;
|
||||
}
|
||||
}
|
||||
|
||||
private void Start()
|
||||
public void Start()
|
||||
{
|
||||
_surface = GetComponentInChildren<TessellatedSphereRenderer>(true);
|
||||
_surfaceMaterial = _surface._materials[0];
|
||||
@ -204,11 +216,17 @@ namespace NewHorizons.Components.SizeControllers
|
||||
{
|
||||
var timeAfter = secondsElapsed - lifespanInSeconds;
|
||||
if (timeAfter <= collapseTime)
|
||||
{
|
||||
Delay.RunWhen(() => Main.IsSystemReady, StartCollapse);
|
||||
}
|
||||
else if (timeAfter <= collapseTime + supernovaTime)
|
||||
{
|
||||
Delay.RunWhen(() => Main.IsSystemReady, StartSupernova);
|
||||
}
|
||||
else
|
||||
{
|
||||
Delay.RunWhen(() => Main.IsSystemReady, () => Delay.FireOnNextUpdate(() => DisableStar(true)));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -258,6 +276,7 @@ namespace NewHorizons.Components.SizeControllers
|
||||
}
|
||||
}
|
||||
|
||||
private float _nextPlanetaryNebulaPulse = 0f;
|
||||
private void UpdateCollapse()
|
||||
{
|
||||
// When its collapsing we directly take over the scale
|
||||
@ -268,11 +287,41 @@ namespace NewHorizons.Components.SizeControllers
|
||||
|
||||
_currentColour = Color.Lerp(_endColour, Color.white, t);
|
||||
|
||||
_surface._materials[0].Lerp(_collapseStartSurfaceMaterial, _collapseEndSurfaceMaterial, t);
|
||||
if (deathType != StellarDeathType.PlanetaryNebula)
|
||||
{
|
||||
_surface._materials[0].Lerp(_collapseStartSurfaceMaterial, _collapseEndSurfaceMaterial, t);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (_collapseTimer > _nextPlanetaryNebulaPulse)
|
||||
{
|
||||
var interval = collapseTime / this.planetaryNebula.Length;
|
||||
_nextPlanetaryNebulaPulse += interval;
|
||||
var nextLayer = this.planetaryNebula.FirstOrDefault(x => !x.enabled);
|
||||
nextLayer?.Activate();
|
||||
if (oneShotSource != null && !PlayerState.IsSleepingAtCampfire() && !PlayerState.InDreamWorld())
|
||||
{
|
||||
oneShotSource.PlayOneShot(AudioType.Sun_Explosion);
|
||||
}
|
||||
}
|
||||
|
||||
_surface._materials[0].Lerp(_collapseStartSurfaceMaterial, WhiteDwarfCollapseMaterial, t);
|
||||
_surface._materials[0].SetFloat(ColorTime, t);
|
||||
}
|
||||
|
||||
// After the collapse is done we go supernova
|
||||
// Main star will call this on the proxy
|
||||
if (!isProxy && _collapseTimer > collapseTime) StartSupernova();
|
||||
if (_collapseTimer > collapseTime)
|
||||
{
|
||||
if (deathType == StellarDeathType.PlanetaryNebula)
|
||||
{
|
||||
this.enabled = false;
|
||||
}
|
||||
else if (!isProxy)
|
||||
{
|
||||
StartSupernova();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void UpdateSupernova()
|
||||
@ -292,11 +341,7 @@ namespace NewHorizons.Components.SizeControllers
|
||||
|
||||
if (_stellarRemnant != null && Time.time > _supernovaStartTime + 15)
|
||||
{
|
||||
_stellarRemnant.SetActive(true);
|
||||
var remnantStarController = _stellarRemnant.GetComponentInChildren<StarController>();
|
||||
if (remnantStarController != null) SunLightEffectsController.AddStar(remnantStarController);
|
||||
var remnantStarLight = _stellarRemnant.FindChild("StarLight");
|
||||
if (remnantStarLight != null) SunLightEffectsController.AddStarLight(remnantStarLight.GetComponent<Light>());
|
||||
EnableRemnant();
|
||||
}
|
||||
|
||||
if (Time.time > _supernovaStartTime + supernovaTime)
|
||||
@ -307,6 +352,21 @@ namespace NewHorizons.Components.SizeControllers
|
||||
}
|
||||
}
|
||||
|
||||
public void EnableRemnant()
|
||||
{
|
||||
_stellarRemnant.SetActive(true);
|
||||
var remnantStarController = _stellarRemnant.GetComponentInChildren<StarController>();
|
||||
if (remnantStarController != null)
|
||||
{
|
||||
SunLightEffectsController.AddStar(remnantStarController);
|
||||
}
|
||||
var remnantStarLight = _stellarRemnant.FindChild("StarLight");
|
||||
if (remnantStarLight != null)
|
||||
{
|
||||
SunLightEffectsController.AddStarLight(remnantStarLight.GetComponent<Light>());
|
||||
}
|
||||
}
|
||||
|
||||
private void DisableStar(bool start = false)
|
||||
{
|
||||
if (controller != null) SunLightEffectsController.RemoveStar(controller);
|
||||
@ -343,7 +403,9 @@ namespace NewHorizons.Components.SizeControllers
|
||||
{
|
||||
// Vanish anything unrelated to player
|
||||
if (!(rb.CompareTag("Player") || rb.CompareTag("Ship") || rb.CompareTag("ShipCockpit") || rb.CompareTag("Probe")))
|
||||
{
|
||||
planetDestructionVolume.Vanish(body, new RelativeLocationData(body, _rigidbody, planetDestructionVolume.transform));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -363,7 +425,16 @@ namespace NewHorizons.Components.SizeControllers
|
||||
_collapseStartSize = CurrentScale;
|
||||
_collapseTimer = 0f;
|
||||
_surface._materials[0].CopyPropertiesFromMaterial(_collapseStartSurfaceMaterial);
|
||||
if (oneShotSource != null && !PlayerState.IsSleepingAtCampfire() && !PlayerState.InDreamWorld()) oneShotSource.PlayOneShot(AudioType.Sun_Collapse);
|
||||
|
||||
if (deathType == StellarDeathType.PlanetaryNebula)
|
||||
{
|
||||
EnableRemnant();
|
||||
}
|
||||
|
||||
if (oneShotSource != null && !PlayerState.IsSleepingAtCampfire() && !PlayerState.InDreamWorld())
|
||||
{
|
||||
oneShotSource.PlayOneShot(AudioType.Sun_Collapse);
|
||||
}
|
||||
|
||||
_proxy?.StartCollapse();
|
||||
}
|
||||
|
||||
@ -29,7 +29,9 @@ namespace NewHorizons.Components.Stars
|
||||
{
|
||||
_cachedParticleRenderers = new ParticleSystemRenderer[explosionParticles.Length];
|
||||
for (int index = 0; index < explosionParticles.Length; ++index)
|
||||
{
|
||||
_cachedParticleRenderers[index] = explosionParticles[index].GetComponent<ParticleSystemRenderer>();
|
||||
}
|
||||
}
|
||||
|
||||
public void Activate()
|
||||
@ -51,7 +53,10 @@ namespace NewHorizons.Components.Stars
|
||||
_time = 0.0f;
|
||||
_currentSupernovaScale = supernovaScale.Evaluate(0.0f);
|
||||
_localSupernovaMat = new Material(supernovaMaterial);
|
||||
surface.sharedMaterial = _localSupernovaMat;
|
||||
if (surface != null)
|
||||
{
|
||||
surface.sharedMaterial = _localSupernovaMat;
|
||||
}
|
||||
|
||||
if (audioSource == null) return;
|
||||
|
||||
@ -80,7 +85,10 @@ namespace NewHorizons.Components.Stars
|
||||
shockwave.transform.localScale = Vector3.one * shockwaveScale.Evaluate(shockwaveTime);
|
||||
shockwave.material.color = Color.Lerp(Color.black, shockwave.sharedMaterial.color, shockwaveAlpha.Evaluate(shockwaveTime));
|
||||
_currentSupernovaScale = supernovaScale.Evaluate(_time);
|
||||
surface.transform.localScale = Vector3.one * _currentSupernovaScale;
|
||||
if (surface != null)
|
||||
{
|
||||
surface.transform.localScale = Vector3.one * _currentSupernovaScale;
|
||||
}
|
||||
_localSupernovaMat.color = Color.Lerp(Color.black, supernovaMaterial.color, supernovaAlpha.Evaluate(_time));
|
||||
|
||||
float distanceToPlayer = PlayerState.InDreamWorld() ? 20000f : Vector3.Distance(transform.position, Locator.GetPlayerCamera().transform.position) - GetSupernovaRadius();
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user