Skip to main content

StatBarSimple

A class in Root.Township, Alta.StatSystem.

A stat bar (such as health or hunger) drawn by one renderer's shader: a fill, a trailing change band that lerps after it, and optional corner notches. Client side.

Constructors​

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

Fields​

MemberWhat it is
protected readonly int _AlphaLimitShader property ID for _AlphaLimit.
protected StatBarSimple.MaterialValue fillThe animated fill value (_FillProgress).
protected float lastMaximumStarts at -1. Not changed in this class; for subclasses to track the stat maximum.
9 private and internal fields
MemberWhat it is
private Renderer barRendererThe bar's renderer; its material is copied per instance.
private bool buildUpchangeIf true, a drop doesn't reset the negative change marker to the last value.
private AltaCoroutine changeAnimationThe running AnimateValues coroutine.
private Renderer[] cornersCorner (notch) renderers that share CornerMaterial.
private float decreaseLerpSpeedSpeed of the negative change marker.
private float increaseLerpSpeedSpeed of the fill and positive change marker.
private bool isUsingPositiveChangeIf true, the bar shows a positive change marker; otherwise its shader value stays 0.
private StatBarSimple.MaterialValue negativeChangeShader value _NegativeChangeProgress, the trailing marker after a loss.
private StatBarSimple.MaterialValue positiveChangeShader value _PositiveChangeProgress, used only when isUsingPositiveChange is on.

Properties​

MemberWhat it is
Material CornerMaterial { get; private set; }The material shared by the corner (notch) renderers.
Material Material { get; private set; }The bar's own material copy, whose fill values are set.

Events​

MemberWhat it is
event StatBarSimple.IsLerping LerpingRaised each frame while animating. Handlers set the flag to keep the animation going.

Methods​

MemberWhat it is
virtual void ForceNotchMaterial(Material notchesMaterial)Puts a given material on all corner renderers.
override void Initialize()Copies the bar and corner materials and sets the fill and change values from the tracked stat.
override void SetAlpha(float alphaMultiplier)Sets _AlphaLimit on the bar and corner materials as well as the base alpha.
protected override void OnStatChanged(Stat stat)Updates the fill and change bands to the stat's new value and starts the animation.
protected override void SetRenderersEnabled(bool isEnabled)Shows or hides the bar and corner renderers.
4 private and internal methods
MemberWhat it is
private IEnumerator AnimateValues() (iterator)Coroutine that runs the Lerping handlers each frame until none of the material values is still moving.
private void OnBecameInvisible()Disables the bar when its renderer goes off screen, unless a photo is being taken.
private void OnBecameVisible()Re-enables the bar when its renderer comes on screen, unless a photo is being taken.
private void UpdateValue(Stat stat)Sets the fill and change shader values from the stat's new value; drops snap at once, gains lerp in.

Used in​

Members of other types that take, return or hold a StatBarSimple: