cull/collision/lights groups (#359)

groups make things turn off when you're not in the sector. (cull =
renderers, collision = colliders/shapes, lights = lights)
this pr makes nh add groups to anything using DetailBuilder.Make
this should improve performance, since things will only appear when
you're close enough to them. it should also help with Jack's mod since
he uses lots of cacti (ie volumes)

this pr also makes keepLoaded actually function (and adds the setting to
scatter)
This commit is contained in:
Will Corby 2022-09-08 17:14:16 -07:00 committed by GitHub
commit 0a54bb2447
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 41 additions and 0 deletions

View File

@ -0,0 +1,29 @@
using UnityEngine;
using Logger = NewHorizons.Utility.Logger;
namespace NewHorizons.Builder.General;
public static class GroupsBuilder
{
/// <summary>
/// puts groups on an object, activated by sector.
/// run this before the gameobject is active.
/// </summary>
public static void Make(GameObject go, Sector sector)
{
if (!sector)
{
Logger.LogWarning($"tried to put groups on {go.name} when sector is null");
return;
}
if (go.activeInHierarchy)
{
Logger.LogWarning($"tried to put groups on an active gameobject {go.name}");
return;
}
go.GetAddComponent<SectorCullGroup>()._sector = sector;
go.GetAddComponent<SectorCollisionGroup>()._sector = sector;
go.GetAddComponent<SectorLightsCullGroup>()._sector = sector;
}
}

View File

@ -1,3 +1,4 @@
using NewHorizons.Builder.General;
using NewHorizons.External.Configs;
using NewHorizons.External.Modules;
using NewHorizons.Handlers;
@ -100,6 +101,7 @@ namespace NewHorizons.Builder.Props
prop.transform.localScale = detail.scale != 0 ? Vector3.one * detail.scale : prefab.transform.localScale;
if (!detail.keepLoaded) GroupsBuilder.Make(prop, sector);
prop.SetActive(true);
if (prop == null) return null;

View File

@ -96,6 +96,7 @@ namespace NewHorizons.Builder.Props
{
position = point.normalized * height,
scale = propInfo.scale,
keepLoaded = propInfo.keepLoaded,
alignToNormal = true
};
var prop = DetailBuilder.Make(go, sector, prefab, detailInfo);

View File

@ -139,6 +139,11 @@ namespace NewHorizons.External.Modules
/// The highest height that these objects will be placed at (only relevant if there's a heightmap)
/// </summary>
public float? maxHeight;
/// <summary>
/// Should this detail stay loaded even if you're outside the sector (good for very large props)
/// </summary>
public bool keepLoaded;
}
[JsonObject]

View File

@ -1391,6 +1391,10 @@
],
"description": "The highest height that these objects will be placed at (only relevant if there's a heightmap)",
"format": "float"
},
"keepLoaded": {
"type": "boolean",
"description": "Should this detail stay loaded even if you're outside the sector (good for very large props)"
}
}
},