跳到主要内容

使用撤销系统

默认情况下 ElementFactory 创建的控件均不支持撤销/重做功能。 您可以通过 ElementFactory 的构造函数来传入 UndoSystem 的实例,这会让此工厂创建的所有控件带有撤销/重做功能:

using UnityEditor;
using winS.UnityEditor.UIElement;
using winS.UnityEditor.Undo;

public class Example_WithUndo : EditorWindow
{
private UndoSystem undoSystem;

private void CreateGUI()
{
undoSystem = new UndoSystem();
ElementFactory elementFactory = new ElementFactory(undoSystem);
rootVisualElement.Add(elementFactory.CreateTextField("Text Field"));
rootVisualElement.Add(elementFactory.CreateFloatField("Float Field"));
}
private void OnDestroy()
{
undoSystem.Clear();
}
}