Last active
December 8, 2023 20:22
-
-
Save nicoplv/df2d1064be62cf894b202b33d050d54f to your computer and use it in GitHub Desktop.
A little script to get a clean name after a duplication or a copy of a gameobject in your unity scene. Drag and drop it into an editor folder !
This file contains 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 System.Text.RegularExpressions; | |
using UnityEditor; | |
using UnityEngine; | |
[InitializeOnLoad] | |
public class CleanDuplicateName | |
{ | |
static bool eventDuplicateAppend; | |
static CleanDuplicateName() | |
{ | |
EditorApplication.hierarchyWindowItemOnGUI += (int instanceID, Rect selectionRect) => | |
{ | |
if(Event.current != null && Event.current.type == EventType.ExecuteCommand && (Event.current.commandName == "Duplicate" || Event.current.commandName == "Paste")) | |
eventDuplicateAppend = true; | |
}; | |
EditorApplication.hierarchyChanged += () => | |
{ | |
if(eventDuplicateAppend) | |
{ | |
foreach (GameObject iGamebject in Selection.gameObjects) | |
iGamebject.name = Regex.Replace(iGamebject.name, @"(.*)\s\([0-9]*\)", @"$1"); | |
} | |
eventDuplicateAppend = false; | |
}; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment