int 当前撤销组的索引。
Unity 会根据当前组索引自动对撤销操作进行分组。
在鼠标按下、单击菜单项和其他操作时,当前组索引会自动增加。
其他资源:Undo.RevertAllDownToGroup,Undo.CollapseUndoOperations。
using UnityEditor; using UnityEngine; public class ResetPositionForSelectedGameObjectsExample : MonoBehaviour { [MenuItem("MyMenu/Reset Positions of Selected GameObjects")] static void ResetPositionForSelectedGameObjects() { Undo.SetCurrentGroupName("Zero out selected gameObjects"); int group = Undo.GetCurrentGroup(); Undo.RecordObjects(Selection.transforms, "transform selected objects"); foreach (Transform t in Selection.transforms) { t.position = Vector3.zero; } Undo.CollapseUndoOperations(group); } }