Class UndoBlock
Represents a series of object actions as a single undo-operation.
Inherited Members
Namespace: Unity.XR.CoreUtils
Syntax
public class UndoBlock : IDisposable
Remarks
UndoBlock methods work in both Edit mode and Play mode. In Play mode undo-operations are disabled. This class mirrors the normal functions you find in the Undo class and collapses them into one operation when the block is complete.
Proper usage of this class is:
using (var undoBlock = new UndoBlock("Desired Undo Message"))
{
undoBlock.yourCodeToUndo()
}
Constructors
UndoBlock(String, Boolean)
Initialize a new UndoBlock.
Declaration
public UndoBlock(string undoLabel, bool testMode = false)
Parameters
Type | Name | Description |
---|---|---|
String | undoLabel | The label to apply to the undo group created within this undo block. |
Boolean | testMode | Whether this is part of a test run. |
Methods
AddComponent<T>(GameObject)
Adds a component to the game object and registers an undo operation for this action.
Declaration
public T AddComponent<T>(GameObject gameObject)
where T : Component
Parameters
Type | Name | Description |
---|---|---|
GameObject | gameObject | The game object you want to add the component to. |
Returns
Type | Description |
---|---|
T | The new component. |
Type Parameters
Name | Description |
---|---|
T | The type of component you want to add. |
Dispose()
This code added to correctly implement the disposable pattern.
Declaration
public void Dispose()
Implements
Dispose(Boolean)
Dispose of this object.
Declaration
protected virtual void Dispose(bool disposing)
Parameters
Type | Name | Description |
---|---|---|
Boolean | disposing | Whether to cleanup this object's state. |
RecordObject(Object)
Records any changes done on the object after the RecordObject function.
Declaration
public void RecordObject(Object objectToUndo)
Parameters
Type | Name | Description |
---|---|---|
Object | objectToUndo | The reference to the object that you will be modifying. |
RegisterCreatedObject(Object)
Register undo operations for a newly created object.
Declaration
public void RegisterCreatedObject(Object objectToUndo)
Parameters
Type | Name | Description |
---|---|---|
Object | objectToUndo | The object that was created. |
SetTransformParent(Transform, Transform)
Sets the parent transform of an object and records an undo operation.
Declaration
public void SetTransformParent(Transform transform, Transform newParent)
Parameters
Type | Name | Description |
---|---|---|
Transform | transform | The Transform component whose parent is to be changed. |
Transform | newParent | The parent Transform to be assigned. |