using Unity.Linq; using UnityEditor; using UnityEngine; using UnityEngine.SceneManagement; public class AllPrefabEdit { [MenuItem("Tools/Edit/Revert All Prefab Instances %F1")] public static void RevertAllPrefabInstances() { foreach (var rootObj in SceneManager.GetActiveScene().GetRootGameObjects()) { foreach (var obj in rootObj.DescendantsAndSelf()) { if (PrefabUtility.IsAnyPrefabInstanceRoot(obj)) { PrefabUtility.RevertPrefabInstance(obj, InteractionMode.AutomatedAction); Debug.Log($"Revert succeeded: {obj.name}"); } } } } [MenuItem("Tools/Edit/Apply All Prefab Instances %F2")] public static void ApplyAllPrefabInstances() { foreach (var rootObj in SceneManager.GetActiveScene().GetRootGameObjects()) { foreach (var obj in rootObj.DescendantsAndSelf()) { if (PrefabUtility.IsAnyPrefabInstanceRoot(obj)) { PrefabUtility.ApplyPrefabInstance(obj, InteractionMode.AutomatedAction); Debug.Log($"Apply succeeded: {obj.name}"); } } } } }
メニューの Tools > Edit か、Ctrl+F1, Ctrl+F2 で実行できます。
※ LINQ to GameObject が必要です。