From c58bcb36b0835a1d8c254cf202d21efb5823aba8 Mon Sep 17 00:00:00 2001 From: Nick Date: Sun, 15 May 2022 02:34:46 -0400 Subject: [PATCH 1/8] Set up star evolution controller --- NewHorizons/Builder/Body/StarBuilder.cs | 54 ++++++--- .../SizeControllers/SizeController.cs | 2 +- .../StarAtmosphereSizeController.cs | 35 ------ .../StarEvolutionController.cs | 111 ++++++++++++++++++ .../VariableSize/VariableSizeModule.cs | 7 +- 5 files changed, 154 insertions(+), 55 deletions(-) delete mode 100644 NewHorizons/Components/SizeControllers/StarAtmosphereSizeController.cs create mode 100644 NewHorizons/Components/SizeControllers/StarEvolutionController.cs diff --git a/NewHorizons/Builder/Body/StarBuilder.cs b/NewHorizons/Builder/Body/StarBuilder.cs index bd10bd3a..e5e731bb 100644 --- a/NewHorizons/Builder/Body/StarBuilder.cs +++ b/NewHorizons/Builder/Body/StarBuilder.cs @@ -33,9 +33,10 @@ namespace NewHorizons.Builder.Body sunAudio.name = "Audio_Star"; + GameObject sunAtmosphere = null; if (starModule.HasAtmosphere) { - var sunAtmosphere = GameObject.Instantiate(GameObject.Find("Sun_Body/Atmosphere_SUN"), planetGO.transform); + sunAtmosphere = GameObject.Instantiate(GameObject.Find("Sun_Body/Atmosphere_SUN"), planetGO.transform); sunAtmosphere.transform.position = planetGO.transform.position; sunAtmosphere.transform.localScale = Vector3.one; sunAtmosphere.name = "Atmosphere_Star"; @@ -54,12 +55,6 @@ namespace NewHorizons.Builder.Body fog.transform.localScale = Vector3.one; fog.fogRadius = starModule.Size * OuterRadiusRatio; fog.lodFadeDistance = fog.fogRadius * (StarBuilder.OuterRadiusRatio - 1f); - if (starModule.Curve != null) - { - var controller = sunAtmosphere.AddComponent(); - controller.scaleCurve = starModule.ToAnimationCurve(); - controller.initialSize = starModule.Size; - } } var ambientLightGO = GameObject.Instantiate(GameObject.Find("Sun_Body/AmbientLight_SUN"), starGO.transform); @@ -130,20 +125,31 @@ namespace NewHorizons.Builder.Body starController.SunColor = lightColour; } - if (starModule.Curve != null) - { - var levelController = starGO.AddComponent(); - var curve = new AnimationCurve(); - foreach (var pair in starModule.Curve) - { - curve.AddKey(new Keyframe(pair.Time, starModule.Size * pair.Value)); - } - levelController._scaleCurve = curve; - } + var supernova = MakeSupernova(starGO); + + var controller = starGO.AddComponent(); + if(starModule.Curve != null) controller.scaleCurve = starModule.ToAnimationCurve(); + controller.size = starModule.Size; + controller.atmosphere = sunAtmosphere; + controller.supernova = supernova; return starController; } + public static GameObject MakeStarProxy(GameObject planetGO, StarModule starModule) + { + MakeStarGraphics(planetGO, null, starModule); + + if (starModule.Curve != null) + { + var controller = planetGO.AddComponent(); + controller.scaleCurve = starModule.ToAnimationCurve(); + controller.size = starModule.Size; + } + + return planetGO; + } + public static GameObject MakeStarGraphics(GameObject rootObject, Sector sector, StarModule starModule) { if (_colorOverTime == null) _colorOverTime = ImageUtilities.GetTexture(Main.Instance, "AssetBundle/StarColorOverTime.png"); @@ -191,5 +197,19 @@ namespace NewHorizons.Builder.Body return starGO; } + + public static SupernovaEffectController MakeSupernova(GameObject starGO) + { + var supernovaGO = GameObject.Find("Sun_Body/Sector_SUN/Effects_SUN/Supernova").InstantiateInactive(); + supernovaGO.transform.SetParent(starGO.transform); + supernovaGO.transform.localPosition = Vector3.zero; + + var supernova = supernovaGO.GetComponent(); + supernova._surface = starGO.GetComponentInChildren(); + + supernovaGO.SetActive(true); + + return supernova; + } } } diff --git a/NewHorizons/Components/SizeControllers/SizeController.cs b/NewHorizons/Components/SizeControllers/SizeController.cs index 4a071a2f..35fbeee7 100644 --- a/NewHorizons/Components/SizeControllers/SizeController.cs +++ b/NewHorizons/Components/SizeControllers/SizeController.cs @@ -10,7 +10,7 @@ namespace NewHorizons.Components.SizeControllers public class SizeController : MonoBehaviour { public AnimationCurve scaleCurve; - public float CurrentScale { get; private set; } + public float CurrentScale { get; protected set; } public float size = 1f; protected void FixedUpdate() diff --git a/NewHorizons/Components/SizeControllers/StarAtmosphereSizeController.cs b/NewHorizons/Components/SizeControllers/StarAtmosphereSizeController.cs deleted file mode 100644 index be295f0b..00000000 --- a/NewHorizons/Components/SizeControllers/StarAtmosphereSizeController.cs +++ /dev/null @@ -1,35 +0,0 @@ -using NewHorizons.Builder.Body; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using UnityEngine; - -namespace NewHorizons.Components.SizeControllers -{ - public class StarAtmosphereSizeController : SizeController - { - private PlanetaryFogController fog; - public float initialSize; - private MeshRenderer[] atmosphereRenderers; - - void Awake() - { - fog = GetComponentInChildren(); - atmosphereRenderers = transform.Find("AtmoSphere").GetComponentsInChildren(); - } - - protected new void FixedUpdate() - { - base.FixedUpdate(); - fog.fogRadius = initialSize * CurrentScale * StarBuilder.OuterRadiusRatio; - fog.lodFadeDistance = initialSize * CurrentScale * (StarBuilder.OuterRadiusRatio - 1f); - foreach (var lod in atmosphereRenderers) - { - lod.material.SetFloat("_InnerRadius", initialSize * CurrentScale); - lod.material.SetFloat("_OuterRadius", initialSize * CurrentScale * StarBuilder.OuterRadiusRatio); - } - } - } -} diff --git a/NewHorizons/Components/SizeControllers/StarEvolutionController.cs b/NewHorizons/Components/SizeControllers/StarEvolutionController.cs new file mode 100644 index 00000000..07a86bb0 --- /dev/null +++ b/NewHorizons/Components/SizeControllers/StarEvolutionController.cs @@ -0,0 +1,111 @@ +using NewHorizons.Builder.Body; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using UnityEngine; + +namespace NewHorizons.Components.SizeControllers +{ + public class StarEvolutionController : SizeController + { + public GameObject atmosphere; + public SupernovaEffectController supernova; + + private PlanetaryFogController _fog; + private MeshRenderer[] _atmosphereRenderers; + + private bool _isCollapsing; + private float _collapseStartSize; + private float _collapseTimer; + + public float collapseTime = 5f; + + private bool _isSupernova; + private float _supernovaStartTime; + + private Material _collapseStartSurfaceMaterial; + private Material _collapseEndSurfaceMaterial; + + void Awake() + { + var sun = GameObject.FindObjectOfType(); + _collapseStartSurfaceMaterial = sun._collapseStartSurfaceMaterial; + _collapseEndSurfaceMaterial = sun._collapseEndSurfaceMaterial; + + if (atmosphere != null) + { + _fog = atmosphere.GetComponentInChildren(); + _atmosphereRenderers = atmosphere.transform.Find("AtmoSphere").GetComponentsInChildren(); + } + } + + public void Die() + { + _isCollapsing = true; + _collapseStartSize = CurrentScale; + _collapseTimer = 0f; + } + + protected new void FixedUpdate() + { + // If we've gone supernova and its been 30 seconds that means it has faded out and is gone + if (_isSupernova) + { + transform.localScale = Vector3.one; + if (Time.time > _supernovaStartTime + 30f) + { + base.gameObject.SetActive(false); + } + return; + } + + if (!_isCollapsing) + { + base.FixedUpdate(); + } + 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; + + supernova._surface._materials[0].Lerp(this._collapseStartSurfaceMaterial, this._collapseEndSurfaceMaterial, t); + + // After the collapse is done we go supernova + if (_collapseTimer > collapseTime) + { + supernova.enabled = true; + _isSupernova = true; + _supernovaStartTime = Time.time; + atmosphere.SetActive(false); + return; + } + } + + // This is just all the scales stuff for the atmosphere effects + if (atmosphere != null) + { + atmosphere.transform.localScale = CurrentScale * Vector3.one; + } + + if (_fog != null) + { + _fog.fogRadius = CurrentScale * StarBuilder.OuterRadiusRatio; + _fog.lodFadeDistance = CurrentScale * (StarBuilder.OuterRadiusRatio - 1f); + } + + if (_atmosphereRenderers.Count() > 0) + { + foreach (var lod in _atmosphereRenderers) + { + lod.material.SetFloat("_InnerRadius", CurrentScale); + lod.material.SetFloat("_OuterRadius", CurrentScale * StarBuilder.OuterRadiusRatio); + } + } + } + } +} diff --git a/NewHorizons/External/VariableSize/VariableSizeModule.cs b/NewHorizons/External/VariableSize/VariableSizeModule.cs index 1901c7c8..5fd02def 100644 --- a/NewHorizons/External/VariableSize/VariableSizeModule.cs +++ b/NewHorizons/External/VariableSize/VariableSizeModule.cs @@ -20,9 +20,12 @@ namespace NewHorizons.External.VariableSize public AnimationCurve ToAnimationCurve(float size = 1f) { var curve = new AnimationCurve(); - foreach (var pair in this.Curve) + if(Curve != null) { - curve.AddKey(new Keyframe(pair.Time, size * pair.Value)); + foreach (var pair in this.Curve) + { + curve.AddKey(new Keyframe(pair.Time, size * pair.Value)); + } } return curve; } From fcad6d8b65d5c3c782b2eb48f1db64e12a6af004 Mon Sep 17 00:00:00 2001 From: Nick Date: Sun, 15 May 2022 02:38:55 -0400 Subject: [PATCH 2/8] Increase supernova time from 30s to 60s --- .../Components/SizeControllers/StarEvolutionController.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/NewHorizons/Components/SizeControllers/StarEvolutionController.cs b/NewHorizons/Components/SizeControllers/StarEvolutionController.cs index 07a86bb0..58953a9f 100644 --- a/NewHorizons/Components/SizeControllers/StarEvolutionController.cs +++ b/NewHorizons/Components/SizeControllers/StarEvolutionController.cs @@ -50,11 +50,11 @@ namespace NewHorizons.Components.SizeControllers protected new void FixedUpdate() { - // If we've gone supernova and its been 30 seconds that means it has faded out and is gone + // If we've gone supernova and its been 60 seconds that means it has faded out and is gone if (_isSupernova) { transform.localScale = Vector3.one; - if (Time.time > _supernovaStartTime + 30f) + if (Time.time > _supernovaStartTime + 60f) { base.gameObject.SetActive(false); } From e89e4aa95db4b60ced5a692f71c4aa908fd2e464 Mon Sep 17 00:00:00 2001 From: Nick Date: Sun, 15 May 2022 02:39:06 -0400 Subject: [PATCH 3/8] Check if scaleCurve is null --- .../Components/SizeControllers/SizeController.cs | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/NewHorizons/Components/SizeControllers/SizeController.cs b/NewHorizons/Components/SizeControllers/SizeController.cs index 35fbeee7..f2b902b4 100644 --- a/NewHorizons/Components/SizeControllers/SizeController.cs +++ b/NewHorizons/Components/SizeControllers/SizeController.cs @@ -15,8 +15,16 @@ namespace NewHorizons.Components.SizeControllers protected void FixedUpdate() { - CurrentScale = scaleCurve.Evaluate(TimeLoop.GetMinutesElapsed()) * size; - base.transform.localScale = new Vector3(CurrentScale, CurrentScale, CurrentScale); + if(scaleCurve != null) + { + CurrentScale = scaleCurve.Evaluate(TimeLoop.GetMinutesElapsed()) * size; + } + else + { + CurrentScale = size; + } + + base.transform.localScale = Vector3.one * CurrentScale; } } } From 7594265835c7b828116b3ff144cebc72002a028b Mon Sep 17 00:00:00 2001 From: Nick Date: Sun, 15 May 2022 21:52:52 -0400 Subject: [PATCH 4/8] Prevent map mode from breaking if image is null --- NewHorizons/Builder/Orbital/FocalPointBuilder.cs | 2 +- NewHorizons/Builder/ShipLog/MapModeBuilder.cs | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/NewHorizons/Builder/Orbital/FocalPointBuilder.cs b/NewHorizons/Builder/Orbital/FocalPointBuilder.cs index 0a8f0c90..ec59ffe4 100644 --- a/NewHorizons/Builder/Orbital/FocalPointBuilder.cs +++ b/NewHorizons/Builder/Orbital/FocalPointBuilder.cs @@ -73,7 +73,7 @@ namespace NewHorizons.Builder.Orbital binary.FakeMassBody = PlanetCreationHandler.GenerateBody(new NewHorizonsBody(fakeMassConfig, mod)); } - + private static float GetGravitationalMass(IPlanetConfig config) { var surfaceAcceleration = config.Base.SurfaceGravity; diff --git a/NewHorizons/Builder/ShipLog/MapModeBuilder.cs b/NewHorizons/Builder/ShipLog/MapModeBuilder.cs index 8563b632..22f03535 100644 --- a/NewHorizons/Builder/ShipLog/MapModeBuilder.cs +++ b/NewHorizons/Builder/ShipLog/MapModeBuilder.cs @@ -107,17 +107,17 @@ namespace NewHorizons.Builder.ShipLog ShipLogAstroObject astroObject = gameObject.AddComponent(); astroObject._id = ShipLogHandler.GetAstroObjectId(body); - Texture2D image; - Texture2D outline; + Texture2D image = null; + Texture2D outline = null; string imagePath = body.Config.ShipLog?.mapMode?.revealedSprite; string outlinePath = body.Config.ShipLog?.mapMode?.outlineSprite; if (imagePath != null) image = ImageUtilities.GetTexture(body.Mod, imagePath); - else image = AutoGenerateMapModePicture(body); + if (image == null) image = AutoGenerateMapModePicture(body); if (outlinePath != null) outline = ImageUtilities.GetTexture(body.Mod, outlinePath); - else outline = ImageUtilities.MakeOutline(image, Color.white, 10); + if (outline == null) outline = ImageUtilities.MakeOutline(image, Color.white, 10); astroObject._imageObj = CreateImage(gameObject, image, body.Config.Name + " Revealed", layer); astroObject._outlineObj = CreateImage(gameObject, outline, body.Config.Name + " Outline", layer); From fb13d5607e615e364aea89d59f32462a47bb6b6a Mon Sep 17 00:00:00 2001 From: Nick Date: Mon, 16 May 2022 13:20:39 -0400 Subject: [PATCH 5/8] Add minimap back to planets --- NewHorizons/Builder/Atmosphere/VolumesBuilder.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/NewHorizons/Builder/Atmosphere/VolumesBuilder.cs b/NewHorizons/Builder/Atmosphere/VolumesBuilder.cs index bb27a514..b58e7509 100644 --- a/NewHorizons/Builder/Atmosphere/VolumesBuilder.cs +++ b/NewHorizons/Builder/Atmosphere/VolumesBuilder.cs @@ -11,7 +11,7 @@ namespace NewHorizons.Builder.Atmosphere public static void Make(GameObject planetGO, IPlanetConfig config, float sphereOfInfluence) { var innerRadius = config.Base.SurfaceSize; - var useMiniMap = config.Base.IsSatellite; + var useMiniMap = !config.Base.IsSatellite; GameObject volumesGO = new GameObject("Volumes"); volumesGO.SetActive(false); From ebe8bd9c1ce1e06610ace7c850209d932ed6182b Mon Sep 17 00:00:00 2001 From: Nick Date: Mon, 16 May 2022 18:41:03 -0400 Subject: [PATCH 6/8] Supernovas work locally Proxies are broken Star atmospheres are broken --- NewHorizons/Builder/Body/ProxyBuilder.cs | 4 +- NewHorizons/Builder/Body/StarBuilder.cs | 29 +++-- .../StarEvolutionController.cs | 105 ++++++++++++++++-- .../External/VariableSize/StarModule.cs | 1 + NewHorizons/schema.json | 4 + 5 files changed, 119 insertions(+), 24 deletions(-) diff --git a/NewHorizons/Builder/Body/ProxyBuilder.cs b/NewHorizons/Builder/Body/ProxyBuilder.cs index 96c7f8e1..52e39c11 100644 --- a/NewHorizons/Builder/Body/ProxyBuilder.cs +++ b/NewHorizons/Builder/Body/ProxyBuilder.cs @@ -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"; - public static void Make(GameObject gameObject, NewHorizonsBody body) + public static void Make(GameObject planetGO, NewHorizonsBody body) { if (lavaMaterial == null) lavaMaterial = SearchUtilities.FindObjectOfTypeAndName("VolcanicMoon_Body").transform.Find("LavaSphere").GetComponent().material; @@ -57,7 +57,7 @@ namespace NewHorizons.Builder.Body } 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); diff --git a/NewHorizons/Builder/Body/StarBuilder.cs b/NewHorizons/Builder/Body/StarBuilder.cs index e5e731bb..cdbca3a9 100644 --- a/NewHorizons/Builder/Body/StarBuilder.cs +++ b/NewHorizons/Builder/Body/StarBuilder.cs @@ -36,7 +36,7 @@ namespace NewHorizons.Builder.Body GameObject sunAtmosphere = null; 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.localScale = Vector3.one; sunAtmosphere.name = "Atmosphere_Star"; @@ -132,22 +132,30 @@ namespace NewHorizons.Builder.Body controller.size = starModule.Size; controller.atmosphere = sunAtmosphere; controller.supernova = supernova; + controller.startColour = starModule.Tint; + controller.startColour = starModule.EndTint; 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) - { - var controller = planetGO.AddComponent(); - controller.scaleCurve = starModule.ToAnimationCurve(); - controller.size = starModule.Size; - } + MakeStarGraphics(proxyGO, null, starModule); - return planetGO; + var supernova = MakeSupernova(starGO); + + var controller = starGO.AddComponent(); + if (starModule.Curve != null) controller.scaleCurve = starModule.ToAnimationCurve(); + controller.size = starModule.Size; + controller.supernova = supernova; + + planet.GetComponentInChildren().SetProxy(controller); + + return proxyGO; } public static GameObject MakeStarGraphics(GameObject rootObject, Sector sector, StarModule starModule) @@ -206,6 +214,7 @@ namespace NewHorizons.Builder.Body var supernova = supernovaGO.GetComponent(); supernova._surface = starGO.GetComponentInChildren(); + supernova._supernovaVolume = null; supernovaGO.SetActive(true); diff --git a/NewHorizons/Components/SizeControllers/StarEvolutionController.cs b/NewHorizons/Components/SizeControllers/StarEvolutionController.cs index 58953a9f..e59e9480 100644 --- a/NewHorizons/Components/SizeControllers/StarEvolutionController.cs +++ b/NewHorizons/Components/SizeControllers/StarEvolutionController.cs @@ -1,4 +1,5 @@ using NewHorizons.Builder.Body; +using NewHorizons.Utility; using System; using System.Collections.Generic; using System.Linq; @@ -13,32 +14,91 @@ namespace NewHorizons.Components.SizeControllers public GameObject atmosphere; public SupernovaEffectController supernova; + public MColor startColour; + public MColor endColour; + + private Color _startColour; + private Color _endColour; + private PlanetaryFogController _fog; private MeshRenderer[] _atmosphereRenderers; + private HeatHazardVolume _heatVolume; + private DestructionVolume _destructionVolume; private bool _isCollapsing; private float _collapseStartSize; private float _collapseTimer; - public float collapseTime = 5f; + public float collapseTime = 5f; // seconds + public float lifespan = 22f; // minutes + private float _age; private bool _isSupernova; private float _supernovaStartTime; private Material _collapseStartSurfaceMaterial; private Material _collapseEndSurfaceMaterial; + private Material _startSurfaceMaterial; + private Material _endSurfaceMaterial; + + private StarEvolutionController _proxy; void Awake() { var sun = GameObject.FindObjectOfType(); - _collapseStartSurfaceMaterial = sun._collapseStartSurfaceMaterial; - _collapseEndSurfaceMaterial = sun._collapseEndSurfaceMaterial; + _collapseStartSurfaceMaterial = new Material(sun._collapseStartSurfaceMaterial); + _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(); + _destructionVolume = GetComponentInChildren(); if (atmosphere != null) { _fog = atmosphere.GetComponentInChildren(); _atmosphereRenderers = atmosphere.transform.Find("AtmoSphere").GetComponentsInChildren(); } + + 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() @@ -46,24 +106,44 @@ namespace NewHorizons.Components.SizeControllers _isCollapsing = true; _collapseStartSize = CurrentScale; _collapseTimer = 0f; + + if (_proxy != null) _proxy.Die(); } 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) { + // Reset the scale back to normal bc now its just the supernova scaling itself + destruction and heat volumes 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); } return; - } + } + + Color currentColour; if (!_isCollapsing) { base.FixedUpdate(); + + currentColour = Color.Lerp(_startColour, _endColour, ageValue); + + supernova._surface._materials[0].Lerp(_startSurfaceMaterial, _endSurfaceMaterial, ageValue); } else { @@ -73,7 +153,9 @@ namespace NewHorizons.Components.SizeControllers transform.localScale = Vector3.one * CurrentScale; _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 if (_collapseTimer > collapseTime) @@ -82,20 +164,18 @@ namespace NewHorizons.Components.SizeControllers _isSupernova = true; _supernovaStartTime = Time.time; atmosphere.SetActive(false); + _destructionVolume._deathType = DeathType.Supernova; return; } } // This is just all the scales stuff for the atmosphere effects - if (atmosphere != null) - { - atmosphere.transform.localScale = CurrentScale * Vector3.one; - } - if (_fog != null) { _fog.fogRadius = CurrentScale * StarBuilder.OuterRadiusRatio; _fog.lodFadeDistance = CurrentScale * (StarBuilder.OuterRadiusRatio - 1f); + + _fog.fogTint = currentColour; } if (_atmosphereRenderers.Count() > 0) @@ -104,6 +184,7 @@ namespace NewHorizons.Components.SizeControllers { lod.material.SetFloat("_InnerRadius", CurrentScale); lod.material.SetFloat("_OuterRadius", CurrentScale * StarBuilder.OuterRadiusRatio); + lod.material.SetColor("_SkyColor", currentColour); } } } diff --git a/NewHorizons/External/VariableSize/StarModule.cs b/NewHorizons/External/VariableSize/StarModule.cs index 7808f880..1f3ee87a 100644 --- a/NewHorizons/External/VariableSize/StarModule.cs +++ b/NewHorizons/External/VariableSize/StarModule.cs @@ -11,6 +11,7 @@ namespace NewHorizons.External.VariableSize { public float Size { get; set; } = 2000f; public MColor Tint { get; set; } + public MColor EndTint { get; set; } public MColor SolarFlareTint { get; set; } public MColor LightTint { get; set; } public float SolarLuminosity { get; set; } = 1f; diff --git a/NewHorizons/schema.json b/NewHorizons/schema.json index ad9ab075..1a9db790 100644 --- a/NewHorizons/schema.json +++ b/NewHorizons/schema.json @@ -596,6 +596,10 @@ "$ref": "#/$defs/color", "description": "Colour of the star." }, + "endTint": { + "$ref": "#/$defs/color", + "description": "Colour of the star at the end of its life." + }, "solarFlareTint": { "$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." From 34cc923a5f44602d0ddc547f58b99ef60847cba3 Mon Sep 17 00:00:00 2001 From: Nick Date: Tue, 17 May 2022 17:29:38 -0400 Subject: [PATCH 7/8] 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?" } } }, From 52cd3377f4e3a2e8e57d43554f3dc7a1e6387d0c Mon Sep 17 00:00:00 2001 From: Nick Date: Tue, 17 May 2022 17:30:13 -0400 Subject: [PATCH 8/8] Bump version number --- NewHorizons/manifest.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/NewHorizons/manifest.json b/NewHorizons/manifest.json index c3c9605a..a8642db2 100644 --- a/NewHorizons/manifest.json +++ b/NewHorizons/manifest.json @@ -3,7 +3,7 @@ "author": "xen, Bwc9876, & Book", "name": "New Horizons", "uniqueName": "xen.NewHorizons", - "version": "0.17.0", + "version": "0.18.0", "owmlVersion": "2.1.0", "conflicts": [ "Raicuparta.QuantumSpaceBuddies", "Vesper.AutoResume", "PacificEngine.OW_Randomizer" ], "pathsToPreserve": [ "planets", "systems", "translations" ]