From 8d370ac5461bd70ff93d19a7b733e96947adedbd Mon Sep 17 00:00:00 2001 From: Noah Pilarski Date: Thu, 18 Aug 2022 19:22:58 -0400 Subject: [PATCH] Add optional mesh change for supernova planet effect --- NewHorizons/Builder/Body/ProxyBuilder.cs | 2 +- .../Builder/Body/SupernovaEffectBuilder.cs | 17 ++++++++++++++++- .../External/Modules/ShockEffectModule.cs | 2 +- NewHorizons/Handlers/PlanetCreationHandler.cs | 2 +- 4 files changed, 19 insertions(+), 4 deletions(-) diff --git a/NewHorizons/Builder/Body/ProxyBuilder.cs b/NewHorizons/Builder/Body/ProxyBuilder.cs index 9943a900..1f3ddd3c 100644 --- a/NewHorizons/Builder/Body/ProxyBuilder.cs +++ b/NewHorizons/Builder/Body/ProxyBuilder.cs @@ -173,7 +173,7 @@ namespace NewHorizons.Builder.Body NHSupernovaPlanetEffectController supernovaPlanetEffect = null; if ((body.Config.ShockEffect == null || body.Config.ShockEffect.hasSupernovaShockEffect) && body.Config.Star == null && body.Config.name != "Sun" && body.Config.FocalPoint == null && !body.Config.isStellarRemnant) { - supernovaPlanetEffect = SupernovaEffectBuilder.Make(proxy, null, body.Config, procGen, null, null, null, atmosphere, fog); + supernovaPlanetEffect = SupernovaEffectBuilder.Make(proxy, null, body.Config, body.Mod, procGen, null, null, null, atmosphere, fog); } // Remove all collisions if there are any diff --git a/NewHorizons/Builder/Body/SupernovaEffectBuilder.cs b/NewHorizons/Builder/Body/SupernovaEffectBuilder.cs index cfd57de3..a6c0afed 100644 --- a/NewHorizons/Builder/Body/SupernovaEffectBuilder.cs +++ b/NewHorizons/Builder/Body/SupernovaEffectBuilder.cs @@ -4,12 +4,13 @@ using NewHorizons.External.Configs; using NewHorizons.Components; using System.Linq; using NewHorizons.Handlers; +using OWML.Common; namespace NewHorizons.Builder.Body { public static class SupernovaEffectBuilder { - public static NHSupernovaPlanetEffectController Make(GameObject planetGO, Sector sector, PlanetConfig config, GameObject procGen, Light ambientLight, PlanetaryFogController fog, LODGroup atmosphere, Renderer atmosphereRenderer, Renderer fogImpostor) + public static NHSupernovaPlanetEffectController Make(GameObject planetGO, Sector sector, PlanetConfig config, IModBehaviour mod, GameObject procGen, Light ambientLight, PlanetaryFogController fog, LODGroup atmosphere, Renderer atmosphereRenderer, Renderer fogImpostor) { var vanillaController = planetGO.GetComponentInChildren(); if (vanillaController != null) @@ -139,6 +140,20 @@ namespace NewHorizons.Builder.Body shockLayer.transform.rotation = Quaternion.Euler(90, 0, 0); } + if (config.ShockEffect != null) + { + if (!string.IsNullOrWhiteSpace(config.ShockEffect.assetBundle) && !string.IsNullOrWhiteSpace(config.ShockEffect.meshPath)) + { + var mesh = AssetBundleUtilities.Load(config.ShockEffect.assetBundle, config.ShockEffect.meshPath, mod); + if (mesh != null) + { + shockLayer.GetComponent().sharedMesh = mesh; + shockLayer.transform.localScale = Vector3.one * 1.1f; + shockLayer.transform.rotation = Quaternion.Euler(0, 0, 0); + } + } + } + return supernovaEffectController; } } diff --git a/NewHorizons/External/Modules/ShockEffectModule.cs b/NewHorizons/External/Modules/ShockEffectModule.cs index 5b2405ec..c5b794d1 100644 --- a/NewHorizons/External/Modules/ShockEffectModule.cs +++ b/NewHorizons/External/Modules/ShockEffectModule.cs @@ -21,7 +21,7 @@ namespace NewHorizons.External.Modules public string assetBundle; /// - /// Path in the asset bundle that leads a replacement mesh for the planet's supernova shock effect + /// Path to the replacement mesh for the planet's supernova shock effect in the supplied asset bundle /// public string meshPath; } diff --git a/NewHorizons/Handlers/PlanetCreationHandler.cs b/NewHorizons/Handlers/PlanetCreationHandler.cs index f0e880c5..c117be4f 100644 --- a/NewHorizons/Handlers/PlanetCreationHandler.cs +++ b/NewHorizons/Handlers/PlanetCreationHandler.cs @@ -599,7 +599,7 @@ namespace NewHorizons.Handlers if ((body.Config.ShockEffect == null || body.Config.ShockEffect.hasSupernovaShockEffect) && body.Config.Star == null && body.Config.name != "Sun" && body.Config.FocalPoint == null) { - SupernovaEffectBuilder.Make(go, sector, body.Config, procGen, ambientLight, fog, atmosphere, null, fog?._fogImpostor); + SupernovaEffectBuilder.Make(go, sector, body.Config, body.Mod, procGen, ambientLight, fog, atmosphere, null, fog?._fogImpostor); } return go;