Class UndoBlock
Class that automatically groups a series of object actions together as a single undo-operation And works in both the editor and player (with player support simply turning off undo-operations) 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() }
Namespace: Unity.XR.CoreUtils
Syntax
public class UndoBlock : IDisposable
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()
Dispose(Boolean)
Dispose of this object
Declaration
protected virtual void Dispose(bool disposing)
Parameters
Type | Name | Description |
---|---|---|
Boolean | disposing | Whether to dispose this object |
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 of transform to the new parent 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. |