docs.unity3d.com
    Show / Hide Table of Contents

    Class CallbackEventHandler

    Interface for classes capable of having callbacks to handle events.

    Inheritance
    Object
    CallbackEventHandler
    Focusable
    Namespace: UnityEngine.UIElements
    Syntax
    public abstract class CallbackEventHandler : object, IEventHandler

    Methods

    ExecuteDefaultAction(EventBase)

    Executes logic after the callbacks registered on the event target have executed, unless the event has been marked to prevent its default behaviour. .

    Declaration
    protected virtual void ExecuteDefaultAction(EventBase evt)
    Parameters
    Type Name Description
    EventBase evt

    The event instance.

    Remarks

    This method is designed to be overriden by subclasses. Use it to implement event handling without registering callbacks which guarantees precedences of callbacks registered by users of the subclass. Unlike ExecuteDefaultActionAtTarget(EventBase), this method is called after both the callbacks registered on the element and callbacks registered on its ancestors with NoTrickleDown.

    ExecuteDefaultActionAtTarget(EventBase)

    Executes logic after the callbacks registered on the event target have executed, unless the event is marked to prevent its default behaviour. .

    Declaration
    protected virtual void ExecuteDefaultActionAtTarget(EventBase evt)
    Parameters
    Type Name Description
    EventBase evt

    The event instance.

    Remarks

    This method is designed to be overriden by subclasses. Use it to implement event handling without registering callbacks, which guarantees precedences of callbacks registered by users of the subclass. Unlike ExecuteDefaultAction(EventBase), this method is called after the callbacks registered on the element but before callbacks registered on its ancestors with NoTrickleDown.

    HandleEvent(EventBase)

    Handle an event, most often by executing the callbacks associated with the event.

    Declaration
    public virtual void HandleEvent(EventBase evt)
    Parameters
    Type Name Description
    EventBase evt

    The event to handle.

    Implements
    IEventHandler.HandleEvent(EventBase)

    HasBubbleUpHandlers()

    Return true if event handlers for the event propagation BubbleUp phase have been attached on this object.

    Declaration
    public bool HasBubbleUpHandlers()
    Returns
    Type Description
    Boolean

    True if object has event handlers for the BubbleUp phase.

    Implements
    IEventHandler.HasBubbleUpHandlers()

    HasTrickleDownHandlers()

    Returns true if event handlers, for the event propagation TrickleDown phase, are attached to this object.

    Declaration
    public bool HasTrickleDownHandlers()
    Returns
    Type Description
    Boolean

    True if object has event handlers for the TrickleDown phase.

    Implements
    IEventHandler.HasTrickleDownHandlers()

    RegisterCallback<TEventType>(EventCallback<TEventType>, TrickleDown)

    Adds an event handler to the instance. If the event handler has already been registered for the same phase (either TrickleDown or BubbleUp) then this method has no effect.

    Declaration
    public void RegisterCallback<TEventType>(EventCallback<TEventType> callback, TrickleDown useTrickleDown = default(TrickleDown))
        where TEventType : EventBase<TEventType>, new()
    Parameters
    Type Name Description
    EventCallback<TEventType> callback

    The event handler to add.

    TrickleDown useTrickleDown

    By default, this callback is called during the BubbleUp phase. Pass TrickleDown.TrickleDown to call this callback during the TrickleDown phase.

    Type Parameters
    Name Description
    TEventType

    RegisterCallback<TEventType, TUserArgsType>(EventCallback<TEventType, TUserArgsType>, TUserArgsType, TrickleDown)

    Adds an event handler to the instance. If the event handler has already been registered for the same phase (either TrickleDown or BubbleUp) then this method has no effect.

    Declaration
    public void RegisterCallback<TEventType, TUserArgsType>(EventCallback<TEventType, TUserArgsType> callback, TUserArgsType userArgs, TrickleDown useTrickleDown = default(TrickleDown))
        where TEventType : EventBase<TEventType>, new()
    Parameters
    Type Name Description
    EventCallback<TEventType, TUserArgsType> callback

    The event handler to add.

    TUserArgsType userArgs

    Data to pass to the callback.

    TrickleDown useTrickleDown

    By default, this callback is called during the BubbleUp phase. Pass TrickleDown.TrickleDown to call this callback during the TrickleDown phase.

    Type Parameters
    Name Description
    TEventType
    TUserArgsType

    SendEvent(EventBase)

    Sends an event to the event handler.

    Declaration
    public abstract void SendEvent(EventBase e)
    Parameters
    Type Name Description
    EventBase e

    The event to send.

    Implements
    IEventHandler.SendEvent(EventBase)

    UnregisterCallback<TEventType>(EventCallback<TEventType>, TrickleDown)

    Remove callback from the instance.

    Declaration
    public void UnregisterCallback<TEventType>(EventCallback<TEventType> callback, TrickleDown useTrickleDown = default(TrickleDown))
        where TEventType : EventBase<TEventType>, new()
    Parameters
    Type Name Description
    EventCallback<TEventType> callback

    The callback to remove.

    TrickleDown useTrickleDown

    Set this parameter to true to remove the callback from the TrickleDown phase. Set this parameter to false to remove the callback from the BubbleUp phase.

    Type Parameters
    Name Description
    TEventType

    UnregisterCallback<TEventType, TUserArgsType>(EventCallback<TEventType, TUserArgsType>, TrickleDown)

    Remove callback from the instance.

    Declaration
    public void UnregisterCallback<TEventType, TUserArgsType>(EventCallback<TEventType, TUserArgsType> callback, TrickleDown useTrickleDown = default(TrickleDown))
        where TEventType : EventBase<TEventType>, new()
    Parameters
    Type Name Description
    EventCallback<TEventType, TUserArgsType> callback

    The callback to remove.

    TrickleDown useTrickleDown

    Set this parameter to true to remove the callback from the TrickleDown phase. Set this parameter to false to remove the callback from the BubbleUp phase.

    Type Parameters
    Name Description
    TEventType
    TUserArgsType
    In This Article
    • Methods
      • ExecuteDefaultAction(EventBase)
      • ExecuteDefaultActionAtTarget(EventBase)
      • HandleEvent(EventBase)
      • HasBubbleUpHandlers()
      • HasTrickleDownHandlers()
      • RegisterCallback<TEventType>(EventCallback<TEventType>, TrickleDown)
      • RegisterCallback<TEventType, TUserArgsType>(EventCallback<TEventType, TUserArgsType>, TUserArgsType, TrickleDown)
      • SendEvent(EventBase)
      • UnregisterCallback<TEventType>(EventCallback<TEventType>, TrickleDown)
      • UnregisterCallback<TEventType, TUserArgsType>(EventCallback<TEventType, TUserArgsType>, TrickleDown)
    Back to top
    Copyright © 2023 Unity Technologies — Terms of use
    • Legal
    • Privacy Policy
    • Cookies
    • Do Not Sell or Share My Personal Information
    • Your Privacy Choices (Cookie Settings)
    "Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
    Generated by DocFX on 18 October 2023