Version: 2023.2

Undo.SetCurrentGroupName

切换到手册
public static void SetCurrentGroupName (string name);

参数

name 当前撤销组的新名称。

描述

设置当前撤销组的名称。

手动设置名称将覆盖隐式生成的组名称。

另请参阅:Undo.GetCurrentGroupName

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);
    }
}