Created
June 7, 2014 23:40
-
-
Save jimfleming/37170cf50a6e443a78f5 to your computer and use it in GitHub Desktop.
Handles collapsing multiple undo operations. Definitely works in Unity 4.5. Haven't tested previous versions.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using UnityEditor; | |
using UnityEngine; | |
using System; | |
using System.Collections; | |
/* | |
Usage: | |
using (new UndoStack("Batch Changes")) { | |
// Make some changes using RecordObject or whatever... | |
} | |
*/ | |
public class UndoStack : IDisposable { | |
private static GameObject _TempGO; | |
private static GameObject TempGO { | |
get { | |
if (_TempGO == null) { | |
_TempGO = new GameObject("{GameObject}"); | |
_TempGO.hideFlags = HideFlags.HideAndDontSave; | |
} | |
return _TempGO; | |
} | |
} | |
public int GroupId { get; protected set; } | |
public UndoStack(string label) { | |
GroupId = Undo.GetCurrentGroup(); | |
Undo.IncrementCurrentGroup(); | |
Undo.RecordObject(TempGO, label); | |
TempGO.transform.localPosition += Vector3.one; | |
} | |
public void Dispose() { | |
Undo.CollapseUndoOperations(GroupId); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment