docs.unity.cn
    Show / Hide Table of Contents

    Class TrackAction

    Base class for a track action. Inherit from this class to make an action that would react on selected tracks after a menu click and/or a key shortcut.

    Inheritance
    Object
    TrackAction
    Namespace: UnityEditor.Timeline.Actions
    Syntax
    public abstract class TrackAction : object, IAction
    Remarks

    To add an action as a menu item in the Timeline context menu, add MenuEntryAttribute on the action class. To make an action to react to a shortcut, use the Shortcut Manager API with TimelineShortcutAttribute.

    Examples

    Simple track Action example (with context menu and shortcut support).

        [MenuEntry("Custom Actions/Sample track Action")]
        public class SampleTrackAction : TrackAction
        {
            public override ActionValidity Validate(IEnumerable<TrackAsset> tracks)
            {
                return ActionValidity.Valid;
            }
    
            public override bool Execute(IEnumerable<TrackAsset> tracks)
            {
                Debug.Log("Test Action");
                return true;
            }
    
            [TimelineShortcut("SampleTrackAction", KeyCode.H)]
            public static void HandleShortCut(ShortcutArguments args)
            {
                Invoker.InvokeWithSelectedTracks<SampleTrackAction>();
            }
        }

    Methods

    Execute(IEnumerable<TrackAsset>)

    Execute the action.

    Declaration
    public abstract bool Execute(IEnumerable<TrackAsset> tracks)
    Parameters
    Type Name Description
    IEnumerable<TrackAsset> tracks

    Tracks that will be used for the action.

    Returns
    Type Description
    Boolean

    true if the action has been executed. false otherwise

    Validate(IEnumerable<TrackAsset>)

    Defines the validity of an Action for a given set of tracks.

    Declaration
    public abstract ActionValidity Validate(IEnumerable<TrackAsset> tracks)
    Parameters
    Type Name Description
    IEnumerable<TrackAsset> tracks

    tracks that the action would act on.

    Returns
    Type Description
    ActionValidity

    The validity of the set of tracks.

    Back to top Copyright © 2020 Unity Technologies
    Generated by DocFX
    on Thursday, October 21, 2021