From 608c9bb27fac4889321c5d390a28cf184561bf88 Mon Sep 17 00:00:00 2001 From: Nick Date: Sat, 25 Mar 2023 11:44:35 -0400 Subject: [PATCH 1/2] Properly check if texture exists --- NewHorizons/Builder/Body/RingBuilder.cs | 22 +++++++++------------- 1 file changed, 9 insertions(+), 13 deletions(-) diff --git a/NewHorizons/Builder/Body/RingBuilder.cs b/NewHorizons/Builder/Body/RingBuilder.cs index 581498ea..59cabfb4 100644 --- a/NewHorizons/Builder/Body/RingBuilder.cs +++ b/NewHorizons/Builder/Body/RingBuilder.cs @@ -1,14 +1,14 @@ using NewHorizons.Components; using NewHorizons.Components.SizeControllers; +using NewHorizons.Components.Volumes; +using NewHorizons.External.Modules; using NewHorizons.Utility; +using NewHorizons.Utility.OWUtilities; using OWML.Common; using System; using System.Collections.Generic; -using NewHorizons.External.Modules; using UnityEngine; using Logger = NewHorizons.Utility.Logger; -using NewHorizons.Components.Volumes; -using NewHorizons.Utility.OWUtilities; namespace NewHorizons.Builder.Body { @@ -64,14 +64,11 @@ namespace NewHorizons.Builder.Body // Properly lit shader doesnt work yet ring.unlit = true; - Texture2D ringTexture; - try + var ringTexture = ImageUtilities.GetTexture(mod, ring.texture); + + if (ringTexture == null) { - ringTexture = ImageUtilities.GetTexture(mod, ring.texture); - } - catch (Exception e) - { - Logger.LogError($"Couldn't load Ring texture:\n{e}"); + Logger.LogError($"Couldn't load Ring texture [{ring.texture}]"); return null; } @@ -85,7 +82,6 @@ namespace NewHorizons.Builder.Body var ringMF = ringGO.AddComponent(); var ringMesh = ringMF.mesh; var ringMR = ringGO.AddComponent(); - var texture = ringTexture; if (RingShader == null) RingShader = Main.NHAssetBundle.LoadAsset("Assets/Shaders/Ring.shader"); if (UnlitRingShader == null) UnlitRingShader = Main.NHAssetBundle.LoadAsset("Assets/Shaders/UnlitTransparent.shader"); @@ -93,14 +89,14 @@ namespace NewHorizons.Builder.Body if (UnlitRingShader1Pixel == null) UnlitRingShader1Pixel = Main.NHAssetBundle.LoadAsset("Assets/Shaders/UnlitRing1Pixel.shader"); var mat = new Material(ring.unlit ? UnlitRingShader : RingShader); - if (texture.width == 1) + if (ringTexture.width == 1) { mat = new Material(ring.unlit ? UnlitRingShader1Pixel : RingShader1Pixel); mat.SetFloat(InnerRadius, 0); } ringMR.receiveShadows = !ring.unlit; - mat.mainTexture = texture; + mat.mainTexture = ringTexture; // Black holes vanish behind rings // However if we lower this to where black holes don't vanish, water becomes invisible when seen through rings From 59721b1f555c7dabf93d6ce60d63bdeb18e6701f Mon Sep 17 00:00:00 2001 From: Nick Date: Sat, 25 Mar 2023 12:14:13 -0400 Subject: [PATCH 2/2] Fix RingOpacityController NRE --- .../Components/RingOpacityController.cs | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/NewHorizons/Components/RingOpacityController.cs b/NewHorizons/Components/RingOpacityController.cs index 0f762506..913230c4 100644 --- a/NewHorizons/Components/RingOpacityController.cs +++ b/NewHorizons/Components/RingOpacityController.cs @@ -25,10 +25,22 @@ namespace NewHorizons.Components CurrentOpacity = 1; } - if (_ringFluidVolume != null) + if (_ringFluidVolume != null && _ringFluidVolume.gameObject.activeInHierarchy) { - if (Mathf.Approximately(CurrentOpacity, 0) && _ringFluidVolume.IsVolumeActive()) _ringFluidVolume.SetVolumeActivation(false); - else if (!_ringFluidVolume.IsVolumeActive()) _ringFluidVolume.SetVolumeActivation(true); + if (Mathf.Approximately(CurrentOpacity, 0)) + { + if (_ringFluidVolume.IsVolumeActive()) + { + _ringFluidVolume.SetVolumeActivation(false); + } + } + else + { + if (!_ringFluidVolume.IsVolumeActive()) + { + _ringFluidVolume.SetVolumeActivation(true); + } + } } if (_meshRenderer == null) return;