{!See https://docs.google.com/document/d/1takg_GmIBBKKTj-GHZCwzxohpQz7Bhekivkk72kYMtE/edit for reference implementation of OneTrust, dataLayer and GTM} {!OneTrust Cookies Consent} {!OneTrust Cookies Consent end} {!dataLayer initialization push} {!dataLayer initialization push end} {!Google Tag Manager} {!Google Tag Manager end} Class UndoStack | App UI | 0.5.5
docs.unity3d.com
Search Results for

    Show / Hide Table of Contents

    Class UndoStack

    An undo stack maintains a stack of commands that have been applied in your application.

    New commands are pushed on the stack using Push(UndoCommand). Commands can be undone and redone using Undo() and Redo().

    UndoStack keeps track of the current command. This is the command which will be executed by the next call to Redo(). The index of this command is returned by index. The state of the edited object can be rolled forward or back using index. If the top-most command on the stack has already been redone, index is equal to count.

    UndoStack provides *command compression*, command *macros*, and supports the concept of a *clean state*.

    Inheritance
    object
    UndoStack
    Inherited Members
    object.ToString()
    object.Equals(object)
    object.Equals(object, object)
    object.ReferenceEquals(object, object)
    object.GetHashCode()
    object.GetType()
    object.MemberwiseClone()
    Namespace: Unity.AppUI.Undo
    Assembly: solution.dll
    Syntax
    public class UndoStack

    Constructors

    Name Description
    UndoStack()

    Default constructor.

    Properties

    Name Description
    this[int]

    Gets the command at the given index.

    canRedo

    Weather the redo stack is empty.

    canUndo

    Weather the undo stack is empty.

    cleanIndex

    The index of the clean state. -1 if there is no clean state.

    commands

    The whole commands list.

    count

    The number of commands in the stack. Macros are counted as a single command.

    index

    The index of the last command in the undo stack.

    isClean

    Weather the undo stack is in a clean state. The clean state is useful when the application supports saving and restoring the state of an object.

    lastCommand

    The last command in the undo stack.

    memorySize

    The total memory size of the undo stack.

    undoLimit

    The maximum number of memory units that can be stored in the undo stack.

    Methods

    Name Description
    BeginMacro(string)

    Begins composition of a macro command with the given text description.

    An empty command described by the specified text is pushed on the stack. Any subsequent commands pushed on the stack will be appended to the macro command's children until EndMacro() is called.

    While a macro is being composed, the stack is disabled. This means that:
    - Events are not emitted.
    - canRedo and canUndo will always return false.
    - Calling Undo() or Redo() has no effect.
    The stack is re-enabled when the macro is ended.

    Here is an example of how to use macros:

    undoStack.BeginMacro("Insert Red Text");
    undoStack.Push(new InsertText(...));
    undoStack.Push(new SetRedText(...));
    undoStack.EndMacro();
    This code is equivalent to:
    var insertRedText = new UndoCommand("Insert Text");
    new InsertText(..., insertRedText);
    new SetRedText(..., insertRedText);
    undoStack.Push(insertRedText);
    Clear()

    Clears the undo and redo stacks.

    EndMacro()

    Ends composition of a macro command.
    If this is the outermost macro in a set nested macros, this function emits indexChanged once for the entire macro command.

    Push(UndoCommand)

    Pushes the given command on the undo stack.

    Redo()

    Calls Redo() on the last command in the redo stack.

    ResetClean()

    Sets the clean state to -1.

    SetClean()

    Sets the clean state to the last command in the undo stack.

    Undo()

    Calls Undo() on the last command in the undo stack.

    Events

    Name Description
    cleanStateChanged

    Emitted when the clean state changes.

    indexChanged

    Emitted the current Command index changes.

    In This Article
    Back to top
    Copyright © 2023 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)