From 7b5e66b37c647e83e2636c8c0b2d442023ba4084 Mon Sep 17 00:00:00 2001 From: Nick Date: Mon, 23 May 2022 21:26:35 -0400 Subject: [PATCH] Fix star log errors --- NewHorizons/Builder/Body/StarBuilder.cs | 17 ++++++---- .../StarEvolutionController.cs | 32 ++++++++++++------- 2 files changed, 32 insertions(+), 17 deletions(-) diff --git a/NewHorizons/Builder/Body/StarBuilder.cs b/NewHorizons/Builder/Body/StarBuilder.cs index a9458c16..fe7b74a6 100644 --- a/NewHorizons/Builder/Body/StarBuilder.cs +++ b/NewHorizons/Builder/Body/StarBuilder.cs @@ -119,21 +119,24 @@ namespace NewHorizons.Builder.Body var supernova = MakeSupernova(starGO, starModule); + starGO.SetActive(false); var controller = starGO.AddComponent(); if (starModule.Curve != null) controller.scaleCurve = starModule.GetAnimationCurve(); controller.size = starModule.size; controller.atmosphere = sunAtmosphere; controller.supernova = supernova; - controller.startColour = starModule.tint; - controller.endColour = starModule.endTint; - controller.willExplode = starModule.goSupernova; + controller.StartColour = starModule.tint; + controller.EndColour = starModule.endTint; + controller.WillExplode = starModule.goSupernova; + starGO.SetActive(true); // 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(); + var sphere = supernovaVolume.AddComponent(); sphere.radius = 0f; + sphere.isTrigger = true; supernovaVolume.AddComponent(); return starController; @@ -145,13 +148,15 @@ namespace NewHorizons.Builder.Body var supernova = MakeSupernova(starGO, starModule); + starGO.SetActive(false); var controller = starGO.AddComponent(); if (starModule.Curve != null) controller.scaleCurve = starModule.GetAnimationCurve(); controller.size = starModule.size; controller.supernova = supernova; - controller.startColour = starModule.tint; - controller.endColour = starModule.endTint; + controller.StartColour = starModule.tint; + controller.EndColour = starModule.endTint; controller.enabled = true; + starGO.SetActive(true); planet.GetComponentInChildren().SetProxy(controller); diff --git a/NewHorizons/Components/SizeControllers/StarEvolutionController.cs b/NewHorizons/Components/SizeControllers/StarEvolutionController.cs index 40da8bdb..38eb2850 100644 --- a/NewHorizons/Components/SizeControllers/StarEvolutionController.cs +++ b/NewHorizons/Components/SizeControllers/StarEvolutionController.cs @@ -1,4 +1,4 @@ -using NewHorizons.Builder.Body; +using NewHorizons.Builder.Body; using NewHorizons.Utility; using System; using System.Collections.Generic; @@ -6,6 +6,7 @@ using System.Linq; using System.Text; using System.Threading.Tasks; using UnityEngine; +using UnityEngine.Events; namespace NewHorizons.Components.SizeControllers { @@ -13,9 +14,9 @@ namespace NewHorizons.Components.SizeControllers { public GameObject atmosphere; public SupernovaEffectController supernova; - public bool willExplode; - public MColor startColour { get; set; } - public MColor endColour { get; set; } + public bool WillExplode { get; set; } + public MColor StartColour { get; set; } + public MColor EndColour { get; set; } private Color _startColour; private Color _endColour; @@ -44,6 +45,8 @@ namespace NewHorizons.Components.SizeControllers private StarEvolutionController _proxy; + public UnityEvent SupernovaStart = new UnityEvent(); + private float maxScale; private static readonly int ColorRamp = Shader.PropertyToID("_ColorRamp"); @@ -61,24 +64,24 @@ namespace NewHorizons.Components.SizeControllers _startSurfaceMaterial.SetTexture(ColorRamp, supernova._surface.sharedMaterial.GetTexture(ColorRamp)); _endSurfaceMaterial.SetTexture(ColorRamp, supernova._surface.sharedMaterial.GetTexture(ColorRamp)); - if (startColour == null) + if (StartColour == null) { _startColour = _startSurfaceMaterial.color; } else { - _startColour = startColour; + _startColour = StartColour; _startSurfaceMaterial.color = _startColour; } - if (endColour == null) + if (EndColour == null) { _endColour = _startColour; _endSurfaceMaterial.color = _startColour; } else { - _endColour = endColour; + _endColour = EndColour; _endSurfaceMaterial.color = _endColour; } @@ -91,19 +94,25 @@ namespace NewHorizons.Components.SizeControllers _atmosphereRenderers = atmosphere?.transform?.Find("AtmoSphere")?.GetComponentsInChildren(); } - if (willExplode) GlobalMessenger.AddListener("TriggerSupernova", Die); + if (WillExplode) GlobalMessenger.AddListener("TriggerSupernova", Die); if (scaleCurve != null) { maxScale = scaleCurve.keys.Select(x => x.value).Max() * size; } + else + { + maxScale = 0; + scaleCurve = new AnimationCurve(); + scaleCurve.AddKey(0, 1); + } _flareEmitter = GetComponentInChildren(); } public void OnDestroy() { - if (willExplode) GlobalMessenger.RemoveListener("TriggerSupernova", Die); + if (WillExplode) GlobalMessenger.RemoveListener("TriggerSupernova", Die); } public void SetProxy(StarEvolutionController proxy) @@ -153,7 +162,7 @@ namespace NewHorizons.Components.SizeControllers base.FixedUpdate(); // Only do colour transition stuff if they set an end colour - if (endColour != null) + 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; @@ -183,6 +192,7 @@ namespace NewHorizons.Components.SizeControllers // After the collapse is done we go supernova if (_collapseTimer > collapseTime) { + SupernovaStart.Invoke(); supernova.enabled = true; _isSupernova = true; _supernovaStartTime = Time.time;