Skip to main content

HistoryAccess

An abstract class in Root.Township, the global namespace.

Component front for an undo and redo history, raising bool events when undo or redo becomes possible or not, for buttons.

Constructors​

MemberWhat it is
protected HistoryAccess()Unity makes components itself; use AddComponent or spawn a prefab instead of new.

Fields​

4 private and internal fields
MemberWhat it is
private bool cacheRedoPossibleLast known redo state.
private bool cacheUndoPossibleLast known undo state.
private BoolEvent redoPossibleChangedEvent raised with whether redo is now possible.
private BoolEvent undoPossibleChangedEvent raised with whether undo is now possible.

Properties​

MemberWhat it is
abstract IHistoryManager History { get; }The history this component drives.
bool IsRedoPossible { get; }Whether there is something to redo.
bool IsUndoPossible { get; }Whether there is something to undo.

Events​

MemberWhat it is
event Action ItemPushedRaised when a new item is added to the history.

Methods​

MemberWhat it is
void Clear()Clears the history.
void Redo()Redoes the last undone item.
void Undo()Undoes the last item.
protected virtual void Awake()Listens for new history items.
2 private and internal methods
MemberWhat it is
private void OnItemPushed()Updates the undo and redo state and raises ItemPushed when the history gets a new action.
private void UpdateCache()Raises the undo and redo events when either becomes possible or impossible.