docs.unity3d.com
Search Results for

    Show / Hide Table of Contents

    Class GradientEditor

    Unity's gradient stop-bar editor: alpha stops above a live preview strip, color stops below, and an inspector for whichever stop is selected.

    Inheritance
    object
    CallbackEventHandler
    Focusable
    VisualElement
    GradientEditor
    Implements
    IEventHandler
    IResolvedStyle
    ITransform
    ITransitionAnimations
    IExperimentalFeatures
    IVisualElementScheduler
    INotifyValueChanged<Gradient>
    ICustomColorGradientFieldPicker
    Inherited Members
    VisualElement.disabledUssClassName
    VisualElement.SetActivePseudoState(bool)
    VisualElement.SetCheckedPseudoState(bool)
    VisualElement.Focus()
    VisualElement.SendEvent(EventBase)
    VisualElement.SetEnabledFromHierarchy(bool)
    VisualElement.SetEnabled(bool)
    VisualElement.MarkDirtyRepaint()
    VisualElement.IsMarkedForRepaint()
    VisualElement.ContainsPoint(Vector2)
    VisualElement.Overlaps(Rect)
    VisualElement.DoMeasure(float, VisualElement.MeasureMode, float, VisualElement.MeasureMode)
    VisualElement.ToString()
    VisualElement.GetClasses()
    VisualElement.ClearClassList()
    VisualElement.AddToClassList(string)
    VisualElement.RemoveFromClassList(string)
    VisualElement.ToggleInClassList(string)
    VisualElement.EnableInClassList(string, bool)
    VisualElement.ClassListContains(string)
    VisualElement.FindAncestorUserData()
    VisualElement.SetBinding(BindingId, Binding)
    VisualElement.GetBinding(BindingId)
    VisualElement.TryGetBinding(BindingId, out Binding)
    VisualElement.GetBindingInfos()
    VisualElement.GetBindingInfos(List<BindingInfo>)
    VisualElement.HasBinding(BindingId)
    VisualElement.ClearBinding(BindingId)
    VisualElement.ClearBindings()
    VisualElement.GetHierarchicalDataSourceContext()
    VisualElement.GetDataSourceContext(BindingId)
    VisualElement.TryGetDataSourceContext(BindingId, out DataSourceContext)
    VisualElement.TryGetLastBindingToUIResult(in BindingId, out BindingResult)
    VisualElement.TryGetLastBindingToSourceResult(in BindingId, out BindingResult)
    VisualElement.Add(VisualElement)
    VisualElement.Insert(int, VisualElement)
    VisualElement.Remove(VisualElement)
    VisualElement.RemoveAt(int)
    VisualElement.Clear()
    VisualElement.ElementAt(int)
    VisualElement.IndexOf(VisualElement)
    VisualElement.Children()
    VisualElement.Sort(Comparison<VisualElement>)
    VisualElement.BringToFront()
    VisualElement.SendToBack()
    VisualElement.PlaceBehind(VisualElement)
    VisualElement.PlaceInFront(VisualElement)
    VisualElement.RemoveFromHierarchy()
    VisualElement.GetFirstOfType<T>()
    VisualElement.GetFirstAncestorOfType<T>()
    VisualElement.Contains(VisualElement)
    VisualElement.FindCommonAncestor(VisualElement)
    VisualElement.viewDataKey
    VisualElement.userData
    VisualElement.canGrabFocus
    VisualElement.focusController
    VisualElement.disablePlayModeTint
    VisualElement.usageHints
    VisualElement.transform
    VisualElement.scaledPixelsPerPoint
    VisualElement.layout
    VisualElement.contentRect
    VisualElement.paddingRect
    VisualElement.worldBound
    VisualElement.localBound
    VisualElement.worldTransform
    VisualElement.hasActivePseudoState
    VisualElement.hasInactivePseudoState
    VisualElement.hasHoverPseudoState
    VisualElement.hasCheckedPseudoState
    VisualElement.hasEnabledPseudoState
    VisualElement.hasDisabledPseudoState
    VisualElement.hasFocusPseudoState
    VisualElement.hasRootPseudoState
    VisualElement.pickingMode
    VisualElement.name
    VisualElement.enabledInHierarchy
    VisualElement.enabledSelf
    VisualElement.languageDirection
    VisualElement.visible
    VisualElement.generateVisualContent
    VisualElement.dataSource
    VisualElement.dataSourcePath
    VisualElement.dataSourceType
    VisualElement.experimental
    VisualElement.hierarchy
    VisualElement.cacheAsBitmap
    VisualElement.parent
    VisualElement.panel
    VisualElement.visualTreeAssetSource
    VisualElement.this[int]
    VisualElement.childCount
    VisualElement.schedule
    VisualElement.style
    VisualElement.resolvedStyle
    VisualElement.customStyle
    VisualElement.styleSheets
    VisualElement.tooltip
    Focusable.Blur()
    Focusable.focusable
    Focusable.tabIndex
    Focusable.delegatesFocus
    CallbackEventHandler.RegisterCallback<TEventType>(EventCallback<TEventType>, TrickleDown)
    CallbackEventHandler.RegisterCallbackOnce<TEventType>(EventCallback<TEventType>, TrickleDown)
    CallbackEventHandler.RegisterCallback<TEventType, TUserArgsType>(EventCallback<TEventType, TUserArgsType>, TUserArgsType, TrickleDown)
    CallbackEventHandler.RegisterCallbackOnce<TEventType, TUserArgsType>(EventCallback<TEventType, TUserArgsType>, TUserArgsType, TrickleDown)
    CallbackEventHandler.RegisterCallback<TEventType>(EventCallback<TEventType>, CallbackOptions)
    CallbackEventHandler.RegisterCallback<TEventType, TUserArgsType>(EventCallback<TEventType, TUserArgsType>, TUserArgsType, CallbackOptions)
    CallbackEventHandler.UnregisterCallback<TEventType>(EventCallback<TEventType>, TrickleDown)
    CallbackEventHandler.UnregisterCallback<TEventType>(EventCallback<TEventType>, CallbackOptions)
    CallbackEventHandler.UnregisterCallback<TEventType, TUserArgsType>(EventCallback<TEventType, TUserArgsType>, TrickleDown)
    CallbackEventHandler.UnregisterCallback<TEventType, TUserArgsType>(EventCallback<TEventType, TUserArgsType>, CallbackOptions)
    CallbackEventHandler.UnregisterAllRemovableCallbacks()
    CallbackEventHandler.HasTrickleDownHandlers()
    CallbackEventHandler.HasBubbleUpHandlers()
    CallbackEventHandler.ExecuteDefaultActionAtTarget(EventBase)
    CallbackEventHandler.HandleEventBubbleUp(EventBase)
    CallbackEventHandler.HandleEventTrickleDown(EventBase)
    CallbackEventHandler.ExecuteDefaultAction(EventBase)
    CallbackEventHandler.NotifyPropertyChanged(in BindingId)
    object.Equals(object)
    object.Equals(object, object)
    object.GetHashCode()
    object.GetType()
    object.MemberwiseClone()
    object.ReferenceEquals(object, object)
    Namespace: Unity.AppUI.UI
    Assembly: Unity.AppUI.dll
    Syntax
    public class GradientEditor : VisualElement, IEventHandler, IResolvedStyle, ITransform, ITransitionAnimations, IExperimentalFeatures, IVisualElementScheduler, INotifyValueChanged<Gradient>, ICustomColorGradientFieldPicker
    Remarks

    The editor is the counterpart ColorGradientField has been waiting for. It implements ICustomColorGradientFieldPicker, so assigning one to customPicker is all it takes to turn the field from a read-only gradient well into an editable one — exactly how ColorField and ColorPicker pair up.

    Everything visual is reused rather than reinvented. The preview strip is a ColorSwatch, the same shader path ColorGradientField's own preview uses, so Fixed and the transparency checkerboard are rendered once and identically in both places. The selected color stop is edited with a ColorField, which brings the whole ColorPicker with it, and the selected alpha stop with a ColorSlider whose track is the sampled stop color fading to transparent.

    Stops are held sorted by time. Dragging one past a neighbour therefore reorders the list, and the selection follows the stop rather than the index, so a drag never silently starts editing a different stop. Both rails are capped at maxKeys, which is Gradient's own limit: a ninth key would be dropped by SetKeys(GradientColorKey[],GradientAlphaKey[]) without an error.

    Interaction

    • Click a stop to select it, drag to move it.
    • Double-click an empty rail to add a stop there, sampled from the current gradient so inserting one does not change how the gradient looks.
    • Delete or Backspace removes the selected stop, never the last one on a rail.

    Example

    var field = new ColorGradientField { customPicker = new GradientEditor() };
    field.RegisterValueChangedCallback(evt => Debug.Log(evt.newValue));

    Constructors

    GradientEditor()

    Default constructor. Starts on an opaque black-to-white blend.

    Declaration
    public GradientEditor()

    Fields

    alphaRailUssClassName

    The alpha stop rail styling class.

    Declaration
    public const string alphaRailUssClassName = "appui-gradienteditor__alpha-rail"
    Field Value
    Type Description
    string

    alphaSliderUssClassName

    The stop alpha slider styling class.

    Declaration
    public const string alphaSliderUssClassName = "appui-gradienteditor__alpha-slider"
    Field Value
    Type Description
    string

    colorFieldUssClassName

    The stop color field styling class.

    Declaration
    public const string colorFieldUssClassName = "appui-gradienteditor__color-field"
    Field Value
    Type Description
    string

    colorRailUssClassName

    The color stop rail styling class.

    Declaration
    public const string colorRailUssClassName = "appui-gradienteditor__color-rail"
    Field Value
    Type Description
    string

    hdrUssClassName

    The HDR styling class.

    Declaration
    public const string hdrUssClassName = "appui-gradienteditor--hdr"
    Field Value
    Type Description
    string

    inspectorUssClassName

    The inspector styling class.

    Declaration
    public const string inspectorUssClassName = "appui-gradienteditor__inspector"
    Field Value
    Type Description
    string

    labelUssClassName

    The inspector label styling class.

    Declaration
    public const string labelUssClassName = "appui-gradienteditor__label"
    Field Value
    Type Description
    string

    locationFieldUssClassName

    The stop location field styling class.

    Declaration
    public const string locationFieldUssClassName = "appui-gradienteditor__location-field"
    Field Value
    Type Description
    string

    markerChipUssClassName

    The stop marker chip styling class. This is the part tinted with the stop's own value.

    Declaration
    public const string markerChipUssClassName = "appui-gradienteditor__marker-chip"
    Field Value
    Type Description
    string

    markerUssClassName

    The stop marker styling class.

    Declaration
    public const string markerUssClassName = "appui-gradienteditor__marker"
    Field Value
    Type Description
    string

    maxKeys

    The most keys a Gradient can hold on either rail. A ninth key is silently dropped by SetKeys(GradientColorKey[],GradientAlphaKey[]), so the editor refuses to add one instead.

    Declaration
    public const int maxKeys = 8
    Field Value
    Type Description
    int

    minKeys

    The fewest keys a Gradient can hold on either rail.

    Declaration
    public const int minKeys = 2
    Field Value
    Type Description
    int
    Remarks

    SetKeys(GradientColorKey[],GradientAlphaKey[]) silently pads anything shorter back up to two, so a rail that let the user delete down to one key would appear to work and then hand back a gradient with a duplicated key. The editor refuses the deletion instead.

    modeDropdownUssClassName

    The gradient mode dropdown styling class.

    Declaration
    public const string modeDropdownUssClassName = "appui-gradienteditor__mode-dropdown"
    Field Value
    Type Description
    string

    rowUssClassName

    The inspector row styling class.

    Declaration
    public const string rowUssClassName = "appui-gradienteditor__row"
    Field Value
    Type Description
    string

    selectedMarkerUssClassName

    The selected stop marker styling class.

    Declaration
    public const string selectedMarkerUssClassName = "appui-gradienteditor__marker--selected"
    Field Value
    Type Description
    string

    stripUssClassName

    The preview strip styling class.

    Declaration
    public const string stripUssClassName = "appui-gradienteditor__strip"
    Field Value
    Type Description
    string

    ussClassName

    The GradientEditor main styling class.

    Declaration
    public const string ussClassName = "appui-gradienteditor"
    Field Value
    Type Description
    string

    Properties

    alphaElement

    The ColorSlider editing the selected alpha stop.

    Declaration
    public ColorSlider alphaElement { get; }
    Property Value
    Type Description
    ColorSlider

    alphaMarkers

    The alpha stop markers, in time order.

    Declaration
    public IReadOnlyList<VisualElement> alphaMarkers { get; }
    Property Value
    Type Description
    IReadOnlyList<VisualElement>

    alphaRailElement

    The rail carrying the alpha stops, above the strip.

    Declaration
    public VisualElement alphaRailElement { get; }
    Property Value
    Type Description
    VisualElement

    colorElement

    The ColorField editing the selected color stop.

    Declaration
    public ColorField colorElement { get; }
    Property Value
    Type Description
    ColorField

    colorMarkers

    The color stop markers, in time order.

    Declaration
    public IReadOnlyList<VisualElement> colorMarkers { get; }
    Property Value
    Type Description
    IReadOnlyList<VisualElement>

    colorRailElement

    The rail carrying the color stops, below the strip.

    Declaration
    public VisualElement colorRailElement { 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
    VisualElement.contentContainer

    hdr

    Whether the color stop editor offers HDR colors. Forwarded from hdr when the editor is opened as its picker.

    Declaration
    [CreateProperty]
    public bool hdr { get; set; }
    Property Value
    Type Description
    bool

    locationElement

    The stop location field, in percent.

    Declaration
    public IntField locationElement { get; }
    Property Value
    Type Description
    IntField

    mode

    How the gradient interpolates between its color stops.

    Declaration
    [CreateProperty]
    public GradientMode mode { get; set; }
    Property Value
    Type Description
    GradientMode
    Remarks

    The dropdown offers Blend and Fixed, matching the registry. PerceptualBlend can still be set from code; it renders as a blend.

    modeElement

    The gradient mode dropdown.

    Declaration
    public Dropdown modeElement { get; }
    Property Value
    Type Description
    Dropdown

    selectedKeyIndex

    The index of the selected stop on its rail, or -1 when nothing is selected.

    Declaration
    public int selectedKeyIndex { get; }
    Property Value
    Type Description
    int

    selectedKeyKind

    Which rail the selected stop lives on.

    Declaration
    public GradientEditor.KeyKind selectedKeyKind { get; }
    Property Value
    Type Description
    GradientEditor.KeyKind

    stripElement

    The ColorSwatch rendering the composited preview.

    Declaration
    public ColorSwatch stripElement { get; }
    Property Value
    Type Description
    ColorSwatch

    value

    The gradient being edited.

    Declaration
    [CreateProperty]
    public Gradient value { get; set; }
    Property Value
    Type Description
    Gradient
    Remarks

    The getter builds a fresh Gradient on every read, so a consumer holding an earlier value never sees it mutate underneath them.

    Methods

    AddAlphaKey(float)

    Adds an alpha stop, sampling the current alpha ramp at that time, then selects it.

    Declaration
    public bool AddAlphaKey(float time)
    Parameters
    Type Name Description
    float time

    Normalized time, clamped to 0..1.

    Returns
    Type Description
    bool

    False when the rail already holds maxKeys stops.

    AddColorKey(float)

    Adds a color stop, sampling the current gradient at that time so the gradient looks unchanged, then selects it.

    Declaration
    public bool AddColorKey(float time)
    Parameters
    Type Name Description
    float time

    Normalized time, clamped to 0..1.

    Returns
    Type Description
    bool

    False when the rail already holds maxKeys stops.

    Dismiss()

    Closes the popover this editor was opened in, if any.

    Declaration
    public void Dismiss()

    RemoveSelectedKey()

    Removes the selected stop.

    Declaration
    public bool RemoveSelectedKey()
    Returns
    Type Description
    bool

    False when nothing is selected, or when its rail is already down to minKeys stops.

    SelectKey(KeyKind, int)

    Selects a stop.

    Declaration
    public void SelectKey(GradientEditor.KeyKind kind, int index)
    Parameters
    Type Name Description
    GradientEditor.KeyKind kind

    Which rail the stop lives on.

    int index

    Index of the stop on that rail. Out-of-range clears the selection.

    SetSelectedKeyAlpha(float)

    Sets the alpha of the selected alpha stop. Does nothing when a color stop is selected.

    Declaration
    public void SetSelectedKeyAlpha(float alpha)
    Parameters
    Type Name Description
    float alpha

    The new alpha, clamped to 0..1.

    SetSelectedKeyColor(Color)

    Sets the color of the selected color stop. Does nothing when an alpha stop is selected.

    Declaration
    public void SetSelectedKeyColor(Color color)
    Parameters
    Type Name Description
    Color color

    The new stop color. Alpha is carried by the alpha rail, not here.

    SetSelectedKeyTime(float)

    Moves the selected stop in time. The selection follows the stop through the reorder that may cause.

    Declaration
    public void SetSelectedKeyTime(float time)
    Parameters
    Type Name Description
    float time

    Normalized time, clamped to 0..1.

    SetValueWithoutNotify(Gradient)

    Sets the gradient without sending a change event.

    Declaration
    public void SetValueWithoutNotify(Gradient newValue)
    Parameters
    Type Name Description
    Gradient newValue

    The gradient to edit. Null resets to the default.

    Show(ColorGradientField, Action<Gradient>, Gradient, bool)

    Opens the editor in a Popover anchored to the field, as ColorField does with ColorPicker.

    Declaration
    public void Show(ColorGradientField owner, Action<Gradient> onValueChanging, Gradient initialValue, bool showHdr)
    Parameters
    Type Name Description
    ColorGradientField owner

    The field that requested the editor.

    Action<Gradient> onValueChanging

    Invoked as the user edits.

    Gradient initialValue

    The gradient assigned when the editor opened.

    bool showHdr

    Whether the editor should allow HDR color stops.

    Implements

    IEventHandler
    IResolvedStyle
    ITransform
    ITransitionAnimations
    IExperimentalFeatures
    IVisualElementScheduler
    INotifyValueChanged<T>
    ICustomColorGradientFieldPicker

    Extension Methods

    VisualElementExtensions.FindNavController(VisualElement)
    RegisterUpdateCallbackExtensions.RegisterUpdateCallback(VisualElement, EventCallback<UpdateEvent>)
    RegisterUpdateCallbackExtensions.UnregisterUpdateCallback(VisualElement, EventCallback<UpdateEvent>)
    VisualElementExtensions.EnableDynamicTransform(VisualElement, bool)
    VisualElementExtensions.EnablePicking(VisualElement, bool)
    VisualElementExtensions.GetChildren<T>(VisualElement, bool)
    VisualElementExtensions.GetContextProvider<T>(VisualElement)
    VisualElementExtensions.GetContextProvider<T>(VisualElement, string)
    VisualElementExtensions.GetContext<T>(VisualElement)
    VisualElementExtensions.GetContext<T>(VisualElement, string)
    VisualElementExtensions.GetExclusiveRootElement(VisualElement)
    VisualElementExtensions.GetLastAncestorOfType<T>(VisualElement)
    VisualElementExtensions.GetPreferredTooltipPlacement(VisualElement)
    VisualElementExtensions.GetSelfContext<T>(VisualElement)
    VisualElementExtensions.GetSelfContext<T>(VisualElement, string)
    VisualElementExtensions.GetTooltipContent(VisualElement)
    VisualElementExtensions.GetTooltipTemplate(VisualElement)
    VisualElementExtensions.HasAncestorOfType<T>(VisualElement, bool)
    VisualElementExtensions.HasAncestorsOfType<T>(VisualElement)
    VisualElementExtensions.IsContextProvider<T>(VisualElement)
    VisualElementExtensions.IsContextProvider<T>(VisualElement, string)
    VisualElementExtensions.IsInvisible(VisualElement)
    VisualElementExtensions.IsOnScreen(VisualElement)
    VisualElementExtensions.ProvideContext<T>(VisualElement, string, T)
    VisualElementExtensions.ProvideContext<T>(VisualElement, T)
    VisualElementExtensions.RegisterContextChangedCallback<T>(VisualElement, string, EventCallback<ContextChangedEvent<T>>)
    VisualElementExtensions.RegisterContextChangedCallback<T>(VisualElement, EventCallback<ContextChangedEvent<T>>)
    VisualElementExtensions.SetPreferredTooltipPlacement(VisualElement, OptionalEnum<PopoverPlacement>)
    VisualElementExtensions.SetTooltipContent(VisualElement, VisualElementExtensions.TooltipContentCallback)
    VisualElementExtensions.SetTooltipTemplate(VisualElement, VisualElement)
    VisualElementExtensions.UnregisterContextChangedCallback<T>(VisualElement, string, EventCallback<ContextChangedEvent<T>>)
    VisualElementExtensions.UnregisterContextChangedCallback<T>(VisualElement, EventCallback<ContextChangedEvent<T>>)
    In This Article
    Back to top
    Copyright © 2026 Unity Technologies — Trademarks and terms of use
    • Legal
    • Privacy Policy
    • Cookie Policy
    • Do Not Sell or Share My Personal Information
    • Your Privacy Choices (Cookie Settings)