From eb4e5bf26e6aa362921f2da367de1d4ee502a53f Mon Sep 17 00:00:00 2001 From: Nick Date: Sat, 14 May 2022 18:57:32 -0400 Subject: [PATCH] Some tweaks --- NewHorizons/Builder/Body/ProxyBuilder.cs | 132 +++++++++++------------ 1 file changed, 63 insertions(+), 69 deletions(-) diff --git a/NewHorizons/Builder/Body/ProxyBuilder.cs b/NewHorizons/Builder/Body/ProxyBuilder.cs index a61494c8..452ac013 100644 --- a/NewHorizons/Builder/Body/ProxyBuilder.cs +++ b/NewHorizons/Builder/Body/ProxyBuilder.cs @@ -2,7 +2,9 @@ using NewHorizons.Components; using NewHorizons.Utility; using OWML.Common; +using System; using UnityEngine; +using Logger = NewHorizons.Utility.Logger; namespace NewHorizons.Builder.Body { @@ -12,80 +14,72 @@ namespace NewHorizons.Builder.Body { var proxyName = $"{body.Config.Name}_Proxy"; - // Stars don't work yet so uh - /* - if (body.Config.Star != null) - { - var sunProxy = SearchUtilities.CachedFind("SunProxy(Clone)"); - var oldProxyEffectController = sunProxy.GetComponentInChildren(); - var newProxy = Object.Instantiate(sunProxy, gameObject.transform.position, Quaternion.identity); - newProxy.name = proxyName; - var proxyController = newProxy.GetComponent(); - proxyController._proxySunController = newProxy.GetComponentInChildren(); - proxyController._proxySunController._atmosphereMaterial = oldProxyEffectController._atmosphereMaterial; - proxyController._proxySunController._fogMaterial = oldProxyEffectController._fogMaterial; - Main.Instance.ModHelper.Events.Unity.FireOnNextUpdate(() => - { - proxyController._sunTransform = gameObject.transform; - proxyController._realSunController = gameObject.GetComponent(); - }); - } - */ - var newProxy = new GameObject(proxyName); - // We want to take the largest size I think - var realSize = body.Config.Base.SurfaceSize; + try + { + // We want to take the largest size I think + var realSize = body.Config.Base.SurfaceSize; - if (body.Config.HeightMap != null) - { - HeightMapBuilder.Make(newProxy, null, body.Config.HeightMap, body.Mod, 20); - if(realSize < body.Config.HeightMap.MaxHeight) realSize = body.Config.HeightMap.MaxHeight; - } - if (body.Config.Base.GroundSize != 0) - { - GeometryBuilder.Make(newProxy, null, body.Config.Base.GroundSize); - if (realSize < body.Config.Base.GroundSize) realSize = body.Config.Base.GroundSize; - } - if (body.Config.Atmosphere != null) - { - CloudsBuilder.MakeTopClouds(newProxy, body.Config.Atmosphere, body.Mod); - if (realSize < body.Config.Atmosphere.Size) realSize = body.Config.Atmosphere.Size; - } - if (body.Config.Ring != null) - { - RingBuilder.MakeRingGraphics(newProxy, null, body.Config.Ring, body.Mod); - if (realSize < body.Config.Ring.OuterRadius) realSize = body.Config.Ring.OuterRadius; - } - if (body.Config.Star != null) - { - StarBuilder.MakeStarGraphics(newProxy, null, body.Config.Star); - if (realSize < body.Config.Star.Size) realSize = body.Config.Star.Size; - } - if(body.Config.ProcGen != null) - { - ProcGenBuilder.Make(newProxy, null, body.Config.ProcGen); - if (realSize < body.Config.ProcGen.Scale) realSize = body.Config.ProcGen.Scale; - } + if (body.Config.HeightMap != null) + { + HeightMapBuilder.Make(newProxy, null, body.Config.HeightMap, body.Mod, 20); + if (realSize < body.Config.HeightMap.MaxHeight) realSize = body.Config.HeightMap.MaxHeight; + } + if (body.Config.Base.GroundSize != 0) + { + GeometryBuilder.Make(newProxy, null, body.Config.Base.GroundSize); + if (realSize < body.Config.Base.GroundSize) realSize = body.Config.Base.GroundSize; + } + if (body.Config.Atmosphere != null) + { + CloudsBuilder.MakeTopClouds(newProxy, body.Config.Atmosphere, body.Mod); + if (realSize < body.Config.Atmosphere.Size) realSize = body.Config.Atmosphere.Size; + } + if (body.Config.Ring != null) + { + RingBuilder.MakeRingGraphics(newProxy, null, body.Config.Ring, body.Mod); + if (realSize < body.Config.Ring.OuterRadius) realSize = body.Config.Ring.OuterRadius; + } + if (body.Config.Star != null) + { + StarBuilder.MakeStarGraphics(newProxy, null, body.Config.Star); + if (realSize < body.Config.Star.Size) realSize = body.Config.Star.Size; + } + if (body.Config.ProcGen != null) + { + ProcGenBuilder.Make(newProxy, null, body.Config.ProcGen); + if (realSize < body.Config.ProcGen.Scale) realSize = body.Config.ProcGen.Scale; + } - // Remove all collisions if there are any - foreach (var col in newProxy.GetComponentsInChildren()) - { - GameObject.Destroy(col); - } - // Fix render idk - foreach (var renderer in newProxy.GetComponentsInChildren()) - { - renderer.shadowCastingMode = UnityEngine.Rendering.ShadowCastingMode.Off; - renderer.receiveShadows = false; - renderer.lightProbeUsage = UnityEngine.Rendering.LightProbeUsage.BlendProbes; - } + // Remove all collisions if there are any + foreach (var col in newProxy.GetComponentsInChildren()) + { + GameObject.Destroy(col); + } - var proxyController = newProxy.AddComponent(); - proxyController.astroName = body.Config.Name; - proxyController._realObjectDiameter = realSize; - proxyController.renderers = newProxy.GetComponentsInChildren(); - proxyController.tessellatedRenderers = newProxy.GetComponentsInChildren(); + foreach (var renderer in newProxy.GetComponentsInChildren()) + { + renderer.shadowCastingMode = UnityEngine.Rendering.ShadowCastingMode.Off; + renderer.receiveShadows = false; + renderer.enabled = true; + } + foreach (var tessellatedRenderer in newProxy.GetComponentsInChildren()) + { + tessellatedRenderer.enabled = true; + } + + var proxyController = newProxy.AddComponent(); + proxyController.astroName = body.Config.Name; + proxyController._realObjectDiameter = realSize; + proxyController.renderers = newProxy.GetComponentsInChildren(); + proxyController.tessellatedRenderers = newProxy.GetComponentsInChildren(); + } + catch (Exception ex) + { + Logger.Log($"Exception thrown when generating proxy for [{body.Config.Name}] : {ex.Message}, {ex.StackTrace}"); + GameObject.Destroy(newProxy); + } } } } \ No newline at end of file