Skip to content

Instantly share code, notes, and snippets.

@beardordie
Created July 3, 2019 03:02
Show Gist options
  • Save beardordie/6c1cfc997dfac461969f7f7fb925b583 to your computer and use it in GitHub Desktop.
Save beardordie/6c1cfc997dfac461969f7f7fb925b583 to your computer and use it in GitHub Desktop.
Unity editor script to add a menu command that Reverts all selected prefabs. Includes safe confirmation dialogue and Undo support. Upgraded from FPSSample
using UnityEditor;
using UnityEngine;
public class RevertSelectedPrefabs
{
[MenuItem("Tools/Revert Selected Prefabs")]
static void Execute()
{
if (Selection.gameObjects.Length < 1) Debug.Log("No selection to revert.");
if (EditorUtility.DisplayDialog("Revert Selected Prefabs?",
"Are you sure you want to revert the selected prefabs? All overrides will be lost.", "Revert", "Do Not Revert"))
{
foreach (var gameObject in Selection.gameObjects)
{
Undo.RegisterCompleteObjectUndo(Selection.gameObjects, "Execute");
PrefabUtility.RevertPrefabInstance(gameObject, InteractionMode.UserAction);
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment