Version: 2023.2
언어: 한국어

Undo.GetCurrentGroup

매뉴얼로 전환
public static int GetCurrentGroup ();

반환

int The index of the current undo group.

설명

Unity automatically groups undo operations by the current group index.

The current group index is automatically increased on mouse down, clicking on menu items and other operations.

Additional resources: 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);
    }
}