Disable undo on all relevant Unity function invocations
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
using System;
|
||||
using System.Reflection;
|
||||
using UnityEditor;
|
||||
using UnityEditor.Animations;
|
||||
using UnityEngine;
|
||||
@@ -74,5 +75,45 @@ namespace AnimatorAsCode.V1
|
||||
{
|
||||
return new EditorCurveBinding {path = binding.path, type = binding.type, propertyName = binding.propertyName + "." + suffix};
|
||||
}
|
||||
|
||||
internal static void NoUndo<T>(T obj, Action action)
|
||||
{
|
||||
try
|
||||
{
|
||||
UndoDisable(obj);
|
||||
action.Invoke();
|
||||
}
|
||||
finally
|
||||
{
|
||||
UndoEnable(obj);
|
||||
}
|
||||
}
|
||||
|
||||
internal static TResult NoUndo<T, TResult>(T obj, Func<TResult> action)
|
||||
{
|
||||
try
|
||||
{
|
||||
UndoDisable(obj);
|
||||
return action.Invoke();
|
||||
}
|
||||
finally
|
||||
{
|
||||
UndoEnable(obj);
|
||||
}
|
||||
}
|
||||
|
||||
private static void UndoDisable<T>(T state)
|
||||
{
|
||||
typeof(T)
|
||||
.GetProperty("pushUndo", BindingFlags.Instance | BindingFlags.NonPublic)
|
||||
.SetValue(state, false);
|
||||
}
|
||||
|
||||
private static void UndoEnable<T>(T state)
|
||||
{
|
||||
typeof(T)
|
||||
.GetProperty("pushUndo", BindingFlags.Instance | BindingFlags.NonPublic)
|
||||
.SetValue(state, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user