From 34cc923a5f44602d0ddc547f58b99ef60847cba3 Mon Sep 17 00:00:00 2001 From: Nick Date: Tue, 17 May 2022 17:29:38 -0400 Subject: [PATCH] Allow setting supernova colour --- .../AssetBundle/Effects_SUN_Supernova_d.png | Bin 0 -> 180 bytes NewHorizons/Builder/Body/ProxyBuilder.cs | 4 -- NewHorizons/Builder/Body/StarBuilder.cs | 48 +++++++++++++----- NewHorizons/Components/NHProxy.cs | 43 ++++++++++++++-- .../StarEvolutionController.cs | 34 ++++++++----- .../External/VariableSize/StarModule.cs | 2 + NewHorizons/schema.json | 5 ++ 7 files changed, 104 insertions(+), 32 deletions(-) create mode 100644 NewHorizons/AssetBundle/Effects_SUN_Supernova_d.png diff --git a/NewHorizons/AssetBundle/Effects_SUN_Supernova_d.png b/NewHorizons/AssetBundle/Effects_SUN_Supernova_d.png new file mode 100644 index 0000000000000000000000000000000000000000..ca8c4066aeb3d4c876edb3e12e942dec5ea31255 GIT binary patch literal 180 zcmeAS@N?(olHy`uVBq!ia0vp^j6m$b!2~2jio3)?0>we@P7LeL$-D$|SkfJR9T^xl z_H+M9WCij$3p^r=85sBugD~Uq{1qucK~GN?#}J9|+TL!?0}dR{TLaTe|8sgVHR)bw zJJkK?_^#hZo7?aH-ERKVrAsECal*}hj+v!tT9ZSU`n;P}`D};ro$~!h>fc97?qC#f WV@~|@D?AlwD1)b~pUXO@geCy@TswyV literal 0 HcmV?d00001 diff --git a/NewHorizons/Builder/Body/ProxyBuilder.cs b/NewHorizons/Builder/Body/ProxyBuilder.cs index 52e39c11..efa52115 100644 --- a/NewHorizons/Builder/Body/ProxyBuilder.cs +++ b/NewHorizons/Builder/Body/ProxyBuilder.cs @@ -59,8 +59,6 @@ namespace NewHorizons.Builder.Body { 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 (realSize < body.Config.Star.Size) realSize = body.Config.Star.Size; } if (body.Config.ProcGen != null) @@ -135,8 +133,6 @@ namespace NewHorizons.Builder.Body var proxyController = newProxy.AddComponent(); proxyController.astroName = body.Config.Name; proxyController._realObjectDiameter = realSize; - proxyController.renderers = newProxy.GetComponentsInChildren(); - proxyController.tessellatedRenderers = newProxy.GetComponentsInChildren(); } catch (Exception ex) { diff --git a/NewHorizons/Builder/Body/StarBuilder.cs b/NewHorizons/Builder/Body/StarBuilder.cs index cdbca3a9..f2f3bbfe 100644 --- a/NewHorizons/Builder/Body/StarBuilder.cs +++ b/NewHorizons/Builder/Body/StarBuilder.cs @@ -38,16 +38,18 @@ namespace NewHorizons.Builder.Body { sunAtmosphere = GameObject.Instantiate(GameObject.Find("Sun_Body/Atmosphere_SUN"), starGO.transform); sunAtmosphere.transform.position = planetGO.transform.position; - sunAtmosphere.transform.localScale = Vector3.one; + sunAtmosphere.transform.localScale = Vector3.one * OuterRadiusRatio; sunAtmosphere.name = "Atmosphere_Star"; PlanetaryFogController fog = sunAtmosphere.transform.Find("FogSphere").GetComponent(); if (starModule.Tint != null) { fog.fogTint = starModule.Tint.ToColor(); - sunAtmosphere.transform.Find("AtmoSphere").transform.localScale = Vector3.one * (starModule.Size * OuterRadiusRatio); + sunAtmosphere.transform.Find("AtmoSphere").transform.localScale = Vector3.one; foreach (var lod in sunAtmosphere.transform.Find("AtmoSphere").GetComponentsInChildren()) { lod.material.SetColor("_SkyColor", starModule.Tint.ToColor()); + lod.material.SetColor("_AtmosFar", starModule.Tint.ToColor()); + lod.material.SetColor("_AtmosNear", starModule.Tint.ToColor()); lod.material.SetFloat("_InnerRadius", starModule.Size); lod.material.SetFloat("_OuterRadius", starModule.Size * OuterRadiusRatio); } @@ -72,7 +74,7 @@ namespace NewHorizons.Builder.Body deathVolume.transform.localScale = Vector3.one; deathVolume.GetComponent().radius = 1f; deathVolume.GetComponent()._onlyAffectsPlayerAndShip = false; - deathVolume.GetComponent()._shrinkBodies = false; + deathVolume.GetComponent()._shrinkBodies = true; deathVolume.name = "DestructionVolume"; Light ambientLight = ambientLightGO.GetComponent(); @@ -125,7 +127,7 @@ namespace NewHorizons.Builder.Body starController.SunColor = lightColour; } - var supernova = MakeSupernova(starGO); + var supernova = MakeSupernova(starGO, starModule); var controller = starGO.AddComponent(); if(starModule.Curve != null) controller.scaleCurve = starModule.ToAnimationCurve(); @@ -133,25 +135,33 @@ namespace NewHorizons.Builder.Body controller.atmosphere = sunAtmosphere; controller.supernova = supernova; controller.startColour = starModule.Tint; - controller.startColour = starModule.EndTint; + controller.endColour = starModule.EndTint; + controller.willExplode = starModule.GoSupernova; + + // It fucking insists on this existing and its really annoying + var supernovaVolume = new GameObject("SupernovaVolumePlaceholder"); + supernovaVolume.transform.SetParent(starGO.transform); + supernova._supernovaVolume = supernovaVolume.AddComponent(); + var sphere = supernovaVolume.AddComponent(); + sphere.radius = 0f; + supernovaVolume.AddComponent(); return starController; } public static GameObject MakeStarProxy(GameObject planet, GameObject proxyGO, StarModule starModule) { - var starGO = new GameObject("Star"); - starGO.transform.parent = proxyGO.transform; - starGO.transform.localPosition = Vector3.zero; + var starGO = MakeStarGraphics(proxyGO, null, starModule); - MakeStarGraphics(proxyGO, null, starModule); - - var supernova = MakeSupernova(starGO); + var supernova = MakeSupernova(starGO, starModule); var controller = starGO.AddComponent(); if (starModule.Curve != null) controller.scaleCurve = starModule.ToAnimationCurve(); controller.size = starModule.Size; controller.supernova = supernova; + controller.startColour = starModule.Tint; + controller.endColour = starModule.EndTint; + controller.enabled = true; planet.GetComponentInChildren().SetProxy(controller); @@ -206,7 +216,7 @@ namespace NewHorizons.Builder.Body return starGO; } - public static SupernovaEffectController MakeSupernova(GameObject starGO) + private static SupernovaEffectController MakeSupernova(GameObject starGO, StarModule starModule) { var supernovaGO = GameObject.Find("Sun_Body/Sector_SUN/Effects_SUN/Supernova").InstantiateInactive(); supernovaGO.transform.SetParent(starGO.transform); @@ -216,6 +226,20 @@ namespace NewHorizons.Builder.Body supernova._surface = starGO.GetComponentInChildren(); supernova._supernovaVolume = null; + if(starModule.SupernovaTint != null) + { + var colour = starModule.SupernovaTint.ToColor(); + + var supernovaMaterial = new Material(supernova._supernovaMaterial); + var ramp = ImageUtilities.LerpGreyscaleImage(ImageUtilities.GetTexture(Main.Instance, "AssetBundle/Effects_SUN_Supernova_d.png"), Color.white, colour); + supernovaMaterial.SetTexture("_ColorRamp", ramp); + supernova._supernovaMaterial = supernovaMaterial; + + // Motes + var moteMaterial = supernova.GetComponentInChildren().material; + moteMaterial.color = new Color(colour.r * 3f, colour.g * 3f, colour.b * 3f, moteMaterial.color.a); + } + supernovaGO.SetActive(true); return supernova; diff --git a/NewHorizons/Components/NHProxy.cs b/NewHorizons/Components/NHProxy.cs index f71d3b25..249b0ea1 100644 --- a/NewHorizons/Components/NHProxy.cs +++ b/NewHorizons/Components/NHProxy.cs @@ -1,4 +1,5 @@ -using NewHorizons.Utility; +using NewHorizons.Components.SizeControllers; +using NewHorizons.Utility; using System.Collections.Generic; using UnityEngine; @@ -7,8 +8,29 @@ namespace NewHorizons.Components public class NHProxy : ProxyPlanet { public string astroName; - public Renderer[] renderers; - public TessellatedRenderer[] tessellatedRenderers; + + private GameObject _star; + private Renderer[] _starRenderers; + private TessellatedRenderer[] _starTessellatedRenderers; + + public override void Awake() + { + base.Awake(); + + // The star part cant be disabled like the rest and we have to manually disable the renderers + // Else it can stop the supernova effect mid way through + _star = GetComponentInChildren()?.gameObject; + + if(_star != null) + { + _starRenderers = _star.GetComponentsInChildren(); + _starTessellatedRenderers = _star.GetComponentsInChildren(); + } + + // Start off + _outOfRange = false; + ToggleRendering(false); + } public override void Initialize() { @@ -34,10 +56,25 @@ namespace NewHorizons.Components public override void ToggleRendering(bool on) { base.ToggleRendering(on); + foreach (Transform child in transform) { + if (child.gameObject == _star) continue; child.gameObject.SetActive(on); } + + if(_star != null) + { + foreach (var renderer in _starRenderers) + { + renderer.enabled = on; + } + + foreach (var renderer in _starTessellatedRenderers) + { + renderer.enabled = on; + } + } } } } \ No newline at end of file diff --git a/NewHorizons/Components/SizeControllers/StarEvolutionController.cs b/NewHorizons/Components/SizeControllers/StarEvolutionController.cs index e59e9480..6a0b7b1c 100644 --- a/NewHorizons/Components/SizeControllers/StarEvolutionController.cs +++ b/NewHorizons/Components/SizeControllers/StarEvolutionController.cs @@ -13,9 +13,10 @@ namespace NewHorizons.Components.SizeControllers { public GameObject atmosphere; public SupernovaEffectController supernova; + public bool willExplode; - public MColor startColour; - public MColor endColour; + public MColor startColour { get; set; } + public MColor endColour { get; set; } private Color _startColour; private Color _endColour; @@ -69,7 +70,8 @@ namespace NewHorizons.Components.SizeControllers if (endColour == null) { - _endColour = _endSurfaceMaterial.color; + _endColour = _startColour; + _endSurfaceMaterial.color = _startColour; } else { @@ -77,22 +79,21 @@ namespace NewHorizons.Components.SizeControllers _endSurfaceMaterial.color = _endColour; } - _heatVolume = GetComponentInChildren(); _destructionVolume = GetComponentInChildren(); if (atmosphere != null) { - _fog = atmosphere.GetComponentInChildren(); - _atmosphereRenderers = atmosphere.transform.Find("AtmoSphere").GetComponentsInChildren(); + _fog = atmosphere?.GetComponentInChildren(); + _atmosphereRenderers = atmosphere?.transform?.Find("AtmoSphere")?.GetComponentsInChildren(); } - GlobalMessenger.AddListener("TriggerSupernova", Die); + if (willExplode) GlobalMessenger.AddListener("TriggerSupernova", Die); } public void OnDestroy() { - GlobalMessenger.RemoveListener("TriggerSupernova", Die); + if (willExplode) GlobalMessenger.RemoveListener("TriggerSupernova", Die); } public void SetProxy(StarEvolutionController proxy) @@ -124,8 +125,8 @@ namespace NewHorizons.Components.SizeControllers 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 (_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) { @@ -173,17 +174,24 @@ namespace NewHorizons.Components.SizeControllers if (_fog != null) { _fog.fogRadius = CurrentScale * StarBuilder.OuterRadiusRatio; - _fog.lodFadeDistance = CurrentScale * (StarBuilder.OuterRadiusRatio - 1f); + _fog.lodFadeDistance = CurrentScale * StarBuilder.OuterRadiusRatio / 3f; - _fog.fogTint = currentColour; + // The colour thing goes over one + 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; } - if (_atmosphereRenderers.Count() > 0) + if (_atmosphereRenderers != null && _atmosphereRenderers.Count() > 0) { foreach (var lod in _atmosphereRenderers) { 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); } } diff --git a/NewHorizons/External/VariableSize/StarModule.cs b/NewHorizons/External/VariableSize/StarModule.cs index 1f3ee87a..2bec97b2 100644 --- a/NewHorizons/External/VariableSize/StarModule.cs +++ b/NewHorizons/External/VariableSize/StarModule.cs @@ -12,9 +12,11 @@ namespace NewHorizons.External.VariableSize public float Size { get; set; } = 2000f; public MColor Tint { get; set; } public MColor EndTint { get; set; } + public MColor SupernovaTint { get; set; } public MColor SolarFlareTint { get; set; } public MColor LightTint { get; set; } public float SolarLuminosity { get; set; } = 1f; public bool HasAtmosphere { get; set; } = true; + public bool GoSupernova { get; set; } = true; } } diff --git a/NewHorizons/schema.json b/NewHorizons/schema.json index 1a9db790..e5d551b0 100644 --- a/NewHorizons/schema.json +++ b/NewHorizons/schema.json @@ -622,6 +622,11 @@ "curve": { "$ref": "#/$defs/curve", "description": "Allows the star to shrink/grow over time." + }, + "goSupernova": { + "type": "boolean", + "default": true, + "description": "Should this star explode after 22 minutes?" } } },