Skip to main content

DarknessSpawnerSettings

A class in Root.Township, the global namespace.

Global settings for spawning creatures in the dark around players. The local client measures screen darkness and asks the server, which spawns near the player.

Constructors​

MemberWhat it is
DarknessSpawnerSettings()Use ScriptableObject.CreateInstance instead of new; Unity loads the saved ones from assets.

Fields​

20 private and internal fields
MemberWhat it is
private Vector3 colorFilterColour weights used when measuring darkness.
private ComputeShader computeShaderCompute shader that measures how dark the view is.
private float darkDefinitionBrightness below which a pixel counts as dark.
private float directionMagnitudeLength of the raw spawn ray direction, used to normalise it.
private float downSampleScaleScale of the downsampled image used to measure darkness.
private float forwardWeightHow strongly spawn rays point forward from the head. Higher means a narrower cone.
private float maxAngleToSpawnMinimum surface normal Y for a spawn, set from an angle in the inspector.
private float maximumSpawnIntervalLongest wait between spawns in one batch.
private float maxTotalDarknessDarkness reading above which the compute shader reader triggers a spawn, 0 to 1.
private float minimumSpawnIntervalShortest wait between spawns in one batch.
private float platformLightRangeRatioMultiplier on light ranges used by PlatformLightDarknessReader.
private Dictionary<uint, int> playerSpawnCountLive spawned count per player ID.
private uint prefabToSpawnHash of the prefab spawned in the dark.
private float raycastDistanceHow far from the head spawn rays reach.
private float readDarknessFrequencySeconds between darkness readings. Defaults to 60.
private float spawnCooldownObsolete cooldown field. Not read here.
private TriangularDistributionInt spawnCountRandom number of spawns tried per batch.
private Dictionary<uint, uint> spawnedToPlayerWhich player each spawned entity belongs to.
private int spawnLimitPerPlayerMost live spawns one player can have. Defaults to 10.
private LayerMask targetMaskLayers spawn rays can land on.

Properties​

MemberWhat it is
Vector3 ColorFilter { get; }Weights for the colour channels when the compute shader measures darkness.
ComputeShader ComputeShader { get; }The compute shader that reads screen darkness.
float DarkDefinition { get; }Brightness below which a pixel counts as dark.
float DownSampleScale { get; }Fraction of screen resolution the darkness is read at.
float MaxTotalDarkness { get; }When the measured darkness is above this, the client asks the server to spawn.
float PlatformLightRangeRatio { get; }Scales light ranges in the platform light darkness reader.
float ReadDarknessFrequency { get; }Seconds between darkness reads.

Methods​

MemberWhat it is
bool SpawnForPlayer(PlayerController playerCharacter)Server: raycasts ahead of the player's view and spawns the prefab on suitable surfaces, up to the per-player limit. Returns whether any spawned.
3 private and internal methods
MemberWhat it is
private void ClearForPlayer(NetworkEntity entity, bool isUnload)When a spawned entity is destroyed, lowers the count for the player it was spawned for.
private void OnValidate()Recomputes directionMagnitude from forwardWeight.
private IEnumerator SpawnForPlayer(PlayerController playerCharacter, List<DarknessSpawnerSettings.SpawnInstructure> spawnPositions) (iterator)Server: raycasts ahead of the player's view and spawns the prefab on suitable surfaces, up to the per-player limit. Returns whether any spawned.

Used in​

Members of other types that take, return or hold a DarknessSpawnerSettings: