Supernovas work locally

Proxies are broken
Star atmospheres are broken
This commit is contained in:
Nick 2022-05-16 18:41:03 -04:00
parent fb13d5607e
commit ebe8bd9c1c
5 changed files with 119 additions and 24 deletions

View File

@ -22,7 +22,7 @@ namespace NewHorizons.Builder.Body
private static readonly string _whiteHolePath = "TowerTwin_Body/Sector_TowerTwin/Sector_Tower_HGT/Interactables_Tower_HGT/Interactables_Tower_CT/Prefab_NOM_WarpTransmitter/WhiteHole/WhiteHoleSingularity"; private static readonly string _whiteHolePath = "TowerTwin_Body/Sector_TowerTwin/Sector_Tower_HGT/Interactables_Tower_HGT/Interactables_Tower_CT/Prefab_NOM_WarpTransmitter/WhiteHole/WhiteHoleSingularity";
public static void Make(GameObject gameObject, NewHorizonsBody body) public static void Make(GameObject planetGO, NewHorizonsBody body)
{ {
if (lavaMaterial == null) lavaMaterial = SearchUtilities.FindObjectOfTypeAndName<ProxyOrbiter>("VolcanicMoon_Body").transform.Find("LavaSphere").GetComponent<MeshRenderer>().material; if (lavaMaterial == null) lavaMaterial = SearchUtilities.FindObjectOfTypeAndName<ProxyOrbiter>("VolcanicMoon_Body").transform.Find("LavaSphere").GetComponent<MeshRenderer>().material;
@ -57,7 +57,7 @@ namespace NewHorizons.Builder.Body
} }
if (body.Config.Star != null) if (body.Config.Star != null)
{ {
var starGO = StarBuilder.MakeStarGraphics(newProxy, null, body.Config.Star); var starGO = StarBuilder.MakeStarProxy(planetGO, newProxy, body.Config.Star);
if (body.Config.Star.Curve != null) AddSizeController(starGO, body.Config.Star.Curve, body.Config.Star.Size); if (body.Config.Star.Curve != null) AddSizeController(starGO, body.Config.Star.Curve, body.Config.Star.Size);

View File

@ -36,7 +36,7 @@ namespace NewHorizons.Builder.Body
GameObject sunAtmosphere = null; GameObject sunAtmosphere = null;
if (starModule.HasAtmosphere) if (starModule.HasAtmosphere)
{ {
sunAtmosphere = GameObject.Instantiate(GameObject.Find("Sun_Body/Atmosphere_SUN"), planetGO.transform); sunAtmosphere = GameObject.Instantiate(GameObject.Find("Sun_Body/Atmosphere_SUN"), starGO.transform);
sunAtmosphere.transform.position = planetGO.transform.position; sunAtmosphere.transform.position = planetGO.transform.position;
sunAtmosphere.transform.localScale = Vector3.one; sunAtmosphere.transform.localScale = Vector3.one;
sunAtmosphere.name = "Atmosphere_Star"; sunAtmosphere.name = "Atmosphere_Star";
@ -132,22 +132,30 @@ namespace NewHorizons.Builder.Body
controller.size = starModule.Size; controller.size = starModule.Size;
controller.atmosphere = sunAtmosphere; controller.atmosphere = sunAtmosphere;
controller.supernova = supernova; controller.supernova = supernova;
controller.startColour = starModule.Tint;
controller.startColour = starModule.EndTint;
return starController; return starController;
} }
public static GameObject MakeStarProxy(GameObject planetGO, StarModule starModule) public static GameObject MakeStarProxy(GameObject planet, GameObject proxyGO, StarModule starModule)
{ {
MakeStarGraphics(planetGO, null, starModule); var starGO = new GameObject("Star");
starGO.transform.parent = proxyGO.transform;
starGO.transform.localPosition = Vector3.zero;
if (starModule.Curve != null) MakeStarGraphics(proxyGO, null, starModule);
{
var controller = planetGO.AddComponent<StarEvolutionController>();
controller.scaleCurve = starModule.ToAnimationCurve();
controller.size = starModule.Size;
}
return planetGO; var supernova = MakeSupernova(starGO);
var controller = starGO.AddComponent<StarEvolutionController>();
if (starModule.Curve != null) controller.scaleCurve = starModule.ToAnimationCurve();
controller.size = starModule.Size;
controller.supernova = supernova;
planet.GetComponentInChildren<StarEvolutionController>().SetProxy(controller);
return proxyGO;
} }
public static GameObject MakeStarGraphics(GameObject rootObject, Sector sector, StarModule starModule) public static GameObject MakeStarGraphics(GameObject rootObject, Sector sector, StarModule starModule)
@ -206,6 +214,7 @@ namespace NewHorizons.Builder.Body
var supernova = supernovaGO.GetComponent<SupernovaEffectController>(); var supernova = supernovaGO.GetComponent<SupernovaEffectController>();
supernova._surface = starGO.GetComponentInChildren<TessellatedSphereRenderer>(); supernova._surface = starGO.GetComponentInChildren<TessellatedSphereRenderer>();
supernova._supernovaVolume = null;
supernovaGO.SetActive(true); supernovaGO.SetActive(true);

View File

@ -1,4 +1,5 @@
using NewHorizons.Builder.Body; using NewHorizons.Builder.Body;
using NewHorizons.Utility;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
@ -13,32 +14,91 @@ namespace NewHorizons.Components.SizeControllers
public GameObject atmosphere; public GameObject atmosphere;
public SupernovaEffectController supernova; public SupernovaEffectController supernova;
public MColor startColour;
public MColor endColour;
private Color _startColour;
private Color _endColour;
private PlanetaryFogController _fog; private PlanetaryFogController _fog;
private MeshRenderer[] _atmosphereRenderers; private MeshRenderer[] _atmosphereRenderers;
private HeatHazardVolume _heatVolume;
private DestructionVolume _destructionVolume;
private bool _isCollapsing; private bool _isCollapsing;
private float _collapseStartSize; private float _collapseStartSize;
private float _collapseTimer; private float _collapseTimer;
public float collapseTime = 5f; public float collapseTime = 5f; // seconds
public float lifespan = 22f; // minutes
private float _age;
private bool _isSupernova; private bool _isSupernova;
private float _supernovaStartTime; private float _supernovaStartTime;
private Material _collapseStartSurfaceMaterial; private Material _collapseStartSurfaceMaterial;
private Material _collapseEndSurfaceMaterial; private Material _collapseEndSurfaceMaterial;
private Material _startSurfaceMaterial;
private Material _endSurfaceMaterial;
private StarEvolutionController _proxy;
void Awake() void Awake()
{ {
var sun = GameObject.FindObjectOfType<SunController>(); var sun = GameObject.FindObjectOfType<SunController>();
_collapseStartSurfaceMaterial = sun._collapseStartSurfaceMaterial; _collapseStartSurfaceMaterial = new Material(sun._collapseStartSurfaceMaterial);
_collapseEndSurfaceMaterial = sun._collapseEndSurfaceMaterial; _collapseEndSurfaceMaterial = new Material(sun._collapseEndSurfaceMaterial);
_startSurfaceMaterial = new Material(sun._startSurfaceMaterial);
_endSurfaceMaterial = new Material(sun._endSurfaceMaterial);
// Copy over the material that was set in star builder
_collapseStartSurfaceMaterial.SetTexture("_ColorRamp", supernova._surface.sharedMaterial.GetTexture("_ColorRamp"));
_collapseEndSurfaceMaterial.SetTexture("_ColorRamp", supernova._surface.sharedMaterial.GetTexture("_ColorRamp"));
_startSurfaceMaterial.SetTexture("_ColorRamp", supernova._surface.sharedMaterial.GetTexture("_ColorRamp"));
_endSurfaceMaterial.SetTexture("_ColorRamp", supernova._surface.sharedMaterial.GetTexture("_ColorRamp"));
if (startColour == null)
{
_startColour = _startSurfaceMaterial.color;
}
else
{
_startColour = startColour.ToColor();
_startSurfaceMaterial.color = _startColour;
}
if (endColour == null)
{
_endColour = _endSurfaceMaterial.color;
}
else
{
_endColour = endColour.ToColor();
_endSurfaceMaterial.color = _endColour;
}
_heatVolume = GetComponentInChildren<HeatHazardVolume>();
_destructionVolume = GetComponentInChildren<DestructionVolume>();
if (atmosphere != null) if (atmosphere != null)
{ {
_fog = atmosphere.GetComponentInChildren<PlanetaryFogController>(); _fog = atmosphere.GetComponentInChildren<PlanetaryFogController>();
_atmosphereRenderers = atmosphere.transform.Find("AtmoSphere").GetComponentsInChildren<MeshRenderer>(); _atmosphereRenderers = atmosphere.transform.Find("AtmoSphere").GetComponentsInChildren<MeshRenderer>();
} }
GlobalMessenger.AddListener("TriggerSupernova", Die);
}
public void OnDestroy()
{
GlobalMessenger.RemoveListener("TriggerSupernova", Die);
}
public void SetProxy(StarEvolutionController proxy)
{
_proxy = proxy;
_proxy.supernova.SetIsProxy(true);
} }
public void Die() public void Die()
@ -46,24 +106,44 @@ namespace NewHorizons.Components.SizeControllers
_isCollapsing = true; _isCollapsing = true;
_collapseStartSize = CurrentScale; _collapseStartSize = CurrentScale;
_collapseTimer = 0f; _collapseTimer = 0f;
if (_proxy != null) _proxy.Die();
} }
protected new void FixedUpdate() protected new void FixedUpdate()
{ {
// If we've gone supernova and its been 60 seconds that means it has faded out and is gone _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) if (_isSupernova)
{ {
// Reset the scale back to normal bc now its just the supernova scaling itself + destruction and heat volumes
transform.localScale = Vector3.one; transform.localScale = Vector3.one;
if (Time.time > _supernovaStartTime + 60f)
// 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); base.gameObject.SetActive(false);
} }
return; return;
} }
Color currentColour;
if (!_isCollapsing) if (!_isCollapsing)
{ {
base.FixedUpdate(); base.FixedUpdate();
currentColour = Color.Lerp(_startColour, _endColour, ageValue);
supernova._surface._materials[0].Lerp(_startSurfaceMaterial, _endSurfaceMaterial, ageValue);
} }
else else
{ {
@ -73,7 +153,9 @@ namespace NewHorizons.Components.SizeControllers
transform.localScale = Vector3.one * CurrentScale; transform.localScale = Vector3.one * CurrentScale;
_collapseTimer += Time.deltaTime; _collapseTimer += Time.deltaTime;
supernova._surface._materials[0].Lerp(this._collapseStartSurfaceMaterial, this._collapseEndSurfaceMaterial, t); currentColour = Color.Lerp(_endColour, Color.white, t);
supernova._surface._materials[0].Lerp(_collapseStartSurfaceMaterial, _collapseEndSurfaceMaterial, t);
// After the collapse is done we go supernova // After the collapse is done we go supernova
if (_collapseTimer > collapseTime) if (_collapseTimer > collapseTime)
@ -82,20 +164,18 @@ namespace NewHorizons.Components.SizeControllers
_isSupernova = true; _isSupernova = true;
_supernovaStartTime = Time.time; _supernovaStartTime = Time.time;
atmosphere.SetActive(false); atmosphere.SetActive(false);
_destructionVolume._deathType = DeathType.Supernova;
return; return;
} }
} }
// This is just all the scales stuff for the atmosphere effects // This is just all the scales stuff for the atmosphere effects
if (atmosphere != null)
{
atmosphere.transform.localScale = CurrentScale * Vector3.one;
}
if (_fog != null) if (_fog != null)
{ {
_fog.fogRadius = CurrentScale * StarBuilder.OuterRadiusRatio; _fog.fogRadius = CurrentScale * StarBuilder.OuterRadiusRatio;
_fog.lodFadeDistance = CurrentScale * (StarBuilder.OuterRadiusRatio - 1f); _fog.lodFadeDistance = CurrentScale * (StarBuilder.OuterRadiusRatio - 1f);
_fog.fogTint = currentColour;
} }
if (_atmosphereRenderers.Count() > 0) if (_atmosphereRenderers.Count() > 0)
@ -104,6 +184,7 @@ namespace NewHorizons.Components.SizeControllers
{ {
lod.material.SetFloat("_InnerRadius", CurrentScale); lod.material.SetFloat("_InnerRadius", CurrentScale);
lod.material.SetFloat("_OuterRadius", CurrentScale * StarBuilder.OuterRadiusRatio); lod.material.SetFloat("_OuterRadius", CurrentScale * StarBuilder.OuterRadiusRatio);
lod.material.SetColor("_SkyColor", currentColour);
} }
} }
} }

View File

@ -11,6 +11,7 @@ namespace NewHorizons.External.VariableSize
{ {
public float Size { get; set; } = 2000f; public float Size { get; set; } = 2000f;
public MColor Tint { get; set; } public MColor Tint { get; set; }
public MColor EndTint { get; set; }
public MColor SolarFlareTint { get; set; } public MColor SolarFlareTint { get; set; }
public MColor LightTint { get; set; } public MColor LightTint { get; set; }
public float SolarLuminosity { get; set; } = 1f; public float SolarLuminosity { get; set; } = 1f;

View File

@ -596,6 +596,10 @@
"$ref": "#/$defs/color", "$ref": "#/$defs/color",
"description": "Colour of the star." "description": "Colour of the star."
}, },
"endTint": {
"$ref": "#/$defs/color",
"description": "Colour of the star at the end of its life."
},
"solarFlareTint": { "solarFlareTint": {
"$ref": "#/$defs/color", "$ref": "#/$defs/color",
"description": "Colour of the solar flares. The shader is a bit weird so the value you put won't exactly reflect what you see. Try experimenting with different colours to see what works." "description": "Colour of the solar flares. The shader is a bit weird so the value you put won't exactly reflect what you see. Try experimenting with different colours to see what works."