Change default particle height to not NRE probably

This commit is contained in:
Nick 2023-09-11 23:49:03 -04:00
parent 84c3655a32
commit 588306f936

View File

@ -2,6 +2,7 @@ using NewHorizons.External.Configs;
using NewHorizons.External.Modules; using NewHorizons.External.Modules;
using NewHorizons.Utility; using NewHorizons.Utility;
using UnityEngine; using UnityEngine;
namespace NewHorizons.Builder.Atmosphere namespace NewHorizons.Builder.Atmosphere
{ {
public static class EffectsBuilder public static class EffectsBuilder
@ -55,29 +56,19 @@ namespace NewHorizons.Builder.Atmosphere
{ {
InitPrefabs(); InitPrefabs();
GameObject effectsGO = new GameObject("Effects"); var effectsGO = new GameObject("Effects");
effectsGO.SetActive(false); effectsGO.SetActive(false);
effectsGO.transform.parent = sector?.transform ?? planetGO.transform; effectsGO.transform.parent = sector?.transform ?? planetGO.transform;
effectsGO.transform.position = planetGO.transform.position; effectsGO.transform.position = planetGO.transform.position;
SectorCullGroup SCG = effectsGO.AddComponent<SectorCullGroup>(); var sectorCullGroup = effectsGO.AddComponent<SectorCullGroup>();
SCG._sector = sector; sectorCullGroup._sector = sector;
SCG._particleSystemSuspendMode = CullGroup.ParticleSystemSuspendMode.Stop; sectorCullGroup._particleSystemSuspendMode = CullGroup.ParticleSystemSuspendMode.Stop;
SCG._occlusionCulling = false; sectorCullGroup._occlusionCulling = false;
SCG._dynamicCullingBounds = false; sectorCullGroup._dynamicCullingBounds = false;
SCG._waitForStreaming = false; sectorCullGroup._waitForStreaming = false;
var minHeight = config.Base.surfaceSize; var (minHeight, maxHeight) = GetDefaultHeightRange(config);
if (config.HeightMap?.minHeight != null)
{
if (config.Water?.size >= config.HeightMap.minHeight) minHeight = config.Water.size; // use sea level if its higher
else minHeight = config.HeightMap.minHeight;
}
else if (config.Water?.size != null) minHeight = config.Water.size;
else if (config.Lava?.size != null) minHeight = config.Lava.size;
var maxHeight = config.Atmosphere.size;
if (config.Atmosphere.clouds?.outerCloudRadius != null) maxHeight = config.Atmosphere.clouds.outerCloudRadius;
foreach (var particleField in config.ParticleFields) foreach (var particleField in config.ParticleFields)
{ {
@ -130,5 +121,48 @@ namespace NewHorizons.Builder.Atmosphere
_ => null, _ => null,
}; };
} }
private static (float, float) GetDefaultHeightRange(PlanetConfig config)
{
// Determining default values for min/max height
var minHeight = 0f;
if (config.HeightMap?.minHeight != null)
{
if (config.Water?.size >= config.HeightMap.minHeight) minHeight = config.Water.size; // use sea level if its higher
else minHeight = config.HeightMap.minHeight;
}
else if (config.Water?.size != null)
{
minHeight = config.Water.size;
}
else if (config.Lava?.size != null)
{
minHeight = config.Lava.size;
}
else if (config.Base != null)
{
minHeight = config.Base.surfaceSize;
}
var maxHeight = 100f;
if (config.Atmosphere != null)
{
if (config.Atmosphere.clouds?.outerCloudRadius != null)
{
maxHeight = config.Atmosphere.clouds.outerCloudRadius;
}
else
{
maxHeight = config.Atmosphere.size;
}
}
else if (config.Base != null)
{
maxHeight = config.Base.surfaceSize * 2f;
}
return (minHeight, maxHeight);
}
} }
} }