Some tweaks

This commit is contained in:
Nick 2022-05-14 18:57:32 -04:00
parent cdcc215b65
commit eb4e5bf26e

View File

@ -2,7 +2,9 @@
using NewHorizons.Components; using NewHorizons.Components;
using NewHorizons.Utility; using NewHorizons.Utility;
using OWML.Common; using OWML.Common;
using System;
using UnityEngine; using UnityEngine;
using Logger = NewHorizons.Utility.Logger;
namespace NewHorizons.Builder.Body namespace NewHorizons.Builder.Body
{ {
@ -12,80 +14,72 @@ namespace NewHorizons.Builder.Body
{ {
var proxyName = $"{body.Config.Name}_Proxy"; 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<SunProxyEffectController>();
var newProxy = Object.Instantiate(sunProxy, gameObject.transform.position, Quaternion.identity);
newProxy.name = proxyName;
var proxyController = newProxy.GetComponent<SunProxy>();
proxyController._proxySunController = newProxy.GetComponentInChildren<SunProxyEffectController>();
proxyController._proxySunController._atmosphereMaterial = oldProxyEffectController._atmosphereMaterial;
proxyController._proxySunController._fogMaterial = oldProxyEffectController._fogMaterial;
Main.Instance.ModHelper.Events.Unity.FireOnNextUpdate(() =>
{
proxyController._sunTransform = gameObject.transform;
proxyController._realSunController = gameObject.GetComponent<SunController>();
});
}
*/
var newProxy = new GameObject(proxyName); var newProxy = new GameObject(proxyName);
// We want to take the largest size I think try
var realSize = body.Config.Base.SurfaceSize; {
// We want to take the largest size I think
var realSize = body.Config.Base.SurfaceSize;
if (body.Config.HeightMap != null) if (body.Config.HeightMap != null)
{ {
HeightMapBuilder.Make(newProxy, null, body.Config.HeightMap, body.Mod, 20); HeightMapBuilder.Make(newProxy, null, body.Config.HeightMap, body.Mod, 20);
if(realSize < body.Config.HeightMap.MaxHeight) realSize = body.Config.HeightMap.MaxHeight; if (realSize < body.Config.HeightMap.MaxHeight) realSize = body.Config.HeightMap.MaxHeight;
} }
if (body.Config.Base.GroundSize != 0) if (body.Config.Base.GroundSize != 0)
{ {
GeometryBuilder.Make(newProxy, null, body.Config.Base.GroundSize); GeometryBuilder.Make(newProxy, null, body.Config.Base.GroundSize);
if (realSize < body.Config.Base.GroundSize) realSize = body.Config.Base.GroundSize; if (realSize < body.Config.Base.GroundSize) realSize = body.Config.Base.GroundSize;
} }
if (body.Config.Atmosphere != null) if (body.Config.Atmosphere != null)
{ {
CloudsBuilder.MakeTopClouds(newProxy, body.Config.Atmosphere, body.Mod); CloudsBuilder.MakeTopClouds(newProxy, body.Config.Atmosphere, body.Mod);
if (realSize < body.Config.Atmosphere.Size) realSize = body.Config.Atmosphere.Size; if (realSize < body.Config.Atmosphere.Size) realSize = body.Config.Atmosphere.Size;
} }
if (body.Config.Ring != null) if (body.Config.Ring != null)
{ {
RingBuilder.MakeRingGraphics(newProxy, null, body.Config.Ring, body.Mod); RingBuilder.MakeRingGraphics(newProxy, null, body.Config.Ring, body.Mod);
if (realSize < body.Config.Ring.OuterRadius) realSize = body.Config.Ring.OuterRadius; if (realSize < body.Config.Ring.OuterRadius) realSize = body.Config.Ring.OuterRadius;
} }
if (body.Config.Star != null) if (body.Config.Star != null)
{ {
StarBuilder.MakeStarGraphics(newProxy, null, body.Config.Star); StarBuilder.MakeStarGraphics(newProxy, null, body.Config.Star);
if (realSize < body.Config.Star.Size) realSize = body.Config.Star.Size; if (realSize < body.Config.Star.Size) realSize = body.Config.Star.Size;
} }
if(body.Config.ProcGen != null) if (body.Config.ProcGen != null)
{ {
ProcGenBuilder.Make(newProxy, null, body.Config.ProcGen); ProcGenBuilder.Make(newProxy, null, body.Config.ProcGen);
if (realSize < body.Config.ProcGen.Scale) realSize = body.Config.ProcGen.Scale; if (realSize < body.Config.ProcGen.Scale) realSize = body.Config.ProcGen.Scale;
} }
// Remove all collisions if there are any // Remove all collisions if there are any
foreach (var col in newProxy.GetComponentsInChildren<Collider>()) foreach (var col in newProxy.GetComponentsInChildren<Collider>())
{ {
GameObject.Destroy(col); GameObject.Destroy(col);
} }
// Fix render idk
foreach (var renderer in newProxy.GetComponentsInChildren<Renderer>())
{
renderer.shadowCastingMode = UnityEngine.Rendering.ShadowCastingMode.Off;
renderer.receiveShadows = false;
renderer.lightProbeUsage = UnityEngine.Rendering.LightProbeUsage.BlendProbes;
}
var proxyController = newProxy.AddComponent<NHProxy>(); foreach (var renderer in newProxy.GetComponentsInChildren<Renderer>())
proxyController.astroName = body.Config.Name; {
proxyController._realObjectDiameter = realSize; renderer.shadowCastingMode = UnityEngine.Rendering.ShadowCastingMode.Off;
proxyController.renderers = newProxy.GetComponentsInChildren<Renderer>(); renderer.receiveShadows = false;
proxyController.tessellatedRenderers = newProxy.GetComponentsInChildren<TessellatedRenderer>(); renderer.enabled = true;
}
foreach (var tessellatedRenderer in newProxy.GetComponentsInChildren<TessellatedRenderer>())
{
tessellatedRenderer.enabled = true;
}
var proxyController = newProxy.AddComponent<NHProxy>();
proxyController.astroName = body.Config.Name;
proxyController._realObjectDiameter = realSize;
proxyController.renderers = newProxy.GetComponentsInChildren<Renderer>();
proxyController.tessellatedRenderers = newProxy.GetComponentsInChildren<TessellatedRenderer>();
}
catch (Exception ex)
{
Logger.Log($"Exception thrown when generating proxy for [{body.Config.Name}] : {ex.Message}, {ex.StackTrace}");
GameObject.Destroy(newProxy);
}
} }
} }
} }