Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using UnityEngine;
- using UnityEditor;
- using System.Collections.Generic;
- public class PrefabNameRevert
- {
- [MenuItem("Prefab/RevertName")]
- static void RevertPrefabNames()
- {
- RevertAllNames(Selection.GetFiltered(typeof(GameObject), SelectionMode.OnlyUserModifiable));
- }
- public static void RemoveNameModification(UnityEngine.Object aObj)
- {
- var mods = new List<PropertyModification>(PrefabUtility.GetPropertyModifications(aObj));
- for (int i = 0; i < mods.Count; i++)
- {
- if (mods[i].propertyPath == "m_Name")
- mods.RemoveAt(i);
- }
- PrefabUtility.SetPropertyModifications(aObj, mods.ToArray());
- }
- public static void RevertAllNames(Object[] aObjects)
- {
- var items = new List<Object>();
- foreach (var item in aObjects)
- {
- var prefab = PrefabUtility.GetPrefabParent(item);
- if (prefab != null)
- {
- Undo.RecordObject(item, "Revert perfab name");
- item.name = prefab.name;
- items.Add(item);
- }
- }
- Undo.FlushUndoRecordObjects();
- foreach (var item in items)
- {
- RemoveNameModification(item);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement