Class CurveEditor
An editable animation-curve graph: drag keys, drag the selected key's tangent handles, double-click to add a key, and pick a preset.
Implements
Inherited Members
Namespace: Unity.AppUI.UI
Assembly: Unity.AppUI.dll
Syntax
public class CurveEditor : VisualElement, IEventHandler, IResolvedStyle, ITransform, ITransitionAnimations, IExperimentalFeatures, IVisualElementScheduler, INotifyValueChanged<AnimationCurve>, ICustomAnimationCurveFieldPicker
Remarks
The editor is the counterpart AnimationCurveField has been waiting for. It implements ICustomAnimationCurveFieldPicker, so assigning one to customPicker turns the field from a read-only curve thumbnail into an editable one — the same way ColorField and ColorPicker pair up.
The curve and the grid are stroked with Painter2D, exactly as AnimationCurveField strokes its thumbnail, so no shader and no render texture are involved. Keys and tangent handles are real elements rather than painted marks, which is what lets them be hit-tested and styled from USS.
The plotted range is taken from the curve on load: time spans the curve's own first and last
key, and value spans [0, 1] widened to fit the curve — the same rule
AnimationCurveField uses, so the thumbnail and the editor frame a curve identically.
Editing clamps into that range rather than growing it, so the graph never moves under the
pointer mid-drag.
Interaction
- Click a key to select it, drag to move it. The first and last key keep their time and move only in value, because they anchor the plotted range.
- Drag a tangent handle to author the slope. Hold
Altto break the handle so the two sides move independently. - Double-click the graph to add a key there.
DeleteorBackspaceremoves the selected key, never the last one.Fflattens it.
Two deliberate divergences from the registry. Tangent modes are chosen from a dropdown in the toolbar rather than from a right-click context menu, because UI Toolkit has no equivalent of the registry's absolutely positioned menu div and a dropdown is the package's own idiom for a mode list. And selection is single-key: there is no marquee box-select, so no group move, group delete or group flatten.
Example
var field = new AnimationCurveField { customPicker = new CurveEditor() };
field.RegisterValueChangedCallback(evt => Debug.Log(evt.newValue));
Constructors
CurveEditor()
Default constructor. Starts on the Ease In-Out preset.
Declaration
public CurveEditor()
Fields
graphUssClassName
The graph styling class.
Declaration
public const string graphUssClassName = "appui-curveeditor__graph"
Field Value
| Type | Description |
|---|---|
| string |
handleRadius
How far from its key a tangent handle sits, in pixels. Fixed rather than proportional so the handle stays grabbable whatever the graph's aspect ratio.
Declaration
public const float handleRadius = 32
Field Value
| Type | Description |
|---|---|
| float |
handleUssClassName
The tangent handle styling class.
Declaration
public const string handleUssClassName = "appui-curveeditor__handle"
Field Value
| Type | Description |
|---|---|
| string |
keyUssClassName
The keyframe marker styling class.
Declaration
public const string keyUssClassName = "appui-curveeditor__key"
Field Value
| Type | Description |
|---|---|
| string |
presetGlyphUssClassName
The preset glyph styling class.
Declaration
public const string presetGlyphUssClassName = "appui-curveeditor__preset-glyph"
Field Value
| Type | Description |
|---|---|
| string |
presetUssClassName
The preset button styling class.
Declaration
public const string presetUssClassName = "appui-curveeditor__preset"
Field Value
| Type | Description |
|---|---|
| string |
presetsUssClassName
The presets row styling class.
Declaration
public const string presetsUssClassName = "appui-curveeditor__presets"
Field Value
| Type | Description |
|---|---|
| string |
selectedKeyUssClassName
The selected keyframe marker styling class.
Declaration
public const string selectedKeyUssClassName = "appui-curveeditor__key--selected"
Field Value
| Type | Description |
|---|---|
| string |
tangentDropdownUssClassName
The tangent mode dropdown styling class.
Declaration
public const string tangentDropdownUssClassName = "appui-curveeditor__tangent-dropdown"
Field Value
| Type | Description |
|---|---|
| string |
toolbarUssClassName
The toolbar styling class.
Declaration
public const string toolbarUssClassName = "appui-curveeditor__toolbar"
Field Value
| Type | Description |
|---|---|
| string |
ussClassName
The CurveEditor main styling class.
Declaration
public const string ussClassName = "appui-curveeditor"
Field Value
| Type | Description |
|---|---|
| string |
Properties
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
graphElement
The element the curve, the grid and the tangent arms are stroked into. Key markers and tangent handles are its children.
Declaration
public VisualElement graphElement { get; }
Property Value
| Type | Description |
|---|---|
| VisualElement |
inTangentHandle
The incoming tangent handle of the selected key. Hidden when nothing is selected.
Declaration
public VisualElement inTangentHandle { get; }
Property Value
| Type | Description |
|---|---|
| VisualElement |
keyMarkers
The key markers, in time order.
Declaration
public IReadOnlyList<VisualElement> keyMarkers { get; }
Property Value
| Type | Description |
|---|---|
| IReadOnlyList<VisualElement> |
outTangentHandle
The outgoing tangent handle of the selected key. Hidden when nothing is selected.
Declaration
public VisualElement outTangentHandle { get; }
Property Value
| Type | Description |
|---|---|
| VisualElement |
plotRect
The area of graphElement the curve is plotted into, in graph-local pixels.
Declaration
public Rect plotRect { get; }
Property Value
| Type | Description |
|---|---|
| Rect |
presets
The available starting shapes.
Declaration
public static IReadOnlyList<CurveEditor.CurvePreset> presets { get; }
Property Value
| Type | Description |
|---|---|
| IReadOnlyList<CurveEditor.CurvePreset> |
presetsElement
The presets row.
Declaration
public VisualElement presetsElement { get; }
Property Value
| Type | Description |
|---|---|
| VisualElement |
selectedKeyIndex
The index of the selected key, or -1 when nothing is selected.
Declaration
public int selectedKeyIndex { get; }
Property Value
| Type | Description |
|---|---|
| int |
tangentElement
The tangent mode dropdown.
Declaration
public Dropdown tangentElement { get; }
Property Value
| Type | Description |
|---|---|
| Dropdown |
value
The curve being edited.
Declaration
[CreateProperty]
public AnimationCurve value { get; set; }
Property Value
| Type | Description |
|---|---|
| AnimationCurve |
Remarks
The getter builds a fresh AnimationCurve on every read, so a consumer holding an earlier value never sees it mutate underneath them.
Methods
AddKey(float, float)
Adds a key and selects it.
Declaration
public bool AddKey(float time, float value)
Parameters
| Type | Name | Description |
|---|---|---|
| float | time | Time of the new key, clamped to the plotted time range. |
| float | value | Value of the new key, clamped to the plotted value range. |
Returns
| Type | Description |
|---|---|
| bool | False when a key already sits at that time. |
ApplyPreset(int)
Replaces the curve with a preset.
Declaration
public void ApplyPreset(int index)
Parameters
| Type | Name | Description |
|---|---|---|
| int | index | Index into presets. |
Dismiss()
Closes the popover this editor was opened in, if any.
Declaration
public void Dismiss()
DomainToPlot(float, float)
Maps a point in curve space onto graphElement's local pixels.
Declaration
public Vector2 DomainToPlot(float time, float value)
Parameters
| Type | Name | Description |
|---|---|---|
| float | time | A time in the plotted range. |
| float | value | A value in the plotted range. |
Returns
| Type | Description |
|---|---|
| Vector2 | The pixel position, with y growing downward. |
GetTangentMode(int)
Returns the tangent mode of a key.
Declaration
public TangentMode GetTangentMode(int index)
Parameters
| Type | Name | Description |
|---|---|---|
| int | index | Index of the key. |
Returns
| Type | Description |
|---|---|
| TangentMode | The key's mode, or Free for an out-of-range index. |
MoveSelectedKey(float, float)
Moves the selected key.
Declaration
public void MoveSelectedKey(float time, float value)
Parameters
| Type | Name | Description |
|---|---|---|
| float | time | Target time. Clamped between the neighbouring keys; ignored for the first and last key, which anchor the plotted time range. |
| float | value | Target value, clamped to the plotted value range. |
PlotToDomain(Vector2)
Maps a point in graphElement's local pixels back into curve space.
Declaration
public Vector2 PlotToDomain(Vector2 local)
Parameters
| Type | Name | Description |
|---|---|---|
| Vector2 | local | A pixel position, with y growing downward. |
Returns
| Type | Description |
|---|---|
| Vector2 | The time in x and the value in y, both unclamped. |
RemoveSelectedKey()
Removes the selected key.
Declaration
public bool RemoveSelectedKey()
Returns
| Type | Description |
|---|---|
| bool | False when nothing is selected, or when it is the only key left. |
SelectKey(int)
Selects a key.
Declaration
public void SelectKey(int index)
Parameters
| Type | Name | Description |
|---|---|---|
| int | index | Index of the key. Out-of-range clears the selection. |
SetTangent(int, TangentSide, float)
Authors one tangent by hand.
Declaration
public void SetTangent(int index, CurveEditor.TangentSide side, float slope)
Parameters
| Type | Name | Description |
|---|---|---|
| int | index | Index of the key. |
| CurveEditor.TangentSide | side | Which tangent to set. |
| float | slope | The slope, in value units per time unit. |
Remarks
On a Broken key only the named side moves. On any other mode the key becomes Free and both sides take the slope, which keeps the curve smooth through the key.
SetTangentMode(int, TangentMode)
Sets the tangent mode of a key and re-derives its tangents.
Declaration
public void SetTangentMode(int index, TangentMode mode)
Parameters
| Type | Name | Description |
|---|---|---|
| int | index | Index of the key. |
| TangentMode | mode | The mode to apply. |
SetValueWithoutNotify(AnimationCurve)
Sets the curve without sending a change event.
Declaration
public void SetValueWithoutNotify(AnimationCurve newValue)
Parameters
| Type | Name | Description |
|---|---|---|
| AnimationCurve | newValue | The curve to edit. Null resets to the default. |
Remarks
Incoming keys land in Free so their authored tangents are preserved exactly. Defaulting them to a solved mode would silently re-derive — and therefore change — a curve the caller only asked to display.
Show(AnimationCurveField, Action<AnimationCurve>, AnimationCurve)
Opens the editor in a Popover anchored to the field, as ColorField does with ColorPicker.
Declaration
public void Show(AnimationCurveField owner, Action<AnimationCurve> onValueChanging, AnimationCurve initialValue)
Parameters
| Type | Name | Description |
|---|---|---|
| AnimationCurveField | owner | The field that requested the editor. |
| Action<AnimationCurve> | onValueChanging | Invoked as the user edits. |
| AnimationCurve | initialValue | The curve assigned when the editor opened. |