Skip to main content

GrassManager

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

Networked wind for grass and clouds: scrolls a wind map and sets global shader values. The server syncs speed, strength, direction and offset to clients every 90 seconds. Use the static instance.

Constructors​

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

Fields​

MemberWhat it is
static GrassManager instanceThe last GrassManager to wake.
20 private and internal fields
MemberWhat it is
private List<WindPattern> availablePatternsBacking field for AvailablePatterns.
private float cloudsRotationCloud rotation as a fraction of a turn, wrapping at 1.
private float cloudsSpeedMultiplierScales how fast clouds turn with the wind.
private float directionChangeLerpSpeedLerp amount per frame when turning; 1 snaps at once.
private bool isCatchingUpClient: true while moving toward the server's offset.
private bool isLerpingDirectionTrue while turning toward newDirection.
private float maxValueToLerpSquared offset gap above which clients snap instead of catching up.
private float networkCloudRotationCloud rotation from the last sync.
private Vector2 newDirectionDirection being turned toward.
private const float SendIntervalSeconds between syncs, 90.
private MethodSyncStruct<bool> syncSync message for the wind state.
private Vector2 windDirectionBacking field for WindDirection.
private Texture2D windMapWind noise texture given to shaders as _WindMap.
private Vector2 windMapOffsetCurrent scroll offset of the wind map.
private Vector2 windMapOffsetNetworkWind map offset from the last sync.
private float windMapScaleWorld size of one wind map tile; shaders get its inverse.
private float windSpeedBacking field for WindSpeed.
private float windStrengthBacking field for WindStrength.
private float worldPositionSerialized world origin. Not read in this build.
private float worldSizeWorld size used to turn wind movement into cloud rotation.

Properties​

MemberWhat it is
List<WindPattern> AvailablePatterns { get; }Wind patterns that can be applied with ReadPattern.
Vector2 WindDirection { get; set; }Wind direction on the ground plane. Setting it updates the shader off headless.
float WindSpeed { get; }How fast the wind map scrolls.
float WindStrength { get; }How strongly grass bends.

Methods​

MemberWhat it is
override void Initialize()Creates the sync message.
override void InitializeAsServer(SpawnData spawnData)Server: starts the 90-second sync loop.
override void OnConnected(Player player)Server: sends the wind state to a joining player with snapping on.
void ReadPattern(WindPattern pattern)Applies a pattern's speed and strength (not direction) and syncs it to clients.
protected void Awake()Sets instance and the global wind map shader values; on headless drops the wind map.
9 private and internal methods
MemberWhat it is
private void ChangeWindDirection(Vector2 direction)Starts turning toward a new (normalized) direction. Private, no callers here.
private void ChangeWindSpeed(float speed)Sets the wind speed, not below 0.
private void ChangeWindStrength(float strength)Sets the wind strength, not below 0, and updates the shader.
private void OnValidate()Editor: normalizes the direction and updates the shader.
private void Sync(IPlayer player, Stream stream, bool isSnapping)Writes or reads the wind state. Clients snap if told to or if far off, otherwise catch up smoothly.
private IEnumerator SyncToClients() (iterator)Server coroutine that syncs to all chunks every 90 seconds.
private void Update()Lerps the direction, scrolls the wind map and cloud rotation by speed, catches up to the server value, and updates shaders.
private void UpdateShader()Sets the global cloud rotation values from cloudsRotation, then the wind parameters.
private void UpdateWindParameters()Sets the global _WindParameters: wind map offset and direction times strength.