Class AudioWaveform
A presentational waveform envelope with an optional playhead.
Implements
Inherited Members
Namespace: Unity.AppUI.UI
Assembly: Unity.AppUI.dll
Syntax
[UxmlElement]
public class AudioWaveform : VisualElement, IEventHandler, IResolvedStyle, ITransform, ITransitionAnimations, IExperimentalFeatures, IVisualElementScheduler
Remarks
AudioWaveform is a pure display element: the caller owns the peak data, the playback state and any polling or animation. It draws one mirrored vertical bar per entry in peaks around a faint centre baseline, and — when progress is set — a playhead line at that fraction of the width.
Use it to preview an audio clip in an inspector, a browser row or a timeline. It knows nothing
about AudioClip, so it works just as well for a precomputed envelope shipped alongside
an asset as for peaks sampled live.
Rendering.
The waveform is stroked straight into the element's mesh with Painter2D, the same path CanvasEdge and AnimationCurveField take. It needs neither a shader nor a render texture: those are only warranted for a full-surface fill such as ColorWheel's. A stroked envelope is exactly what Painter2D is for.
Colours.
Everything the painter draws is read in C#, so no colour may be a literal. All three come from
custom style properties that AudioWaveform.uss binds to App UI tokens —
--waveform-color, --waveform-baseline-color and --waveform-playhead-color —
the same pattern as Progress's --progress-color. The C# fields start at
clear so a stylesheet that fails to resolve is visible rather than plausible.
Example
var waveform = new AudioWaveform
{
peaks = new List<float> { 0.1f, 0.4f, 0.9f, 0.6f, 0.2f },
progress = new Optional<float>(0.35f),
};
UXML
<appui:AudioWaveform progress="0.35" />
Constructors
AudioWaveform()
Default constructor.
Declaration
public AudioWaveform()
Fields
strokeWidth
The width of a waveform bar and of the playhead, in points.
Declaration
public const float strokeWidth = 1
Field Value
| Type | Description |
|---|---|
| float |
Remarks
A hairline, matching the registry's non-scaling 1px stroke. It is a stroke width in code rather than a layout dimension, so it is not a token-backed length.
ussClassName
The AudioWaveform main styling class.
Declaration
public const string ussClassName = "appui-audio-waveform"
Field Value
| Type | Description |
|---|---|
| string |
Properties
peaks
The normalized peak amplitudes, in the [0, 1] range, one mirrored vertical bar each.
Declaration
[CreateProperty]
[UxmlAttribute]
public List<float> peaks { get; set; }
Property Value
| Type | Description |
|---|---|
| List<float> |
Remarks
Never null. Assigning null empties the list rather than replacing it, so a caller can hold
on to the collection. Values outside [0, 1] are clamped when drawn, and a peak of
zero or less draws no bar at all, so silence reads as the bare baseline.
progress
The playhead position, as a [0, 1] fraction of the clip. Unset hides the playhead.
Declaration
[CreateProperty]
[UxmlAttribute]
public Optional<float> progress { get; set; }
Property Value
| Type | Description |
|---|---|
| Optional<float> |
resolvedBaselineColor
The centre baseline colour resolved from --waveform-baseline-color.
Declaration
public Color resolvedBaselineColor { get; }
Property Value
| Type | Description |
|---|---|
| Color |
resolvedPlayheadColor
The playhead colour resolved from --waveform-playhead-color.
Declaration
public Color resolvedPlayheadColor { get; }
Property Value
| Type | Description |
|---|---|
| Color |
resolvedWaveformColor
The bar colour resolved from --waveform-color.
Declaration
public Color resolvedWaveformColor { get; }
Property Value
| Type | Description |
|---|---|
| Color |