Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/video/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Unity3d 如何从历史记录中删除撤消(RevertAllInCurrentGroup?)_Unity3d - Fatal编程技术网

Unity3d 如何从历史记录中删除撤消(RevertAllInCurrentGroup?)

Unity3d 如何从历史记录中删除撤消(RevertAllInCurrentGroup?),unity3d,Unity3d,我正试图使用RevertAllInCurrentGroup撤消上一个操作,但它似乎不起作用。实际上,我真正想做的就是从历史中移除撤销;我不在乎是否应用撤消 在一些init代码中,我有: // 'component' is a MonoBehaviour-derived class. Here I create the default editor for the component m_editor = Editor.CreateEditor(component); 然后在my编辑器窗口的On

我正试图使用
RevertAllInCurrentGroup
撤消上一个操作,但它似乎不起作用。实际上,我真正想做的就是从历史中移除撤销;我不在乎是否应用撤消

在一些init代码中,我有:

// 'component' is a MonoBehaviour-derived class. Here I create the default editor for the component
m_editor = Editor.CreateEditor(component);
然后在my
编辑器窗口的
OnGUI
中:

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:操作无效,因为
中的某些
堆栈中的对象的当前状态
。我想也许我不应该在
OnGUI
中执行恢复,所以我将其更改为设置一个标志,并在
Update
中执行恢复,但这没有任何区别(除非我显然不再得到异常)

是否有人知道如何使用此函数,或者是否有其他方法可以撤消
编辑器
实例应用的上一个操作?我尝试过使用
Undo.RegisterCompleteObjectUndo
Undo.ClearUndo
但它们似乎也没有做任何事情(Undo操作仍然出现在Undo堆栈中)

为了澄清,我正在根据从服务器收到的消息(这是一个正在运行的Unity游戏,可能在编辑器内部或外部,这是一个实时更新系统),在编辑器中动态创建
GameObjects
。然后我允许编辑这些组件,并将更改后的组件发送回服务器。我正在呈现我自己的inspector UI,我想为组件使用内置的
编辑器
实例(例如,如果存在
摄影机
组件,将使用内置的
摄影机编辑器


唯一的问题是使用内置编辑器会导致撤销操作被添加到堆栈中,但我真的不关心这些撤销操作,因为它们应用的
GameObject
只是一个临时占位符
GameObject
,每隔几秒钟就会不断更新,每当我收到来自服务器的新消息。

如果您想要的与单击“编辑->撤消”菜单相同(或如您所说,撤消编辑器应用的上一个操作),请使用以下代码:

Undo.PerformUndo();

啊,是的,你说得对,我可以用它!我的意思是,我想撤消我正在使用的
编辑器
实例应用的最后一个操作(或者撤消/删除我当前正在编辑的对象的所有撤消历史记录)。无论如何,我现在会保持这个打开状态,以防其他人有任何其他建议。实际上,这是不好的,因为它不会从撤消堆栈中删除操作。我仍然可以“重做”操作。我需要它完全从撤消堆栈中删除。