LiquidSurfaceVisual
An abstract class in Root.Township, Alta.Liquid.
Base for the liquid surface inside a container. It tracks how far the container is tipped (through LiquidGravity) and how full it is, and on clients draws the surface. It also stays active on the server, where the tip state is still updated.
- Listed in Stats, effects, heat and liquid
- Inherits or implements
MonoBehaviour,IBuildRendererPostBake,IBuildBakeable - Derived types
CookingLiquidVisual,BottledLiquid
Constructors
| Member | What it is |
|---|---|
protected LiquidSurfaceVisual() | Unity makes components itself; use AddComponent or spawn a prefab instead of new. |
Fields
20 private and internal fields
| Member | What it is |
|---|---|
private VisibilityDetector androidContainerLod0 | Visibility detector kept from an older field name; not used in code in this build. |
private static readonly int ColorId | Shader ID of _Color. |
private VisibilityDetector containerLod0 | Visibility detector on the container's main LOD; the surface only updates while it is visible (always on the server). |
private Renderer dynamicRenderer | The renderer of the moving liquid surface. Backing field for DynamicRenderer. |
private MaterialPropertyBlock dynamicRendererPropertyBlock | Property block set on the surface renderer from the current liquid. Backing field for DynamicRendererPropertyBlock. |
private Material dynamicRendererTemplateMaterial | The surface renderer's original material, used as the template for each liquid's material. |
private FloatEvent fullnessChanged | Event raised with the new fullness value; exposed as FullnessChanged. |
private float fullyPouringLimit | Tip value above which the container counts as fully pouring. |
private LiquidGravity liquidGravity | Simulates the liquid sloshing and tipping as the container moves. Backing field for LiquidGravity. |
private MaterialPropertyBlock lodPropertyBlock | Property block set on the lower LOD renderers from the current liquid. |
private Renderer[] otherLods | Renderers for the lower LODs of the liquid; shown only while there is liquid. |
private float tip | Read-only inspector value showing the current tip. |
private float tippingThreshold | Tip value at which the liquid starts to pour. Backing field for TippingThreshold. |
private float tippingValue | Read-only inspector value for tipping; not written in this build. |
private static UpdateModule updateModule | Late update module that runs UpdateVisual while the liquid is moving. |
private IUnityUpdateMethod visualLoop | Handle of the registered UpdateVisual loop. |
private float visualTipLimit | Limit on how far the surface visually tips. Backing field for VisualTipLimit. |
private float volumeClamp | Fullness is multiplied by this before the volume curve, so the surface never looks fuller than this. |
private AnimationCurve volumeCurve | Maps the container's fill amount to the visual fullness. |
private bool wasMoving | Moving state from the last fixed update, used to start and stop the visual loop. |
Properties
| Member | What it is |
|---|---|
Renderer DynamicRenderer { get; } | The renderer that draws the moving liquid surface. |
Material DynamicRendererMaterial { get; internal set; } | Instance material of the dynamic renderer, made in SetLiquid. |
MaterialPropertyBlock DynamicRendererPropertyBlock { get; } | Property block used on the dynamic renderer. |
float Fullness { get; private set; } | How full it looks, 0 to 1, after the volume curve. |
bool IsContainerVisible { get; private set; } | True while the container's LOD 0 is visible. |
bool IsContainingLiquid { get; private set; } | True above 1% fullness. |
bool IsFullyPouring { get; } | True when tipped past the fully pouring limit. |
bool IsMoving { get; private set; } | True while the liquid surface is still moving. |
virtual bool IsUsingUpdateLoop { get; } | Whether UpdateVisual runs while moving. True by default. |
LiquidData Liquid { get; private set; } | The liquid shown. |
LiquidGravity LiquidGravity { get; } | Tracks the tip and movement of the liquid. |
List<Renderer> OtherRendererLODs { get; } | Lower LOD renderers for the liquid, shown only when there is liquid. |
float TippingThreshold { get; set; } | Tip value at which the container starts to pour. |
float VisualTipLimit { get; set; } | Tip limit used for the surface visuals. |
Events
| Member | What it is |
|---|---|
event Action DynamicRendererMaterialUpdated | Raised after the materials change for a new liquid. |
event Action<float> FullnessChanged | Raised with the new fullness. |
event LiquidDataEventHandler LiquidChanged | Raised when SetLiquid sets a new liquid. |
Methods
| Member | What it is |
|---|---|
virtual void SetFullness(float fullness) | Sets how full it is (through the volume curve) and shows or hides the liquid. |
virtual void SetLiquid(LiquidData liquid) | Shows a new liquid: sets thickness and materials and raises LiquidChanged. |
protected virtual void Awake() | Sets up property blocks and the tip tracker, and listens for the container becoming visible. |
protected virtual void FixedUpdate() | Updates the tip tracker, and on clients starts or stops the visual update when movement starts or stops. |
protected virtual void HandleInvisible() | Called when the container goes out of view. Stays enabled on the server. |
protected virtual void HandleVisible() | Called when the container comes into view; enables the visual if there is liquid. |
protected virtual void OnDisable() | Hides the surface and stops the visual update. |
protected virtual void OnEnable() | Resets the tip tracker, shows the surface and starts the visual update on clients. |
protected virtual void OnValidate() | Pushes inspector changes to the tip tracker while playing. |
protected abstract void SetLODRendererPropertyBlockFromLiquid(MaterialPropertyBlock propertyBlock, LiquidData liquid) | Fills a property block for the LOD renderers from a liquid. Subclasses implement it. |
protected void SetMaterialsAcordingToLiquid(LiquidData liquid) | Applies the liquid's material and property blocks to the dynamic and LOD renderers. |
protected abstract void SetPropertyBlockFromLiquid(MaterialPropertyBlock propertyBlock, LiquidData liquid) | Fills a property block from a liquid. Subclasses implement it. |
protected abstract Material SetupMaterialFromLiquidVisualSettings(LiquidVisualData visualSettings, Material materialTemplate) | Builds the shared material for a liquid visual from the template. Subclasses implement it. |
protected abstract void UpdateVisual() | Redraws the surface while it moves. Subclasses implement it. |
2 private and internal methods
Used in
Members of other types that take, return or hold a LiquidSurfaceVisual: