Skip to main content

LiquidStencilShaderController

A class in Root.Township, Alta.Liquid.

Client: gives a liquid container's volume and surface renderers a stencil number from a shared pool while it's visible and has liquid, and releases it otherwise.

Constructors​

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

Fields​

8 private and internal fields
MemberWhat it is
private ILiquidContainer containerThe liquid container on this object.
private bool isStencilAssignedWhether a stencil number is held.
private int stencilNumberThe held stencil number.
private Renderer surfaceRendererLiquid surface renderer.
private MaterialPropertyBlock surfaceRendererPropertyBlockThe surface visual's property block.
private Renderer volumeRendererLiquid volume renderer.
private MaterialPropertyBlock volumeRendererPropertyBlockProperty block for the volume renderer.
private VisibilityDetector volumeVisibilityDetectorTells when the volume becomes visible or not.

Methods​

9 private and internal methods
MemberWhat it is
private void Awake()Gets the container and listens for its surface material changing.
private void CheckForStencil()Takes a stencil number when visible with liquid, otherwise releases it.
private void HandleLiquidLevelChanged(ILiquidContainer container)Rechecks the stencil when the shown amount changes.
private void OnDisable()Unhooks the liquid level and visibility events.
private void OnEnable()Hooks the liquid level and visibility events.
private void ReleaseStencilBufferNumber()Gives the stencil number back to the pool.
private void SetRenderersStencilBufferNumber(bool isForced)Takes a stencil number (if none or forced) and sets it on both materials.
private void Start()Checks the stencil and sets up property blocks.
private void UpdateStencilOnNewMaterial()Assigns a fresh stencil number when the surface material is replaced.