Table of Contents

Class CoverVolume

Namespace
DFA.Puddlecraft

A box that tells Puddlecraft how sheltered a space is: indoors, under an arcade, behind a door. The rain sound is muffled only by the volumes the audio listener is inside, so an interior sounds indoors exactly where a volume says so and nowhere else. With Blocks Rain on, the box's top also keeps rain off whatever is under it.

The box is defined like a Box Collider (Center and Size, in the object's local space) and follows the object's position, rotation and scale.

Volumes nest through the hierarchy. A volume parented under another, such as a doorway inside a building, overrides its parent inside its own box, blending in from its faces over the Falloff distance. A nested volume only counts inside the volumes it is parented under, so a doorway's box can extend out through the door to start its falloff outside without muffling the street.

Cover is how muffled the rain sounds, from 0 (as loud as out in the open) to 1 (as muffled as fully indoors). The inspector shows it inverted, as a Rain Sound slider from quiet to loud. Most volumes only need coverClosed. For a door or window, a script or animation sets openness, which moves the cover from coverClosed (at 0) to coverOpen (at 1).

[ExecuteAlways]
[DisallowMultipleComponent]
[AddComponentMenu("Puddlecraft/Cover Volume")]
[Icon("Packages/com.dfa.puddlecraft/editor/icons/cover-volume.png")]
public sealed class CoverVolume : PuddlecraftBehaviour
Inheritance
CoverVolume

Properties

blocksRain

Keeps rain off everything under the box, like an invisible roof: rain, splashes, raindrop ripples and wet ground all treat it as cover. Rebake the rain cover after changing it in Baked mode.

public bool blocksRain { get; set; }

Property Value

bool

boxToWorld

The box in world space: local-to-world for a unit cube centred on the origin.

public Matrix4x4 boxToWorld { get; }

Property Value

Matrix4x4

center

Centre of the box, in the object's local space.

public Vector3 center { get; set; }

Property Value

Vector3

cover

The volume's cover right now: between coverClosed and coverOpen, by openness.

public float cover { get; }

Property Value

float

coverClosed

How muffled the rain sounds inside with openness at 0, from 0 (as loud as out in the open) to 1 (as muffled as fully indoors). The only cover most volumes need.

public float coverClosed { get; set; }

Property Value

float

coverOpen

How muffled the rain sounds inside with openness at 1 (a door or window wide open), from 0 to 1 like coverClosed.

public float coverOpen { get; set; }

Property Value

float

falloff

How far in from its faces the volume blends in, in metres (0 or more).

public float falloff { get; set; }

Property Value

float

nestingDepth

How many Cover Volumes this one is nested in, through its parents in the Hierarchy.

public int nestingDepth { get; }

Property Value

int

openness

Moves the cover from coverClosed (0) to coverOpen (1), for a door or window being opened.

public float openness { get; set; }

Property Value

float

priority

Breaks ties between volumes at the same nesting depth: the higher priority wins.

public int priority { get; set; }

Property Value

int

size

Size of the box, in the object's local space (each axis 0 or more). The object's scale applies on top.

public Vector3 size { get; set; }

Property Value

Vector3

Methods

Contains(Vector3)

Whether a world position is inside the box.

public bool Contains(Vector3 worldPosition)

Parameters

worldPosition Vector3

Returns

bool

CoverAt(Vector3)

How sheltered a world position is, from 0 (out in the rain, or in no volume) to 1 (fully indoors). The volumes it is in are blended from the outermost in, each over its falloff, so nested volumes win.

public static float CoverAt(Vector3 worldPosition)

Parameters

worldPosition Vector3

Returns

float

InnermostAt(Vector3)

The innermost volume containing a world position (the one that wins there), or null.

public static CoverVolume InnermostAt(Vector3 worldPosition)

Parameters

worldPosition Vector3

Returns

CoverVolume

TryGetTop(float, float, out float)

The top of the box straight above or below (x, z), in world space: where a vertical line through the point first meets it coming down. False when the line misses the box, or the box is flat (zero size or scale on an axis).

public bool TryGetTop(float x, float z, out float height)

Parameters

x float
z float
height float

Returns

bool

WeightAt(Vector3)

How much the volume counts at a world position: 0 outside, rising to 1 at Falloff metres in from the nearest face.

public float WeightAt(Vector3 worldPosition)

Parameters

worldPosition Vector3

Returns

float