Created
July 3, 2019 03:02
-
-
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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