我试图使用RevertAllInCurrentGroup
撤消上一个操作,但它似乎不起作用。其实我真正想做的只是从历史中删除撤消;我不在乎撤消是否适用。如何从历史记录中删除撤销(RevertAllInCurrentGroup?)
在一些初始化代码,我有:
// 'component' is a MonoBehaviour-derived class. Here I create the default editor for the component
m_editor = Editor.CreateEditor(component);
然后在OnGUI
在我EditorWindow
:
m_editor.OnInspectorGUI();
// ..'hasChanged' is set to true if the user changed some property
if (hasChanged)
{
// ..do some stuff using the new values on the object, which includes sending a message to a server
Undo.RevertAllInCurrentGroup();
}
当我打电话RevertAllInCurrentGroup
我得到InvalidOperationException: Operation is not valid due to the current state of the object
在一些Stack
对象GUILayoutUtility.EndLayoutGroup
。我想也许我不应该在OnGUI
做恢复,所以我改变它设置一个标志,并在Update
做恢复,但这并没有什么区别(除了我明显不再有例外)。
有谁知道如何使用这个函数,或者如果有其他方法可以撤消Editor
实例所应用的最后一个操作?我试过使用Undo.RegisterCompleteObjectUndo
和Undo.ClearUndo
,但他们似乎也没有做任何事情(撤消操作仍然出现在撤消堆栈中)。
为了便于说明,我使用编辑器中的组件根据从服务器接收到的消息动态创建GameObjects
(这是一个正在运行的Unity游戏,可能在编辑器内部或外部 - 这是一个实时更新系统) 。然后,我允许编辑这些组件,并将更改后的组件发送回服务器。我正在渲染我自己的检查器UI,并且我想为组件使用内置的Editor
实例(例如,如果组件中有Camera
,则将使用内置的CameraEditor
)。
唯一的问题是,使用内置编辑器会将撤消操作添加到堆栈,但我真的不在意这些撤消操作,因为它们适用的GameObject
只是一个临时占位符GameObject
,它是每当我收到来自服务器的新消息时,都会不断更新每秒的coulpe。
啊是啊,你说得对,我可以用它!我的意思是,虽然我想撤消我正在使用的编辑器实例所应用的最后一个操作(或者撤消/删除当前正在编辑的对象的所有撤消历史记录)。无论如何,我会保持这种情况,以防其他人有任何其他建议。 – Sam
实际上这并不好,因为它不会从撤消堆栈中删除操作。我仍然可以“重做”手术。我需要将它从撤消堆栈中完全移除。 – Sam