Skip to main content

BorderDefinedAtmosphere

A class in Root.Township, Alta.Environmental.Atmosphere.

Client: an area outlined by corner transforms that blends the atmosphere from an outside set to an inside set as the local player walks in from the border.

Constructors​

MemberWhat it is
BorderDefinedAtmosphere()Unity makes components itself; use AddComponent or spawn a prefab instead of new.

Fields​

13 private and internal fields
MemberWhat it is
private IEnumerable<LocationChunk> allChunksLocation chunks overlapping the area.
private Bounds borderBoundsBounds around the corners, boundsHeight tall.
private float boundsHeightHeight of the area above the object.
private bool btnAddNewChildInspector button for AddCorner.
private float distanceFromBorderToConsiderInsideDistance in from the border over which the blend goes from outside to fully inside.
private AtmosphereSet insideSetAtmosphere used inside the area.
private bool isCheckingAtEndOfFrameGuards against more than one recheck per frame.
private static readonly Logger loggerLogger for this class.
private Transform[] orderedBorderCornersCorner transforms in order around the outline.
private AtmosphereSet outsideSetAtmosphere used outside the area.
private IUnityUpdateMethod updatePlayerPositionRegistered per-frame check, while the player is near.
private Vector3[] verticesPositionsCached corner positions.
private bool wasLocalPlayerWithinAreaMeant to track the last inside state; never set in this build, so it stays false.

Methods​

21 private and internal methods
MemberWhat it is
private void AddCorner()Editor button: adds a new corner child halfway between the first and last corners.
private async void CheckPlayer(bool hasPlayer)Handler for a covered chunk gaining or losing the local player; rechecks at most once a frame.
private void ClampCorners()Flattens every corner to local height 0.
private float DistaceToBorderY(Vector3 point)Distance from the point to the top of the area bounds.
private float DistanceToBorderXZ(Vector3 point)Horizontal distance from the point to the nearest border edge.
private void DrawGizmoQuadForLine(Vector3 from, Vector3 to, Color color)Empty in this build.
private void DrawGizmos(Color color)Editor: flattens the corners and refreshes the bounds for gizmo drawing.
private Vector3[] GetVerticesPositions()The corner positions at the object's height, refreshed if any corner moved.
private bool IsLocalPlayerWithinArea()True if any chunk overlapping the area has the local player.
private bool NeedToUpdatePositions()True if a corner was added, removed or moved.
private void OnDisable()Unhooks the local player and chunk events.
private void OnDrawGizmos()Editor gizmo, faint.
private void OnDrawGizmosSelected()Editor gizmo when selected.
private void OnEnable()Client: sets up now, or once the local player exists.
private void OnLocalPlayerSet(PlayerController player)Sets up once the local player is created.
private void SetAmbienceValue(float outsideToInsideRatio)Blends ambient colour between the two sets by the ratio and crossfades their ambience audio.
private void Setup()Works out the bounds, finds the chunks overlapping them and listens for the local player in them.
private void UpdateBounds()Fits the bounds around the corners, extending boundsHeight above the object.
private void UpdatePlayerInsideZone()Starts the per-frame position check when the player is in a covered chunk, otherwise resets to outside.
private void UpdatePlayerPosition()Per frame: works out how far inside the border the player is and sets the blend.
private void UpdatePositions()Copies the corner positions, flattened to the object's height.