Unity utility to rename game objects for use as headers in the scene hierarchy.
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
/* Original code[1] Copyright (c) 2019 Shane Celis[2] | |
Licensed under the MIT License[3] | |
[1]: https://gist.github.com/shanecelis/557b30f46b534a80047b9f2969a94c6e | |
[2]: https://github.com/shanecelis | |
[3]: https://opensource.org/licenses/MIT | |
*/ | |
using UnityEngine; | |
using UnityEditor; | |
using System.Text.RegularExpressions; | |
/** Unity utility to rename game objects for use as headers in the scene | |
hierarchy. See tweet[1] for usage example. | |
Inspired by on this tip[2] from Unity. | |
[1]: https://twitter.com/shanecelis/status/1137967723911290880 | |
[2]: https://learn.unity.com/tutorial/unity-tips#5c7f8528edbc2a002053b481 | |
*/ | |
public static class Renamer { | |
[MenuItem("Tools/Make Header %-")] | |
public static void MakeHeader() { | |
// https://docs.unity3d.com/ScriptReference/Selection.GetTransforms.html | |
Transform[] selection = Selection.GetTransforms(SelectionMode.TopLevel | SelectionMode.Editable); | |
foreach (Transform t in selection) { | |
Undo.RecordObject(t.gameObject, "Change name to be a header"); | |
var name = t.gameObject.name; | |
t.gameObject.name = $"---- {name} ----"; | |
} | |
} | |
[MenuItem("Tools/Unmake Header &-")] | |
public static void UnmakeHeader() { | |
Transform[] selection = Selection.GetTransforms(SelectionMode.TopLevel | SelectionMode.Editable); | |
foreach (Transform t in selection) { | |
Undo.RecordObject(t.gameObject, "Change name to not be a header"); | |
var name = t.gameObject.name; | |
name = Regex.Replace(name, @"^-+ ", ""); | |
name = Regex.Replace(name, @" -+$", ""); | |
t.gameObject.name = name; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment