Class VuMeter
A slim vertical audio level meter: a dB ruler, one or two thin level bars, an optional peak-hold line, and a draggable attenuation marker.
Implements
Inherited Members
Namespace: Unity.AppUI.UI
Assembly: Unity.AppUI.dll
Syntax
[UxmlElement]
public class VuMeter : VisualElement, IEventHandler, IResolvedStyle, ITransform, ITransitionAnimations, IExperimentalFeatures, IVisualElementScheduler
Remarks
VuMeter mirrors the meter beside a channel strip in Unity's Audio Mixer. It is presentational:
feed it live levels and it paints them. It never reads an AudioMixer itself,
so it is equally usable for a microphone preview, a VOIP indicator or a test signal.
The level colour is anchored to fader rather than to a fixed dB: safe well below the marker, warning as the level approaches it, clipping once it passes. Move the fader and the bands move with it, which is what makes the meter readable at any attenuation.
Rendering.
Each channel bar is stroked and filled into its own mesh with Painter2D, the same path CanvasEdge and AnimationCurveField take, because the fill is a banded gradient that USS cannot express. A shader would be overkill for a few filled rectangles; those are reserved for full-surface fills like ColorWheel's. The ruler, the marker chip and the readout are ordinary elements, styled from USS.
Colours.
Every colour the painter uses is read in C#, so none may be a literal. They come from custom
style properties that VuMeter.uss binds to App UI tokens, and the C# fields start at
clear so an unresolved stylesheet is visible rather than plausible.
Example
var meter = new VuMeter { levels = new List<float> { -12f, -18f }, fader = -6f };
meter.faderChanged += db => mixer.SetFloat("Volume", db);
UXML
<appui:VuMeter min="-80" max="20" show-readout="true" />
Constructors
VuMeter()
Default constructor.
Declaration
public VuMeter()
Fields
barUssClassName
One channel bar.
Declaration
public const string barUssClassName = "appui-vu-meter__bar"
Field Value
| Type | Description |
|---|---|
| string |
barsUssClassName
The container the per-channel bars live in.
Declaration
public const string barsUssClassName = "appui-vu-meter__bars"
Field Value
| Type | Description |
|---|---|
| string |
bodyUssClassName
The row holding the meter group and the ruler.
Declaration
public const string bodyUssClassName = "appui-vu-meter__body"
Field Value
| Type | Description |
|---|---|
| string |
defaultMax
The default top of the scale, in dB.
Declaration
public const float defaultMax = 20
Field Value
| Type | Description |
|---|---|
| float |
defaultMin
The default bottom of the scale, in dB.
Declaration
public const float defaultMin = -80
Field Value
| Type | Description |
|---|---|
| float |
dragLaneUssClassName
The invisible lane that accepts the fader drag.
Declaration
public const string dragLaneUssClassName = "appui-vu-meter__drag-lane"
Field Value
| Type | Description |
|---|---|
| string |
markerArrowUssClassName
The marker's arrow head.
Declaration
public const string markerArrowUssClassName = "appui-vu-meter__marker-arrow"
Field Value
| Type | Description |
|---|---|
| string |
markerLabelUssClassName
The marker's numeric chip.
Declaration
public const string markerLabelUssClassName = "appui-vu-meter__marker-label"
Field Value
| Type | Description |
|---|---|
| string |
markerUssClassName
The attenuation marker.
Declaration
public const string markerUssClassName = "appui-vu-meter__marker"
Field Value
| Type | Description |
|---|---|
| string |
meterUssClassName
The meter group: bars, peak line and the attenuation marker.
Declaration
public const string meterUssClassName = "appui-vu-meter__meter"
Field Value
| Type | Description |
|---|---|
| string |
noReadoutUssClassName
The styling class applied when the numeric readout is hidden.
Declaration
public const string noReadoutUssClassName = "appui-vu-meter--no-readout"
Field Value
| Type | Description |
|---|---|
| string |
readoutUssClassName
The numeric level readout under the meter.
Declaration
public const string readoutUssClassName = "appui-vu-meter__readout"
Field Value
| Type | Description |
|---|---|
| string |
rulerUssClassName
The dB ruler.
Declaration
public const string rulerUssClassName = "appui-vu-meter__ruler"
Field Value
| Type | Description |
|---|---|
| string |
tickDashUssClassName
A ruler row's dash.
Declaration
public const string tickDashUssClassName = "appui-vu-meter__tick-dash"
Field Value
| Type | Description |
|---|---|
| string |
tickLabelUssClassName
A ruler row's label.
Declaration
public const string tickLabelUssClassName = "appui-vu-meter__tick-label"
Field Value
| Type | Description |
|---|---|
| string |
tickUssClassName
One ruler row: a dash plus its label.
Declaration
public const string tickUssClassName = "appui-vu-meter__tick"
Field Value
| Type | Description |
|---|---|
| string |
ussClassName
The VuMeter main styling class.
Declaration
public const string ussClassName = "appui-vu-meter"
Field Value
| Type | Description |
|---|---|
| string |
warningRange
How far below the fader the warning band starts, in dB.
Declaration
public const float warningRange = 12
Field Value
| Type | Description |
|---|---|
| float |
Properties
barCount
The number of channel bars currently painted.
Declaration
public int barCount { get; }
Property Value
| Type | Description |
|---|---|
| int |
barsElement
The container the channel bars live in.
Declaration
public VisualElement barsElement { get; }
Property Value
| Type | Description |
|---|---|
| VisualElement |
contentContainer
Logical container where child elements are added. If a child is added to this element, the child is added to this element's content container instead.
Declaration
public override VisualElement contentContainer { get; }
Property Value
| Type | Description |
|---|---|
| VisualElement |
Overrides
fader
The attenuation fader, in dB. Always inside min..max, and the anchor the level colour bands are measured from.
Declaration
[CreateProperty]
[UxmlAttribute]
public float fader { get; set; }
Property Value
| Type | Description |
|---|---|
| float |
levels
The per-channel levels, in dB. One bar each; an empty list still paints a single silent bar.
Declaration
[CreateProperty]
[UxmlAttribute]
public List<float> levels { get; set; }
Property Value
| Type | Description |
|---|---|
| List<float> |
markerElement
The attenuation marker.
Declaration
public VisualElement markerElement { get; }
Property Value
| Type | Description |
|---|---|
| VisualElement |
max
The top of the scale, in dB.
Declaration
[CreateProperty]
[UxmlAttribute]
public float max { get; set; }
Property Value
| Type | Description |
|---|---|
| float |
min
The bottom of the scale, in dB.
Declaration
[CreateProperty]
[UxmlAttribute]
public float min { get; set; }
Property Value
| Type | Description |
|---|---|
| float |
peak
The peak-hold marker, in dB. Unset hides it.
Declaration
[CreateProperty]
[UxmlAttribute]
public Optional<float> peak { get; set; }
Property Value
| Type | Description |
|---|---|
| Optional<float> |
readoutElement
The numeric level readout.
Declaration
public LocalizedTextElement readoutElement { get; }
Property Value
| Type | Description |
|---|---|
| LocalizedTextElement |
resolvedClipColor
The clipping colour resolved from --vu-meter-clip-color.
Declaration
public Color resolvedClipColor { get; }
Property Value
| Type | Description |
|---|---|
| Color |
resolvedFaderColor
The fader marker colour resolved from --vu-meter-fader-color.
Declaration
public Color resolvedFaderColor { get; }
Property Value
| Type | Description |
|---|---|
| Color |
resolvedPeakColor
The peak-hold colour resolved from --vu-meter-peak-color.
Declaration
public Color resolvedPeakColor { get; }
Property Value
| Type | Description |
|---|---|
| Color |
resolvedSafeColor
The safe-level colour resolved from --vu-meter-safe-color.
Declaration
public Color resolvedSafeColor { get; }
Property Value
| Type | Description |
|---|---|
| Color |
resolvedTrackColor
The empty-track colour resolved from --vu-meter-track-color.
Declaration
public Color resolvedTrackColor { get; }
Property Value
| Type | Description |
|---|---|
| Color |
resolvedWarningColor
The approaching-clip colour resolved from --vu-meter-warning-color.
Declaration
public Color resolvedWarningColor { get; }
Property Value
| Type | Description |
|---|---|
| Color |
rulerElement
The dB ruler.
Declaration
public VisualElement rulerElement { get; }
Property Value
| Type | Description |
|---|---|
| VisualElement |
showReadout
Whether the numeric level readout shows under the meter.
Declaration
[CreateProperty]
[UxmlAttribute]
public bool showReadout { get; set; }
Property Value
| Type | Description |
|---|---|
| bool |
ticks
The dB values the ruler marks. Rebuilt in full whenever it is assigned.
Declaration
[CreateProperty]
[UxmlAttribute]
public List<float> ticks { get; set; }
Property Value
| Type | Description |
|---|---|
| List<float> |
Events
faderChanged
Raised whenever the fader lands on a new value, whether set in code or dragged.
Declaration
public event Action<float> faderChanged
Event Type
| Type | Description |
|---|---|
| Action<float> |