/// <summary> /// Makes the passed ref undo object the current undo if it wasn't, and returns it afterwards. /// Use this in your editor scripts to be able to undo/redo via the menu items (Ctrl+Alt+u, Ctrl+Alt+r) /// ex: /// private BetterUndo _undo; /// public BetterUndo undo { get { return BetterUndo.MakeCurrent(ref _undo); } } /// And then from this point on, you just use 'undo' - that way this instace becomes the current undo, /// and thus available to be accessed from the menu items. /// </summary> public static BetterUndo MakeCurrent(ref BetterUndo undo) { if (current != undo) { current = undo; } return(undo); }
private void HandleUndoAndSet(object value) { if (UnityTarget != null) { Undo.RecordObject(UnityTarget, "Editor Member Modification"); } _undoTimer = EditorApplication.timeSinceStartup - _undoLastTime; if (_undoTimer > kUndoTick) { _undoTimer = 0f; _undoLastTime = EditorApplication.timeSinceStartup; BetterUndo.MakeCurrent(ref _undo); _setVar.ToValue = value; _undo.RegisterThenPerform(_setVar); } else { _set(value); } }