Skip to content

Commit

Permalink
Implement 'Revert Prefab Name' option in the GameObject/Prefabs conte…
Browse files Browse the repository at this point in the history
…xt menu
  • Loading branch information
arimger committed Dec 10, 2023
1 parent 9c2fc2c commit ed500bb
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 0 deletions.
41 changes: 41 additions & 0 deletions Assets/Editor Toolbox/Editor/Utilities/PrefabUtility.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
using UnityEditor;

namespace Toolbox.Editor.Utilities
{
public static class PrefabUtility
{
[MenuItem("GameObject/Prefab/Revert Prefab Name", true, -100)]
public static bool ValidateRevertPrefabName()
{
var gameObjects = Selection.gameObjects;
for (int i = 0; i < gameObjects.Length; i++)
{
var gameObject = gameObjects[i];
if (UnityEditor.PrefabUtility.IsAnyPrefabInstanceRoot(gameObject))
{
return true;
}
}

return false;
}

[MenuItem("GameObject/Prefab/Revert Prefab Name", false, -100)]
public static void RevertPrefabName()
{
var gameObjects = Selection.gameObjects;
Undo.RecordObjects(gameObjects, "Revert Prefab Name");
for (int i = 0; i < gameObjects.Length; i++)
{
var gameObject = gameObjects[i];
var prefabObject = UnityEditor.PrefabUtility.GetCorrespondingObjectFromSource(gameObject);
if (prefabObject == null)
{
continue;
}

gameObject.name = prefabObject.name;
}
}
}
}
11 changes: 11 additions & 0 deletions Assets/Editor Toolbox/Editor/Utilities/PrefabUtility.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit ed500bb

Please sign in to comment.